0

I have a multi module maven project for e.g.

A B C D E Currently this project is working fine and have a single job to build all the modules and upload to the artifactory with some version for e.g. 4.0.0-.They are using versions:set -DnewVersion=4.0.0-${BUILD_NUMBER} from Jenkins job.Now my next task is to split this project into module so they dev team can build each module independetly but my issue is some modules is having the dependecy on other modules for e.g

Module B is having dependecy on module A and Module C.if I build the module A first then it generate the number 4.0.0-00001 and upload it to the artifactory and then I build the module C then it generate the build 4.0.0-00005.Now the question comes how could I build the module B which is having the dependency on module A and C.In my opinion I need to define the version of module A and C explicitly in the dependency section.

     <dependency>
        <groupId>com.xyz.engine</groupId>
        <artifactId>A</artifactId>
        <version>4.0.0-00005</version>
     </dependency>

From my module POM I am calling my parent POM and In jenkins job I am giving versions:set -DnewVersion=4.0.0-${BUILD_NUMBER} for versioning purpose if I explicity define the version of A module then it is also passing the same value to the Parent POM and searching for it which is not avilable.Below is my module POM file

<?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.truvenhealth.analyticsengine</groupId>
        <artifactId>AnalyticsEngine</artifactId>
        <version>4.0.0-00002</version>
    </parent>

    <artifactId>LicenseVerifier</artifactId>
    <name>LicenseVerifier</name>
    <packaging>jar</packaging>

    <dependencies>
        <!-- Modules dependencies -->
        <dependency>
            <groupId>com.xyz.engine</groupId>
            <artifactId>Common</artifactId>
            <version>4.0.0-00007</version>
         </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>

        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>

        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
        </dependency>



        <!-- External dependencies -->
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-collections4</artifactId>
        </dependency>

        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
        </dependency>

        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjtools</artifactId>
            <version>1.6.2</version>
        </dependency>

        <dependency>
            <groupId>com.verhas</groupId>
            <artifactId>license3j</artifactId>
            <version>1.0.4</version>
        </dependency>

    </dependencies>


    <build>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>false</filtering>
            </resource>
        </resources>

        <plugins>
            <!-- Plugin configurations inherited from the parent POM -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
            </plugin>

            <plugin>
                <groupId>org.jacoco</groupId>
                <artifactId>jacoco-maven-plugin</artifactId>
            </plugin>

            <plugin>
                <groupId>org.projectlombok</groupId>
                <artifactId>lombok-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

it is taking the same value for Parent POM which I assigned to Common module .I am keeping the Parent POM in separate repository it should not take the same value it should only take that value which I am defining for the Parent POM and it should download it from their and provide all the values to module POM and the build should be created for module LicenseVerifier with different version.

unknown
  • 1,815
  • 3
  • 26
  • 51

1 Answers1

0

If you have a multi module build which looks like this:

root (pom.xml parent of all modules)
 +---- module-a (pom.xml)
 +---- module-b (pom.xml)
 +---- module-c (pom.xml)
 +---- module-d (pom.xml)

To build a module separately you can do this via Maven like this:

mvn -pl module-a  clean package

This will build the module-a only and get the dependencies of other modules from the remote repository. Or you can enhance that like this:

mvn -pl module-a -amd clean package

where the option -amd means --also-make-dependents. If a developer needs a particular state you can do this by a mvn install first and afterwards only build the module you would like to build.

A very important thing in relationship with multi module builds is to have the same version for all modules and the parent. So dependencies between those modules is no problem.

Starting with Maven 3.2.1 you can define the version via properties.

A simple change to prevent Maven from emitting warnings about versions with property expressions. Allowed property expressions in versions include ${revision}, ${changelist}, and ${sha1}. These properties can be set externally, but eventually a mechanism will be created in Maven where these properties can be injected in a standard way. For example you may want to glean the current Git revision and inject that value into ${sha1}. This is by no means a complete solution for continuous delivery but is a step in the right direction.

Furthermore during development i would prefer the SNAPSHOT versions which the cleanup in the repository manager simpler. So in essence i don't any need to separate the modules which logicaly belong together.

Apart from that if you use the same version within your multimodule build you can use things like this: ${project.version} to define the version of a dependency which is part of the reactor.

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • Thanks for giving me the answer but here my need is build the independent module but that module is having the dependecy to other module jar/zip/war file which is having specific version but while I specifiy that version in my module POM for e.g. 4.0.0-00007 then it passes that same version to PARENT POM and get failed beacuse either PARENT POM doesn't have that version. . – unknown Apr 23 '15 at 16:14
  • I am having the same structure for maven -project which you described above I am running it from Jenkins and generating the Jenkins build number with my version which I mentioned for e.g. 4.0.0-34 and it is passing the same value to all child POM file.when I run this it passes this value to child which change the version of dependent module and the job get failed beacuse the common modules doesn't have that build in artifactory. – unknown Apr 23 '15 at 21:53