I'm using the gmaven-plugin to set a custom system property in my POM. This seems to work, as I'm able to successfully echo the property using the maven-antrun-plugin; however, the maven-deploy-plugin seems completely unaware of the property and is unable to resolve it.
Relevant portion of the POM:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
System.setProperty("nodotsversion", "${env.PATCH_VERSION}".replace('.', ''))
</source>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version><!-- 1.2 in central -->
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<configuration>
<target>
<echo message="${nodotsversion}" />
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.6</version>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<repositoryId>artifactory</repositoryId>
<packaging>sql</packaging>
<generatePom>true</generatePom>
<url>${project.distributionManagement.snapshotRepository.url}</url>
<groupId>com.company.product</groupId>
<artifactId>patch${nodotsversion}</artifactId>
开发者_如何学Go <version>1.0.0-SNAPSHOT</version>
<file>${WORKSPACE}/myfile.sql</file>
</configuration>
</plugin>
</plugins>
</build>
When I run this with mvn clean install deploy:deploy-file
, I get the following error:
Caused by: org.apache.maven.plugin.MojoExecutionException: The artifact information is incomplete or not valid:
[0] 'artifactId' with value 'patch${nodotsversion}' does not match a valid id pattern.
Why is the maven-antrun-plugin able to resolve my custom system property, while the maven-deploy-plugin is not?
I'm not sure, but I believe that the ${...}
placeholder syntax can only resolve project properties. I believe the system properties are added to the project properties at a point in the build, which is why system properties are available in this way, but a system property added later in the build won't be available. You should add the property to the project properties instead.
I'm not sure how this is related, but I recently figured out a problem I was having using the ${...}
syntax and the gmaven-plugin. In my plugin I was generating a finalName for the build. This part of the pom looks like:
<build>
<finalName>${my.final.name}</finalName>
Then, in the maven <source>
section I had something like:
def myvar = "prefix${someothervar}suffix"
project.properties['my.final.name'] = myvar
The pom was for a war. When I ran maven, the output was always:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on project myservice: The parameters 'warName' for goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war are missing or invalid -> [Help 1]
After much head scratching I finally figured out how to solve the problem. myvar
needed to be declared as a String!
String myvar = "prefix${someothervar}suffix"
project.properties['my.final.name'] = myvar
精彩评论