Context:
The question is regarding a multi-module (maven, not Java 9 modules) Java project using maven for building it, where one module depends on the jar of another module.
Overview of the modules and some context:
- A: a library compiled to a jar.
- B: a client application, that depends on jar of A; compiled to an executable jar.
- C: a server application, neither depending on A nor B; compiled to an executable jar.
- I can only use Java 8 and thus no Java 9 modules.
- The IDE used is IntelliJ IDEA Ultimate.
What works:
- Building the modules to three separate jars (executable in case of B and C) using
mvn clean package
. - Importing the packages from module A into the classes of module B (not what I want).
- Adding a dependency to module A into the pom.xml of B (I don't know what effect this has...).
What I would like to achieve:
- I would like to add a dependency to the jar built from module A to the pom.xml of module B.
- I would like to import public classes and interfaces from the jar of module A in the classes of module B (by adding it as a dependency in the pom.xml and without copying the jar manually). -> Development and debugging of B should only depend on the last stable build of A and should not break with simultaneous development on the library A.
- The whole build process should be completed by executing one Bash script (once).
- Building the project should do the following steps in order:
- Build module A to a jar (if unavoidable also build B).
- Build (or rebuild) module B using the jar generated in step 1. to an executable jar.
- Build module C at any time during the build process.
Is there an elegant solution using maven for doing this?