Maven project with multiple module and multiple assembly

811 views Asked by At

I'm having difficulties trying to construct a maven project with multiple module and each module has its own assembly.

I'm not too sure if this can be done in maven or not in the first place.

I have a project structure like so:

project
 +- root
 |  +- pom.xml
 +- module-common
 |  +- pom.xml
 |  +- src 
 |  |  +- main
 |  |  |  +- java
 |  |  +- test
 |  |     +- java
 |  +- target  
 + module-client
 |  +- pom.xml
 |  +- src
 |  |  +- main
 |  |     +- java
 |  |     +- assembly
 |  |     +- scripts
 |  |     +- resources
 |  |  +- test
 |  |     +- java
 |  +- target
 + module-server
    +- src
    |  +- main
    |  |  +- java
    |  |  +- assembly
    |  |  +- scripts
    |  |  +- resources
    |  +- test
    |     +- java
    +- target

A few key points to explain the structure

  • I'm trying to create a remoting application, hence the server and client component

  • root is the parent for all modules, and it's a pom packaging

  • the common classes will be in the common module

  • both server and client module will depend on common

I can assemble the project correctly by issuing maven assembly 3 times

mvn clean package                 (on the root)
mvn clean package assembly:single (on the client)
mvn clean package assembly:single (on the server)

I'm trying to find a way where I can just call

mvn clean package

on the root module, and both assemblies (in the client and server) will be called and each will run according to its own assembly descriptor

I cannot use the same assembly descriptor to run on both modules because they are assembled differently.

The client is assembled with the "resource" packaged in the main jar file, and only scripts outside

The server is assembled with the "resource" packaged out of the main jar file.

1

There are 1 answers

2
aurya On BEST ANSWER

In your root pom.xml add this :

<modules>
    <module>module-common</module>
    <module>module-client</module>
    <module>module-server</module>
</modules>

And Use this folder structure :

project
 +- root
    +- pom.xml
    +- module-common
    |  +- pom.xml
    |  +- src 
    |  |  +- main
    |  |  |  +- java
    |  |  +- test
    |  |     +- java
    |  +- target  
    + module-client
    |  +- pom.xml
    |  +- src
    |  |  +- assembly
    |  |  +- main
    |  |     +- java
    |  |     +- scripts
    |  |     +- resources
    |  |  +- test
    |  |     +- java
    |  +- target
    + module-server
       +- src
       |  +- assembly
       |  +- main
       |  |  +- java
       |  |  +- scripts
       |  |  +- resources
       |  +- test
       |     +- java
       +- target