You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@maven.apache.org by "Daniel Johnson (danijoh2)" <da...@cisco.com> on 2015/08/07 20:55:41 UTC
Plugin Configuration params take precedence over CLI Arguments?
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
Re: Plugin Configuration params take precedence over CLI Arguments?
Posted by Stephen Connolly <st...@gmail.com>.
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) <da...@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
>
>
Re: Plugin Configuration params take precedence over CLI Arguments?
Posted by Stephen Connolly <st...@gmail.com>.
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) <da...@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
>
>