I have a multi-module project which I assemble with the assembly plugin to a fat jar. Thank works fine so far, but now I want to build another jar that only consists of special packages of the dependencies of the uber-pom.
An example:
I have 3 deps on sub-projects and I want to have a jar with
com.mycompany.api.*,
com.mycompany.settings.*
com.mycompany.public.*
but not
com.mycompany.internal.*
These packages are distributed through the 3 deps.
Any chance to realize something like that with the assembly plugin?
Thanks,
Jan
The Shade plugin should probably be able to do something like that.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<includes>
<include>com/mycompany/api/*</include>
<include>com/mycompany/settings/*</include>
<include>com/mycompany/public/*</include>
</includes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Related
The classes added to exclude in maven shade plugin don't get excluded.
My pom.xml has one dependency which has shaded classes conflicting with other dependencies.
So I added the path to those classes in maven shade plugin to exclude them.
I have this for maven shade plugin.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring.boot.version}</version>
</dependency>
</dependencies>
<version>3.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<excludes>
<exclude>io.confluent.shaded.kafka.serializers.subject.*</exclude>
<exclude>io/confluent/shaded/kafka/serializers/subject/*</exclude>
</excludes>
</filter>
</filters>
<mainClass>com.expediagroup.das.businessevent.CommerceBusinessBookingEventMetricCalculatorApp</mainClass>
<layout>JAR</layout>
</configuration>
</execution>
</executions>
</plugin>
After compiling it still shows those classes not being removed.
Any help is appreciated.
I created a general shade plugin instance below
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<filters>
<filter>
<artifact>*:*<artifact/>
<excludes>
<exclude>META-INF/*.gif</exclude>
<excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
However when executing mvn clean package I found the original- jar is the same size of the shade jar and contains all the dependency library, what could be the cause of such incident
original-myapp-0.0.1-SNAPSHOT.jar 168Mb
myapp-0.0.1-SNAPSHOT.jar 168Mb
I'm using Maven 3.6.2 with a multi-module Java project. The example module depends on the core module, so I have a dependency in the example module's POM like this:
<dependency>
<groupId>com.company</groupId>
<artifactId>core</artifactId>
<version>${project.version}</version>
</dependency>
The issue is that not all of the classes from the core module are being packaged into the example jar when I run mvn clean install. Only the classes that are used in the example project are being packaged. I need all classes packaged for a later process.
I'm using the maven-shade-plugin with this configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<minimizeJar>true</minimizeJar>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
<exclude>module-info.class</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>${project.name}</finalName>
</configuration>
</execution>
</executions>
</plugin>
How can I include all classes from the core module in the example jar without having to use them in the example jar?
The issue was the minimizeJar parameter. According to https://maven.apache.org/plugins/maven-shade-plugin/shade-mojo.html#minimizeJar:
When true, dependencies will be stripped down on the class level to
only the transitive hull required for the artifact.
I removed that parameter and it worked as expected.
I am creating a shaded jar with Maven shade plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<source>1.7</source>
<target>1.7</target>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
The shade plugin extracts the classes from all jars and pack them in a single jar but I get following warning for 1 jar:
[WARNING] The POM for org.knowhowlab.osgi:sigar:jar:1.6.5_01 is
invalid, transitive dependencies (if any) will not be available
and the sigar jar gets added as a jar,unlike others, which I was not expecting.
The sigar jar is my pom is added like this:
<dependency>
<groupId>org.knowhowlab.osgi</groupId>
<artifactId>sigar</artifactId>
<version>1.6.5_01</version>
</dependency>
One difference I see in this sigar jar is that it contains files such as .so, .dll.
How can I make this jar get added like others in shaded jar?
I'm using the Maven Android plugin to build my Android library using the apklib packaging. This produces an apklib archive of the library, so I'm also using the Maven jar plugin to produce a jar artifact that can be used in an app.
My problem is that BuildConfig.class and R.class are being included in the jar, which I don't want (really I would like to exclude anything in gen altogether). I've been trying to create exclude rules for them but haven't had any success. Here's the jar plugin configuration I've been using in my pom:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<excludes>
<exclude>**/BuildConfig.java</exclude>
<exclude>**/R.java</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
Any help is appreciated.
The trick here is to apply your configuration to the default-jar phase of the build lifecycle and exclude .class files, rather than .java files. You do this by adding <id>default-jar</id> to your execution as follows:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>default-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<excludes>
<exclude>**/BuildConfig.class</exclude>
<exclude>**/R.class</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
You'll probably also want to exclude the classes R$attr.class, R$drawable.class, R$layout.class, and R$string.class.