maven-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stephen Connolly <stephen.alan.conno...@gmail.com>
Subject Re: Plugin Configuration params take precedence over CLI Arguments?
Date Sat, 08 Aug 2015 14:36:01 GMT
When you don't specify the value in the POM you are *effectively*[1]
specifying <demoName>${demoName}</demoName>

So what you have done is disabled configuration via the CLI.

[1] I say *effectively* because if you did configure that and the property
was undefined then that explicit configuration would evaluate to the
literal string ${demoName} so this is more of a special case handling where
it is <demoName>${demoName}</demoName> if there is a property called
demoName and <demoName /> if there isn't

On 7 August 2015 at 19:55, Daniel Johnson (danijoh2) <danijoh2@cisco.com>
wrote:

> Hi,
>
> I am facing an issue I really did not expect, where a plugins
> <configuration> parameters in the POM take precedence over CLI
> –Dparam=value parameter values.
>
> My plugin takes a string parameter:
> @Mojo(name = "showValue", requiresProject = true, aggregator = true,
> defaultPhase = LifecyclePhase.PACKAGE, threadSafe = true)
> public class DemoMojo extends AbstractMojo {
>
>     /**
>      * The name of the property to print
>      */
>     @Parameter(property=“demoName”)
>     private String demoName;
>
>     public void execute() throws MojoExecutionException,
> MojoFailureException {
>         if (StringUtils.isEmpty(demoName)) {
>             getLog().info("demo-plugin: demoName variable was not given.");
>         } else {
>             getLog().info("demo-plugin: " + demoName);
>         }
>     }
> }
>
> So far this works as I expect:
>
> <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
> http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="
> http://maven.apache.org/POM/4.0.0"
>     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>   <modelVersion>4.0.0</modelVersion>
>   <groupId>com.danijoh2.project</groupId>
>   <artifactId>sample</artifactId>
>   <version>1.0.0-SNAPSHOT</version>
> <build>
>     <plugins>
>       <plugin>
>         <groupId>com.danijoh2</groupId>
>         <artifactId>demo-plugin</artifactId>
>         <version>1.0.0-SNAPSHOT</version>
>         <executions>
>           <execution>
>             <id>demo</id>
>             <goals>
>               <goal>showValue</goal>
>             </goals>
>           </execution>
>         </executions>
>       </plugin>
>     </plugins>
>   </build>
> </project>
>
> DANIJOH2-M-V0MA:Desktop danijoh2$ mvn clean install
> [INFO]
> ------------------------------------------------------------------------
> [INFO] Building sample 1.0.0-SNAPSHOT
> ...
> [INFO] --- demo-plugin:1.0.0-SNAPSHOT:showValue (default-cli) @ sample ---
> [INFO] demo-plugin: demoName variable was not given.
>
> And if I pass the parameter I see it is accepted:
> DANIJOH2-M-V0MA:Desktop danijoh2$ mvn clean install  –DdemoName=cliParam
> [INFO]
> ------------------------------------------------------------------------
> [INFO] Building sample 1.0.0-SNAPSHOT
> ...
> [INFO] --- demo-plugin:1.0.0-SNAPSHOT:showValue (default-cli) @ sample ---
> [INFO] demo-plugin: cliParam
>
> However, if I specify the parameter in the POM, I no longer see the CLI
> value being used:
>
>       <plugin>
>         <groupId>com.danijoh2</groupId>
>         <artifactId>demo-plugin</artifactId>
>         <version>1.0.0-SNAPSHOT</version>
>         <configuration>
>           <demoName>pomParam</demoName>
>         </configuration>
> …
>       </plugin>
>
> DANIJOH2-M-V0MA:Desktop danijoh2$ mvn clean install  –DdemoName=cliParam
> [INFO]
> ------------------------------------------------------------------------
> [INFO] Building sample 1.0.0-SNAPSHOT
> ...
> [INFO] --- demo-plugin:1.0.0-SNAPSHOT:showValue (default-cli) @ sample ---
> [INFO] demo-plugin: pomParam
>
> Shouldn’t the CLI parameter value override any value in the POM?
>
> Thanks,
> Daniel
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message