Create multiple runnable Jars (with dependencies included) from a single Maven project [duplicate]

You can do it. You’ll need a separate execution for each artifact that you’re building (i.e., give each its own id but you can leave the phase as default), and you’ll need to specify the finalName and archive/manifest/mainClass for each. <build> <plugins> <plugin> <artifactId>maven-assembly-plugin</artifactId> <executions> <execution> <id>build-a</id> <configuration> <archive> <manifest> <mainClass>foobar.Aclass</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> … Read more

maven-assembly-plugin doesn’t add dependencies with system scope

you can do it by adding this dependencySet to your assembly file descriptor <dependencySet> <outputDirectory>/</outputDirectory> <unpack>true</unpack> <scope>system</scope> </dependencySet> this assembly descriptor add all dependencies including system scoped <assembly xmlns=”http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0″ xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd”> <id>jar-with-all-dependencies</id> <formats> <format>jar</format> </formats> <includeBaseDirectory>false</includeBaseDirectory> <dependencySets> <dependencySet> <outputDirectory>/</outputDirectory> <useProjectArtifact>true</useProjectArtifact> <unpack>true</unpack> <scope>runtime</scope> </dependencySet> <dependencySet> <outputDirectory>/</outputDirectory> <unpack>true</unpack> <scope>system</scope> </dependencySet> </dependencySets> </assembly>

Creating Two Executable Jars Using maven-assembly-plugin

So as soon as I posted this, I found this thread: Create multiple runnable Jars (with depencies included) from a single Maven project This uses a different approach in that it doesn’t use two profiles, it uses two executions, as such: <plugin> <artifactId>maven-assembly-plugin</artifactId> <version>2.4</version> <executions> <execution> <id>build-publisher</id> <configuration> <appendAssemblyId>false</appendAssemblyId> <archive> <manifest> <mainClass>fully.qualified.path.Publisher</mainClass> </manifest> </archive> <descriptorRefs> … Read more

Maven assembly : add different version of the same artifact

I found a solution by using maven-dependency-plugin to copy resolved pom dependencies and additional jar. <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.1</version> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/lib</outputDirectory> <overWriteReleases>false</overWriteReleases> <overWriteSnapshots>false</overWriteSnapshots> <overWriteIfNewer>true</overWriteIfNewer> <includeScope>runtime</includeScope> </configuration> </execution> <execution> <id>copy-model</id> <phase>package</phase> <goals> <goal>copy</goal> </goals> <configuration> <artifactItems> <artifactItem> <groupId>my.test.pkg</groupId> <artifactId>my-model</artifactId> <classifier>server</classifier> <version>1.0.3</version> <type>jar</type> </artifactItem> <artifactItem> <groupId>my.test.pkg</groupId> <artifactId>my-model</artifactId> <classifier>server</classifier> <version>1.1.0</version> <type>jar</type> … Read more

Using maven to output the version number to a text file

Sure. Create a text file somewhere in src/main/resources, call it version.txt (or whatever) File content: ${project.version} now in your pom.xml, inside the build element, put this block: <build> <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <includes> <include>**/version.txt</include> </includes> </resource> <resource> <directory>src/main/resources</directory> <filtering>false</filtering> <excludes> <exclude>**/version.txt</exclude> </excludes> </resource> … </resources> </build> after every build, the file (which you can find … Read more

Idea to avoid that spring.handlers/spring.schemas get overwritten when merging multiple spring dependencies in a single jar

I managed to get rid of the bug using the shader plugin instead of the (buggy) assembler plugin: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <executions> <execution> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <transformers> <transformer implementation=”org.apache.maven.plugins.shade.resource.ManifestResourceTransformer”> <mainClass>at.seresunit.lecturemanager_connector.App</mainClass> </transformer> <transformer implementation=”org.apache.maven.plugins.shade.resource.AppendingTransformer”> <resource>META-INF/spring.handlers</resource> </transformer> <transformer implementation=”org.apache.maven.plugins.shade.resource.AppendingTransformer”> <resource>META-INF/spring.schemas</resource> </transformer> </transformers> </configuration> </execution> </executions> </plugin> I think I found the solution on the springsource … Read more

Maven 2 assembly with dependencies: jar under scope “system” not included

I’m not surprised that system scope dependencies are not added (after all, dependencies with a system scope must be explicitly provided by definition). Actually, if you really don’t want to put that dependency in your local repository (for example because you want to distribute it as part of your project), this is what I would … Read more

Building a fat jar using maven

Note: If you are a spring-boot application, read the end of answer Add following plugin to your pom.xml The latest version can be found at … <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>CHOOSE LATEST VERSION HERE</version> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> <executions> <execution> <id>assemble-all</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> </plugins> </build> … After configuring … Read more