How to config multi-module project in Maven assembly to create one fat jar with all dependencies and chosen entrypoint?
I have multi-module project
main(parent) pom
<artifactId>parentModule</artifactId>
<groupId>com.myapps</groupId>
[...]
<modules>
<module>childModule1</module>
<module>childModule2</module>
</modules>
child pom 1
<artifactId>childModule1</artifactId>
<groupId>com.myapps</groupId>
[...]
<parent>
<artifactId>parentModule</artifactId>
<groupId>com.myapps</groupId>
</parent>
child pom 2 (with entry point com.myapps.application.App ,and depends on childModule1)
<artifactId>childModule2</artifactId>
<groupId>com.myapps</groupId>
[...]
<parent>
<artifactId>parentModule</artifactId>
<groupId>com.myapps</groupId>
</parent>
[...]
<dependencies>
<dependency>
<artifactId>childModule1</artifactId>
<groupId>com.myapps</groupId>
</dependency>
</dependencies>
What config I have to add to my poms(assembly plugin tag) and my assembly.xml to create one fat jar with all needed dependencies(including childModule1) running from entrypoint(which is in childModule2)?
My plugin tag in main(parent) pom includes:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>assembly/assembly.xml</descriptor>
</descriptors>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.myapps.application.App</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
And assembly.xml consists of "filesets" tags, and tag "format".
What additional config I have to add to my poms or assembly config xml, to create one full-operational fat jar as a result? For now it makes distributive with files successfully but fails to create jar with an error - "archive can not be empty". I suppose that it makes by "moduleset" tags in assembly, I have read docs, but cant understand how to do it.
UPD Do I need to create plugin tag in parentmodule with descriptor "assembly/assembly.xml"(with fileset instructions) and separate plugin tag in childmodule2 with descriptor "jar-with-dependencies"?
This can be done in multiple ways, but I have some time ago distilled this into a step-by-step approach in: https://ath3nd.wordpress.com/2013/12/25/packaging-a-multimodule-maven-spring-app-in-a-standalone-jar/
However, there are multiple other ways to do so, which might be a bit more modern. For example, some use maven-shade-plugin
, some can use spring-boot-maven-plugin
(I currently use that to embed my jetty
inside), but there you have a bit less control over what's going on, as they do a lot of the heavy lifting for you.
If you are stuck with having to use the maven-assembly-plugin
, then you can combine it with:
maven-jar-plugin
maven-dependency-plugin