-2

Could someone let me know easy way to handle internal dependencies for maven projects. For now I have following things.

  1. MainPorject depends on project A, B and C - Fat jar
  2. Project A needs project B for compilation - Thin Jar
  3. and project b depends on project c on compilation - Thin Jar

for now, I manually compile all the jar files from A,B and C project from their respective repos and put in mainProject to crate fat jar.

Is there a way I can provide config in such a way that when I compile mainProject it automatically fetches the latest code A,B and C repo? Same goes for project A and Project B.

Gaurang Shah
  • 11,764
  • 9
  • 74
  • 137
  • 2
    I think you have to structure project A B and C like it describes in https://stackoverflow.com/a/15383584/2880879. And if you want to fetch latest code for every build then you need some sort of CI tools like Jenkins and GoCD etc But this dose not apply to development environment . For more information about multi module maven project structure build example ref https://books.sonatype.com/mvnex-book/reference/multimodule.html – user2880879 May 26 '20 at 00:21
  • If you have all the project sources locally in properly configured projects A, B, C, MainProject with POM as the previous comment suggested, and they're up to date before you build (something like git pull takes less than a minute), you shouldn't need anything more. when using A,B,C as mainProject's modules dependencies, they will be compiled in the right order before to be used to compile the mainProject. – Alessio Moraschini May 26 '20 at 00:35

2 Answers2

0

Build a multi-module project that contains all three projects as modules. Then you always build everything with the latest code. And Maven takes care that everything is built in the right order.

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
0

You need a multi-module Maven project, with this setup:

<!-- parent -->
<groupId>com.stackoverflow</groupId>
<artifactId>parent</artifactId>
<version>1.0.0</version>

<modules>
  <module>C</module>
  <module>B</module>
  <module>A</module>
  <module>Bundle</module>
</modules>

<!-- each module, optionally, if you want to let parent manage the dependency versions -->
<parent>
  <groupId>com.stackoverflow</groupId>
  <artifactId>parent</artifactId>
  <version>1.0.0</version>
  <relativePath>../pom.xml</relativePath>
</parent>

Parent pom.xml sits in a root directory and A, B, C, Bundle are direct children of the root directory.

<root>
|   pom.xml
|
+---A
|       pom.xml
|
+---B
|       pom.xml
|
+---Bundle
|       pom.xml
|
\---C
        pom.xml
Silviu Burcea
  • 5,103
  • 1
  • 29
  • 43