How to customize a run configuration in IntelliJ?


Hi,

I am using IntelliJ 8.1 and I am trying to make a custom JUnit run configuration. I am testing a custom java class and setting it a particular classpath through the 'VM parameters' field. I am wondering if it is possible:

* to use an environment variable in this field. For example $GRAILS_HOME/dist/[...].jar if GRAILS_HOME is defined in my OS

* to have a shortcut to IntelliJ install directory: instead of putting /Applications/myIntelliJ/lib/idea_rt.jar put something like ${intellij_home}/lib/idea_rt.jar in order to work on any developer station (without having to set intellij_home obviously...)

* to use the equivalent of eclipse variable ${resource_loc}. In fact, I want to know which file is selected (either in the editor or in the Project view) to be able to run a single test on this file.

I know I can set environment variables inside the run configuration but I would try to avoid having to customize each configuration on each developer workstation.

Thanks for your help!

Cyril

4 comments
Comment actions Permalink

Hi.

Before answering particular questions: please, notice that JUnit configuration has the setting "Use classpath and JDK of module". Usually users are able to provide a module with required classpath and dependencies, and after that IDEA cares about classpath substitution in the command line. Could it be enough?

> to use an environment variable in this field. For example $GRAILS_HOME/dist/[...].jar if GRAILS_HOME is defined in my OS
IDEA just passes the specified variables to command line, which tests are executed with. You can write anything which is accepted by java.

> to have a shortcut to IntelliJ install directory
Yes, it is $APPLICATION_HOME_DIR$ macro.

Notice that you do not need to explicitly type the macro for a field which is purposed for the single path (e.g. Working directory). There you just write the path to a location inside currently used IDEA installation (like C:\JetBrains\IDEA_build_1234\bin), and it is written into project files with $APPLICATION_HOME_DIR$. However, it's not about VM parameters field.

> to use the equivalent of eclipse variable ${resource_loc}
It seems that there is no exact equivalent (though IDEA understands some macros like $PROJECT_DIR$). Instead, there are context actions (e.g. in the editor context menu) to immediately create a run configuration for the test you stand inside and run it. Created configuration is temporary. The defaults for new configuration are available in Run configurations dialog, by pressing Edit defaults button.

Alexander.

0
Comment actions Permalink

Thanks for your answer Alexander. I am replying you inline.

> Before answering particular questions: please, notice that JUnit configuration has the setting
> "Use classpath and JDK of module". Usually users are able to provide a module with required
> classpath and > dependencies, and after that IDEA cares about classpath substitution in the
> command line. Could it be enough?

no because actually my test does not use the classpath of the module. I know it is strange but that's why I am using the -classpath option in 'VM parameters'


> to use an environment variable in this field. For example $GRAILS_HOME/dist/[...].jar if
> GRAILS_HOME is defined in my OS IDEA just passes the specified variables to command
> line, which tests are executed with. You can write anything which is accepted by java.

ok. Actually I don't want to use $GRAILS_HOME in my application but in the run configuration, that is in the 'VM parameters' box.
To clarify, my VM parameters is today something like:
'-server -Xmx512M -classpath /Applications/InstalledSoftware/grails-1.0.4/lib/groovy-all-1.5.6.jar:/Applications/InstalledSoftware/grails-1.0.4/dist/grails-cli-1.0.4.jar:/System/Library/Java:"$APPLICATION_HOME_DIR$/lib/idea_rt.jar":"$APPLICATION_HOME_DIR$/lib/junit.jar".

Is this possible to replace ' /Applications/InstalledSoftware/grails-1.0.4/lib/groovy-all-1.5.6.jar' by something like '$GRAILS_HOME/lib/groovy-all-1.5.6.jar' (I have tried and it doesn't work)?


>> to have a shortcut to IntelliJ install directory
> Yes, it is $APPLICATION_HOME_DIR$ macro.


Thanks, it works


>> to use the equivalent of eclipse variable ${resource_loc}
> It seems that there is no exact equivalent (though IDEA understands some macros like $PROJECT_DIR$).
> Instead, there are context actions (e.g. in the editor context menu) to immediately create a run configuration
> for the test you stand inside and run it. Created configuration is temporary. The defaults for new configuration
> are available in Run configurations dialog, by pressing Edit defaults button.

Ok but unfortunately I can't add context actions myself? If I do, how can I get back the parameter saying on which file the context action is running?
I have tried your tip and it creates a new run configuration if I understand well (say for example MyClassTest) based on a default run configuration.

The thing is I have an helper class that test my real class (the one in my project). So in Test/Class in my run config I need to put my helper class and to give it a parameter -Dtest.file=[...] in 'VM parameters' with the corresponding filename to test. Can I do this with context actions? I have looked at editing the default but anyway I see no mean to tell IntelliJ where to put the test class, it always goes in the Test/Class field.

Thanks again,

Cyril

0
Comment actions Permalink

> Is this possible to replace ' /Applications/InstalledSoftware/grails-1.0.4/lib/groovy-all-1.5.6.jar' by something like '$GRAILS_HOME/lib/groovy-all-1.5.6.jar' (I have tried and it doesn't work)?
Yes, I see. This really does not supported.

Turning back to the initial intention:
> I would try to avoid having to customize each configuration on each developer workstation.
I would do the following:
1. Get a module to provide a classpath to run. If no existent module has appropriate classpath, provide new module, without sources, but with proper dependencies.
2. If possible, put necessary library jars under the project directory. Add jars to the module dependencies. In project file they will be referred as $PROJECT_DIR$/somepath/library.jar, and so, the configuration will be the same on all workstations.
3. Otherwise, there is an option to go to Settings / Path variables and define one like GRAILS_HOME = /myworkstationpath/grails/. Add jars to the module dependencies. In project file they will be referred via defined variable. Every developer has to define same named variable on his workstation with proper path.
4. Specify this module in the run configuration settings.
After that the project files will be the same on all workstations.

> The thing is I have an helper class that test my real class (the one in my project). So in Test/Class in my run config I need to put my helper class
> and to give it a parameter -Dtest.file=[...] in 'VM parameters' with the corresponding filename to test.
It seems that such way is not supported. With such frameworks as JUnit a test class is typically tied to its tested class.

Alexander.

0
Comment actions Permalink

Ok, thanks a lot Alexander, this does answer my questions.

Thanks,

Cyril

0

Please sign in to leave a comment.