1

Currently I have 3 maven projects:

     ProjectCommon
    _______|________ 
    |              | 
ProjectA        ProjectB

Resulting on this 3 pom.xml:

#ProjectCommon/pom.xml

<groupId>my.package</groupId>
<version>1.0</version>

#ProjectB/pom.xml

<dependency>
   <groupId>my.package</groupId>
   <artifactId>ProjectCommon</artifactId>
   <version>1.0</version>
</dependency>

#ProjectB/pom.xml

<dependency>
   <groupId>my.package</groupId>
   <artifactId>ProjectCommon</artifactId>
   <version>1.0</version>
</dependency>

When I need to package my 2 apps (ProjectAand ProjectB) and always need to run this commands:

cd ProjectCommon && mvn install
cd ProjectA && mvn package
cd ProjectB && mvn package

There are any other way to configure my projects (like using Maven Modules) to do what I have now, instead of always need to install my ProjectCommon on my local repository?

Beto Neto
  • 3,962
  • 7
  • 47
  • 81

1 Answers1

-1

I recommend to create a structure like this:

+- root (pom.xml)
    +--- common (pom.xml)
    +--- projectA (pom.xml)
    +--- projectB (pom.xml)

The root contains two modules entries like this:

<modules>
  <module>projectA</module>
  <module>projectB</module>
  <module>common</module>
</modules>

Each child module should contain a parent entry like this (example for common module):

<parent>
  <groupId>my.package</groupId>
  <artifactId>parent</artifactId>
  <version>1.0-SNAPSHOT</version>
</parent>

<artifactId>common</artifactId>

Furthermore in the projectA/projectB you can define simply the dependency to common and now you can build all modules including your projects with a single command from root directory:

mvn clean package

or if you like to run integration tests:

mvn clean verify

There is no need to do an install...

One things is worth to mention with this setup you have to use a single version for all common, projectA, projectB and for root

khmarbaise
  • 92,914
  • 28
  • 189
  • 235
  • 1
    `you can build all modules` - but what if I don't want to build all modules but just common and ProjectA because tests on ProjectB can not be executed on my system or take hours to complete? – Robert May 10 '18 at 11:55
  • `you have to use a single version for all` this is a problem for me, because `ProjectA` and `ProjectB` are distinct apps and when I release a new version I do not want to release both. – Beto Neto May 10 '18 at 12:21
  • 1
    But based on your description you have a coupling to commons... from both projects. That means you have to handle commons separately and build and release it separately and update the release version in projects accordingly. Furthermore if projectA/projectB are separated you have to run/build/release them also separately..Apart from that I would recommend to start using a CI solution like jenkins which could make things easier.... – khmarbaise May 10 '18 at 12:37