Reputation: 21
I am trying to chain multiple maven properties (connected with a '-') in the same expression to be outputted to the command line using a single line command (this will be a command to be executed in a Jenkins pipeline). I believe I should be able to do achieve this using the maven-help-plugin. For example, if I run the following command:mvn help:evaluate
Then when prompted I interactively supply the multi-property expression: ${project.artifactId}-${project.version}
I get back the expected value: maven-tests-0.0.3-SNAPSHOT
I want to be able to use the plugin non-interactively by supplying the expression using the -Dexpression flag. As specified in the documentation for the maven-help-plugin, properties in the expression should not be wrapped by ${}, so I used the following command:
mvn help:evaluate -Dexpression=project.artifactId-project.version -q -DforceStdout
In return I get a null object or invalid expression
error.
It may be that the plugin completely disallows multiple properties in one expression using this method, but I could not find anything that seemed to suggest this.
mvn help:evaluate -Dexpression=${project.artifactId}-${project.version} -q -DforceStdout
mvn help:evaluate -Dexpression=project.artifactId\-project.version -q -DforceStdout
mvn help:evaluate -Dexpression=project.artifactId"-"project.version -q -DforceStdout
The version of the maven-help-plugin used is 3.2.0, managed from spring-boot-starter-parent.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>com.x.y</groupId>
<artifactId>maven-tests</artifactId>
<version>0.0.3-SNAPSHOT</version>
<name>maven-tests</name>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-help-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>parse-version</id>
<goals>
<goal>parse-version</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Upvotes: 2
Views: 136