0

There are several applications that need to be built and packaged from a number of modules.

In parent pom, i'm using the profile to invoke builds for different apps.

root
  parent/
     pom.xml
  moduleA/
     pom.xml
  moduleB/
     pom.xml
  moduleC/
     pom.xml

For example, app "profile-1" would need a subset of existing modules to be built and put together as a tar ball. The tar would contain several jars and different config files pulled from the target/ of the sub modules.

I'm using a shell script invoked using exec-maven-plugin to put together the tar.

The problem I'm facing is that, in one application, i need to build the same module multiple times but with different maven parameters.

What is the best way to do this?

<profiles>
        <profile>
            <id>profile-1</id>
            <modules>
                <module>../moduleA</module>
                <module>../moduleB</module>
                <!-- <module>../moduleC</module> -->
            </modules>
            <properties>
                <global.version>0.0.1-SNAPSHOT</global.version>
            </properties>
            <build>
                <!-- use maven exec plugin to run a shell script which generates the tar ball picking jars and config files from different modules target dirs -->
                <plugins>
                </plugins>
            </build>
        <profile>
</profiles>

A sample sub module pom

<groupId>com.test</groupId>
    <artifactId>moduleC</artifactId>
    <packaging>bundle</packaging>
    <version>${global.version}</version>

    <name>test :: ${project.artifactId} :: ${name} </name>


    <parent>
      <groupId>com.test</groupId>
      <artifactId>parent</artifactId>
      <version>${global.version}</version>
      <relativePath>../parent</relativePath>
    </parent>

Things i tried:
1) Can i separate into multiple profiles and invoke them as -Pprofile-1,profile-2?
It did not work for me but i would be doing something wrong.

2) Have another shell script that has mvn command line to build the moduleC in different ways.
- Even though i pass in the "-Dglobal_version", the moduleC run from mvn command line does not seem to find the parent in the repository.

I tried doing a "-N" build to put the parent pom in the repository before building the application but did not help.

user127091
  • 183
  • 1
  • 1
  • 13
  • 1
    "I'm using a shell script invoked using exec-maven-plugin to put together the tar.". This is a big indication that you are doing something wrong somewhere. Assemblies are usually done with the `maven-assembly-plugin`. Why do you have that many profiles? That also is a smell in your build. – Tunaki Feb 08 '16 at 22:11
  • i can use the assembly plugin. I need to build and package different applications that are put together using different combinations of the sub modules. But how can i build the same module multiple times by passing in different maven params? – user127091 Feb 08 '16 at 22:51

1 Answers1

0

Best way is:

mvn clean install --projects moduleA, moduleB
mvn clean install --projects moduleB, moduleC

You can't run multiple builds with maven (see this stackoverflow question)

Gabriel
  • 408
  • 5
  • 12