Maven issue to build one module using revision property
Asked Answered
A

1

15

Recently we tried to deploy files using jenkins providing ${revision} property for the build ( Maven 3.3.9 ). It worked OK on json creating 0.0.1-SNAPSHOT for dev builds and 0.0.1-RC for releases, but we have an issue using maven on developer machines. We have multi-module maven project with version defined in parent and some modules uses others as dependencies. Both build it from jenkins and use maven locally, to integrate with IDEs and run tests before pushing it into repository. When we try to build a single module, maven does not recognize ${revision}, although it works fine when we mention all modules e.g. mvn clean install -pl appserver, we see

Failed to execute goal on project appserver: Could not resolve dependencies for project com.org:appserver:war:0.0.1-local: Failed to collect dependencies at com.org:my-kinesis-events:jar:0.0.1-local: Failed to read artifact descriptor for com.org:my-kinesis-events:jar:0.0.1-local: Could not transfer artifact com.org:my-parent:pom:${revision} from/to central: Failed to transfer .../repository/maven-central/com/org/my-parent/${revision}/my-parent-${revision}.pom. Error code 500, Server Error -> [Help 1]

We tried to use:

  • -Drevision=0.0.1-local

  • <profile> <id>default-version</id> <activation> <property> <name>!revision</name> </property> <activeByDefault>true</activeByDefault> </activation> <properties> <revision>0.0.1-local</revision> <project.version>0.0.1-local</project.version> </properties> </profile>

but the only thing that works is a build for parent that that builds the module and all modules it depends on:

mvn clean install -pl appserver,my-kinesis-events,module1,module2,...

Although the above works it requires from the team to define custom run configuration in IDE, each time they need something.

Did somebody also experienced this issue and found the solution?

Parent pom snippet: <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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.org</groupId> <artifactId>my-parent</artifactId> <version>${revision}</version> <packaging>pom</packaging> <name>My Parent module</name>
<modules> <module>../my-tools</module> <module>my-kinesis-events</module> .... </modules> ..... </project> <dependencyManagement> <dependencies> <dependency> <groupId>my.org</groupId> <artifactId>my-kinesis-events<</artifactId> <version>${project.version}</version> <dependency> <dependencies> </dependencyManagement>

Module pom snippet: <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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <artifactId>appServer</artifactId> <parent> <groupId>com.org</groupId> <artifactId>my-dsp</artifactId> <version>${revision}</version> <relativePath>..</relativePath> </parent> <packaging>war</packaging> <name>AppServerAPI</name> <description>Application Server</description> <dependencies> <dependency> <groupId>com.org</groupId> <artifactId>my-openrtb</artifactId> </dependency> ..... </dependencies> .... </project>

Auriscope answered 11/12, 2016 at 13:7 Comment(3)
Unfortunately there is currently a bug exactly related to that in Maven see details in MNG-6090...Another issue related to that has already been fixed for Maven 3.4.0 (see MNG-6057)Kress
Thanks. This creates three other questions. First, where I can find maven 3.4.0 (maven.apache.org/docs/history.html states that 3.3.9 is the latest ). Second, when MNG-690 is planned to be resolved? Third, does any workaround exists until it'll be resolved?Auriscope
Maven 3.4.0 is not released yet...Apart from that Maven is an open source project so there does not exist a plan when what will be resolved...Unfortunately there exist no workaround at the moment...Kress
W
22

These issues have been fixed since Maven 3.5, you need however to use the maven flatten plugin to ensure that all variables are removed from your POM before publishing. Otherwise you end up having POM containing ${revision} has version.

This is neatly explained in the official maven documentation:

https://maven.apache.org/maven-ci-friendly.html#install-deploy

Westberg answered 18/10, 2018 at 20:43 Comment(3)
The blog post link is broken.Chartist
This article can be found here blog.soebes.io/posts/2017/04/…Killen
Needed to add : <build> <plugins>. <plugin>. <groupId>org.codehaus.mojo</groupId>. <artifactId>flatten-maven-plugin</artifactId>. </plugin>. <plugin>. <groupId>org.codehaus.mojo</groupId>. <artifactId>properties-maven-plugin</artifactId>. </plugin>. </plugins>. </build>.Interpenetrate

© 2022 - 2024 — McMap. All rights reserved.