Maven Command Line

Is it possible to set environment variables in the build profile rather than set them on the command line?

For example, I want to enable the debugger when I use my test environment (-Denv = test).

I want maven to do this:

export MAVEN_OPTS="-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=n" 

This way I can quickly connect the debugger without repeating the repeating line over and over.

I do not believe that helps me in this case:

 <plugin> ... <!-- Automatically enable the debugger when running Jetty --> <argLine>-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,address=4000,server=y,suspend=n</argLine> </configuration> ... </plugin> 

Walter

+7
java command-line debugging maven-2
source share
1 answer

In recent versions of Maven, you can activate the debugger by running mvnDebug rather than mvn , the mvnDebug bat / sh file installs MVN__DEBUG_OPTS and passes them to java.exe. Past values:

 set MAVEN_DEBUG_OPTS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 

If this is not enough, this may work (note that I have not tested this yet, I will update as soon as I have). Maven reads properties with the prefix "env." from the environment you can set environment variables by pre-adding them. i.e:.

 <profile> <id>dev</id> <properties> <env.MAVEN_OPTS>-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000<env.MAVEN_OPTS> </properties> </profile> 

Update: the surefire plugin allows you to specify the system properties that will be used during the test. The configuration is as follows:

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.4.2</version> <configuration> <systemProperties> <property> <name>propertyName</name> <value>propertyValue</value> </property> </systemProperties> </configuration> </plugin> 

If none of them works for you, you can write a small plugin configured in your profile that binds to the initialization phase and sets your variables. The plugin would have this configuration:

 <plugin> <groupId>name.seller.rich</groupId> <artifactId>maven-environment-plugin</artifactId> <version>0.0.1</version> <executions> <execution> <id>set-properties</id> <phase>initialize</phase> <goals> <goal>set-properties</goal> </goals> </execution> </executions> <configuration> <properties> <env.MAVEN_OPTS>-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000<env.MAVEN_OPTS> </properties> </configuration> </plugin> 

at run time, the plugin will set each property passed with System.setProperty (). If the first two do not fit or do not work, this should solve your problem.

+11
source share

All Articles