Maven friendly CI - revision property doesn't work with Jenkins build

Viewed 904

I'm trying to use maven friendly ci for my multi-module project. My project has three levels of parent child hierarchy, i.e., my parent project has few child projects and those child projects has many other child projects within them.

I have added a sample of my pom files below. My parent pom has a flatten plugin as well, everything works fine in my local machine. But when I build it from Jenkins, it doesn't work. And I get the below error

Error

[ERROR] [ERROR] Some problems were encountered while processing the POMs: [FATAL] Non-resolvable parent POM for com.faskan:child-module:[unknown-version]: Could not transfer artifact com.faskan:parent-module:pom:${revision} from/to nexus

Parent project's pom.xml

<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
         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>

    <parent>
        <groupId>org.faskan</groupId>
        <artifactId>global-parent-dependency</artifactId>
        <version>1.1.0</version>
    </parent>

    <groupId>org.faskan</groupId>
    <artifactId>parent-module</artifactId>
    <version>${revision}</version>
    <packaging>pom</packaging>

    <name>project parent pom</name>

    <properties>
        <revision>21.15.0-SNAPSHOT</revision>
    </properties>

   <build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>flatten-maven-plugin</artifactId>
            <version>1.2.2</version>
            <configuration>                
            </configuration>
            <executions>
                <!-- enable flattening -->
                <execution>
                    <id>flatten</id>
                    <phase>process-resources</phase>
                    <goals>
                        <goal>flatten</goal>
                    </goals>
                </execution>
                <!-- ensure proper cleanup -->
                <execution>
                    <id>flatten.clean</id>
                    <phase>clean</phase>
                    <goals>
                        <goal>clean</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

...
</project>

Child project's pom.xml

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <artifactId>child-module</artifactId>

    <parent>
        <groupId>org.faskan</groupId>
        <artifactId>parent-module</artifactId>
        <version>${revision}</version>
    </parent>

    <name>child admin</name>

    <packaging>jar</packaging>
..
</project>

Child of child project (grand child)

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>
    <artifactId>grand-child-module</artifactId>
    <packaging>jar</packaging>

    <name>child of child module</name>

    <parent>
        <groupId>org.faskan</groupId>
        <artifactId>child-module</artifactId>
        <version>${revision}</version>
    </parent>
..
</project>

I found a similar question How do you get maven child projects to build in Jenkins when using CI Friendly versions?. Not sure if mine is the same because I don't get any parse failure errors.

2 Answers

The following configuration is missing in your parent pom.xml for the flatten plugin:

<configuration>
  <updatePomFile>true</updatePomFile>
  <flattenMode>resolveCiFriendliesOnly</flattenMode>
</configuration>  

I believe you have to add this configuration for ci-friendly projects, as explained here.

In

    <parent>
        <groupId>org.faskan</groupId>
        <artifactId>parent-module</artifactId>
        <version>${revision}</version>
    </parent>

you can't have ${revision} for version. Maven don't know where to get it. You need to use actual version.

PS: I don't know how you manage to build it locally.

Related