7
votes

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
2
Option 1 would have worked. (works for me ) - Jayan
Ant Build/Properties/Properties tab/ specify the full name of the variable, so in your case would be env.IDEA_HOME as the Name. - dvd
The general issue which I also have is how can one export an idea setting that is project or ide specific (set in the idea UI for it's optins) int an ant invocation such that the value is inherited from the ide or project setting at invocaton time ie: have macros representing the IDE settings that can be used to assign idea "Project Structure" properties to ant accessable properties ie: IDEA_HOME for , JAVA_HOME="Project SDK", "Project Root "where .idea is located" "Java Language Level", "Build Output Dir", "Project Name" etc - peterk
I need this too - a way to know the location of the invoking ".idea" project root (not the module) when an ant script is invoked an environment directory independent manner so the value adapts to the specific source tree location - peterk

2 Answers

2
votes

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.

1
votes

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.