Maven variables precedence: how to make env variable being more important than hardcoded value in pom.xml? -


i'd implement, in maven, way of passing variables pom via env variable using default value if not provided.

i created minimalitic pom.xml prints foo , foobar vars. foobar has default value:

<project>     <groupid>com.example</groupid>     <artifactid>test</artifactid>     <version>sprint-snapshot</version>     <modelversion>4.0.0</modelversion>     <properties>         <foobar>1111111</foobar>     </properties>     <build><plugins><plugin><groupid>org.apache.maven.plugins</groupid><artifactid>maven-antrun-plugin</artifactid><version>1.1</version>         <executions><execution>                 <phase>validate</phase><goals><goal>run</goal></goals>                 <configuration><tasks>                         <echo>foo = ${foo}</echo>                         <echo>foobar = ${foobar}</echo>                 </tasks></configuration>         </execution></executions>     </plugin></plugins></build> </project> 

now, let’s try run passing value command line, or via env variable:

me@mymachine /d/mvn-tests $ mvn install | grep foo      [echo] foo = ${foo}      [echo] foobar = 1111111  me@mymachine /d/mvn-tests $ mvn install -dfoo=999 | grep foo      [echo] foo = 999      [echo] foobar = 1111111  me@mymachine /d/mvn-tests $ foo=999 mvn install | grep foo      [echo] foo = 999      [echo] foobar = 1111111  me@mymachine /d/mvn-tests $ mvn install -dfoobar=555 | grep foo      [echo] foo = ${foo}      [echo] foobar = 555  me@mymachine /d/mvn-tests $ foobar=555 mvn install | grep foo      [echo] foo = ${foo}      [echo] foobar = 1111111 

the last scenario 1 don’t like: i’d prefer env variable take precedence on property defined in top of xml (i want 1 hardcoded in xml last-resort check).

so seems maven’s precedence follows:

command line param > hardcoded xml value > env variable 

i’d have:

command line param > env variable > hardcoded xml value 

is there way can achieve behaviour want?

i’ve noticed can use env.foobar point unambiguously env variable:

...     <echo>foo = ${foo}</echo>     <echo>foobar = ${foobar}</echo>     <echo>env.foobar = ${env.foobar}</echo> 

and then

me@mymachine /d/mvn-tests $ foobar=15 mvn install | grep foo [echo] foo = ${foo} [echo] foobar = 1111111 [echo] env.foobar = 15 

but how in pom.xml sth in js file ${env.foobar || foobar} i.e. take 1 env, if not specified, take other one?

i think you'd better off using maven profiles , defining behavior/values based on that. have @ documentation.

this way you'll able fine-tune variables wish.


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -