Skip to content

Instantly share code, notes, and snippets.

@Schm1tz1
Last active June 7, 2023 06:12
Show Gist options
  • Save Schm1tz1/fbc47a623c20b10455bf0b97c877e31f to your computer and use it in GitHub Desktop.
Save Schm1tz1/fbc47a623c20b10455bf0b97c877e31f to your computer and use it in GitHub Desktop.
Maven POM examples to create a (fat) JAR with all dependencies for an example project as well as a directory of dependencies (examples here: Sentry for log4J v1 and a custom connector in Clojars Artifactory)

Maven Examples for fat JARs

Maven POM examples to create a (fat) JAR that will pull all dependencies for example projects. It will also create a directory of dependencies.

Examples here: Sentry for log4J v1 and a custom connector in Clojars Artifactory

Usage Example

Run Maven:

mvn package --file pom-clojars.xml

You will find the fat JAR in target/connect-modules-1.0.0-jar-with-dependencies.jar and a directory with dependencies in target/dependencies.

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.schm1tz1</groupId>
<artifactId>connect-modules</artifactId>
<name>Connect Modules</name>
<version>1.0.0</version>
<repositories>
<repository>
<id>mavenCentral</id>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
<repository>
<id>Clojars</id>
<url>https://clojars.org/repo/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>io.mdrogalis</groupId>
<artifactId>voluble</artifactId>
<version>0.3.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.4.2</version>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>./target/dependencies</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.github.schm1tz1</groupId>
<artifactId>sentry-integration</artifactId>
<name>Sentry Integration</name>
<version>${sentry.version}</version>
<properties>
<sentry.version>1.7.30</sentry.version>
</properties>
<repositories>
<repository>
<id>mavenCentral</id>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>io.sentry</groupId>
<artifactId>sentry-log4j</artifactId>
<version>${sentry.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.4.2</version>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>./target/dependencies</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment