Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven issue to build one module using revision property

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>

like image 475
Igor Grinfeld Avatar asked Dec 11 '16 13:12

Igor Grinfeld


1 Answers

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 following blog post.

like image 150
eschnou Avatar answered Oct 16 '22 04:10

eschnou