Search code examples
javamavenmaven-module

Maven multimodule library build


I'm developing library with Maven system, which is published in the Nexus repository. In the nexus (and the maven build as well), the project produces the final jar named <projectName>-<version>.jar - this is exactly what I want.

Now, I decided to split the library into maven modules and therefore top level pom.xml have <packaging>pom</packaging>. The build also do not produce final <projectName>-<version>.jar, instead it produces <moduleName>-<version>.jar for each module.

What I want to achieve is to have the project split into modules and be able to produce final <projectName>-<version>.jar containing defined modules. Is this possible? Is it possible to solve this issue migrating to the Gradle?


Solution

  • When you decided to split the library into multi modules it means that you decided to build them independently. So it's expected that each module creates it's own <moduleName>-<version>.jar.

    Now when you use the created modules as dependencies for the bigger module with scope of compile maven would automatically add them to lib of the project.

    So in your case you don't need to change packaging to pom and just add the modules as dependency in the pom.xml file and let maven to create the final jar for you.

    Also if you want use pom packaging there is a good question here which might help you.