Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

set environment variables for ant script

does anyone knows how to set additional environment variables for an ant script from within intellij-idea/rubymine? The part of the ant script which uses the environment variable looks as below:

  <property environment="env"/>
  <fail unless="env.IDEA_HOME" message="IDEA_HOME must be set."/>

What I've tried so far:

  • Passing an environment variable on startup to intellij
  • Settings -> Path Variables
  • Ant Build -> Properties
  • Ant Build -> Execution -> Ant command line
like image 909
Ruben Jenster Avatar asked Mar 02 '12 12:03

Ruben Jenster


2 Answers

You can set variables as additional command line parameters. Here is a screenshot.

enter image description here

And then my output:

echoproperties
#Ant properties
#Sun Mar 04 04:48:30 EST 2012
\==-buildfile
ant.core.lib=E\:\\IntelliJ IDEA 114.145\\lib\\ant\\lib\\ant.jar
ant.file=E\:\\IdeaProjects\\psiviewer\\build.xml
ant.file.psiviewer=E\:\\IdeaProjects\\psiviewer\\build.xml
ant.file.type=file
ant.file.type.psiviewer=file
ant.home=E\:\\IntelliJ IDEA 114.145\\lib\\ant
ant.java.version=1.6
ant.library.dir=E\:\\IntelliJ IDEA 114.145\\lib\\ant\\lib
ant.project.default-target=all
ant.project.name=psiviewer
ant.version=Apache Ant(TM) version 1.8.2 compiled on December 20 2010
awt.toolkit=sun.awt.windows.WToolkit
basedir=E\:\\IdeaProjects\\psiviewer
dir.idea=e\:/idea11
file.encoding=windows-1252
file.encoding.pkg=sun.io

You see dir.idea is set to what we passed to ant.

like image 115
sylvanaar Avatar answered Oct 16 '22 20:10

sylvanaar


Problem: Run ant build within IntelliJ, let ant build property to use IntelliJ Path Variables value

Solution:

  1. Added path variable QC1_SHELL_DEPLOY to intelliJ IntelliJ Settings ->Path Variables
  2. In your Ant Build window (views -> Tool Windows -> Ant Build), right click on your ant script (assuming you have one added), click properties. create a property for ant script qc_deploy_dir. property for ant script with arbitrary value

  3. Open ant.xml in your project .idea/ant.xml, change the line defining qc_deploy_dir to use IntelliJ Path Variable $QC1_SHELL_DEPLOY property change for ant.xml

  4. Go back to your properties window for ant script, now qc_deploy_dir is picking up QC1_SHELL_DEPLOY value.

like image 29
Weicheng Avatar answered Oct 16 '22 20:10

Weicheng