Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build a multi-module maven project in jenkins

Tags:

maven

jenkins

I have a projects structure as follows:

ProjectParent
 - pom.xml
 ProjectApp
   -pom.xml
 ProjectAPI
   -pom.xml
 ProjectModels
   -pom.xml
 ProjectServices
   -pom.xml
 Etc..

ProjectModels/ProjectsServices are dependencies within ProjectAPI/ProjectApp.

  1. Should I create separate jobs within Jenkins to build each module separately?

  2. I created a job for ProjectAPP but get the following error below (Have set goals and actions to "clean install":

[INFO] Scanning for projects... [INFO]
[INFO] ------------------------------------------------------------------------ [INFO] Building myproject-app 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------

Downloading: http://maven.springframework.org/snapshot/com/myproject/myproject-common-config/0.0.1-SNAPSHOT/myproject-common-config-0.0.1-SNAPSHOT.pom
[WARNING] The POM for com.myproject:myproject-common-config:jar:0.0.1-SNAPSHOT is missing,

no dependency information available Downloading: http://maven.springframework.org/snapshot/com/myproject/myproject-entities/0.0.1-SNAPSHOT/myproject-entities-0.0.1-SNAPSHOT.pom [WARNING] The POM for com.myproject:myproject-entities:jar:0.0.1-SNAPSHOT is missing, no dependency information available Downloading: http://maven.springframework.org/snapshot/com/myproject/myproject-services/0.0.1-SNAPSHOT/myproject-services-0.0.1-SNAPSHOT.pom [WARNING] The POM for com.myproject:myproject-services:jar:0.0.1-SNAPSHOT is missing, no dependency information available Downloading: http://maven.springframework.org/snapshot/com/myproject/myproject-persistence/0.0.1-SNAPSHOT/myproject-persistence-0.0.1-SNAPSHOT.pom [WARNING] The POM for com.myproject:myproject-persistence:jar:0.0.1-SNAPSHOT is missing, no dependency information available Downloading: http://maven.springframework.org/snapshot/com/myproject/myproject-common-config/0.0.1-SNAPSHOT/myproject-common-config-0.0.1-SNAPSHOT.jar ...... org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal on project myproject-app: Could not resolve dependencies for project com.myproject:myproject-app:war:0.0.1-SNAPSHOT: The following artifacts could not be resolved: com.myproject:myproject-common-config:jar:0.0.1-SNAPSHOT, com.myproject:myproject-entities:jar:0.0.1-SNAPSHOT, com.myproject:myproject-services:jar:0.0.1-SNAPSHOT, com.myproject:myproject-persistence:jar:0.0.1-SNAPSHOT: Could not find artifact com.myproject:myproject-common-config:jar:0.0.1-SNAPSHOT in org.springframework.maven.snapshot (http://maven.springframework.org/snapshot)


ProjectParent Pom

<?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>
    <groupId>com.myproject</groupId>
    <artifactId>myproject-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>

    <modules>
        <module>myproject-entities</module>
        <module>myproject-services</module>
        <module>myproject-persistence</module>
        <module>myproject-app</module>
        <module>myproject-merchant</module>
        <module>myproject-common-config</module>
        <module>myproject-api</module>
    </modules>

    <dependencyManagement>
        <dependencies>
            ...
        </dependencies>
    </dependencyManagement>

    <repositories>      
        ...
    </repositories>

    <build>
        ...
    </build>

    <properties>
        ...

        <myproject-entities-version>0.0.1-SNAPSHOT</myproject-entities-version>
        <myproject-services-version>0.0.1-SNAPSHOT</myproject-services-version>
        <myproject-persistence-version>0.0.1-SNAPSHOT</myproject-persistence-version>
    </properties>

</project>


ProjectApp Pom

<?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com.myproject</groupId>
        <artifactId>myproject-parent</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>

    <artifactId>myproject-app</artifactId>
    <packaging>war</packaging>

    <version>0.0.1-SNAPSHOT</version>
    <name>myproject-app</name>
    <url>http://maven.apache.org</url>


    <dependencies>

        ...

        <dependency>
            <groupId>com.myproject</groupId>
            <artifactId>myproject-common-config</artifactId>
            <version>${myproject-common-config}</version>
        </dependency>

        <dependency>
            <groupId>com.myproject</groupId>
            <artifactId>myproject-entities</artifactId>
            <version>${myproject-entities-version}</version>
        </dependency>

        <dependency>
            <groupId>com.myproject</groupId>
            <artifactId>myproject-services</artifactId>
            <version>${myproject-services-version}</version>
        </dependency>

        <dependency>
            <groupId>com.myproject</groupId>
            <artifactId>myproject-persistence</artifactId>
            <version>${myproject-persistence-version}</version>
        </dependency>

    </dependencies>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <myproject-common-config>0.0.1-SNAPSHOT</myproject-common-config>
        <myproject-entities-version>0.0.1-SNAPSHOT</myproject-entities-version>
        <myproject-services-version>0.0.1-SNAPSHOT</myproject-services-version>
        <myproject-persistence-version>0.0.1-SNAPSHOT</myproject-persistence-version>
    </properties>

</project>


Am I using the wrong goals? Do I need to chain a number of commands? i.e. build other modules first?

I'm using Maven 3.

NOTE: I changed the target to "clean install" against the ParentProject Pom and everything builds correctly.

Thanks

like image 435
Thomas Buckley Avatar asked Apr 21 '13 21:04

Thomas Buckley


2 Answers

The problem is that you can't create a project solely for the ProjectApp module because it depends on the other modules below the ProjectApp parent. If you don't deploy those modules to your maven repository, maven is not able to find them in the repository nor in the build reactor.

Instead you should create the job for the parent. This will build the necessary modules.

You may also work with the option also-make-dependants when you have a job for ProjectApp, but I haven't any experience with this.

like image 88
SpaceTrucker Avatar answered Sep 28 '22 10:09

SpaceTrucker


Had the same problem, and SpaceTrucker answer helped me.

Hence I just run something like:

.../ProjectParent$ mvn -am -pl ProjectApp test

like image 35
yashaka Avatar answered Sep 28 '22 09:09

yashaka