Maven shade output not found - maven

I'm using the Maven Shade plugin, but I can't find its output.
The log says it clearly : the Maven-shade-plugin has worked.
But in the end, the output of the plugin is not where it is supposed to be.
Why ?
Maven log:
--- maven-shade-plugin:2.0:shade (default) # zploger ---
Including log4j:log4j:jar:1.2.17 in the shaded jar.
Including zparkingb:utils:jar:1.5.0 in the shaded jar.
Including zparkingb:swing:jar:1.5.6 in the shaded jar.
(...)
We have a duplicate org/xmlpull/v1/XmlPullParser.class in C:\Users\laurent\.m2\repository\xpp3\xpp3_min\1.1.4c\xpp3_min-1.1.4c.jar
We have a duplicate org/xmlpull/v1/XmlPullParserException.class in C:\Users\laurent\.m2\repository\xpp3\xpp3_min\1.1.4c\xpp3_min-1.1.4c.jar
Replacing D:\work\Zploger\builds\zplogerAudio-exe.jar with D:\work\Zploger\builds\zploger-3.2.0.002-exe.jar
Attaching shaded artifact.
And the pom/xml.
<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>
<keepDependenciesWithProvidedScope>true</keepDependenciesWithProvidedScope>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>exe</shadedClassifierName>
<finalName>${project.exe_finalname}</finalName>
<outputDirectory>../builds</outputDirectory>
<artifactSet>
<excludes>
<exclude>demo:*</exclude>
</excludes>
</artifactSet>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.zparkingb.zploger.GUI.Zploger</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>

Related

How to prevent a shaded jar to be installed to the local repository

At the end of my "package" step I end up with 2 jars : the one made by the "maven-jar-plugin" and the uber/fat/shaded one made by "maven-shade-plugin".
myapp.jar and myapp-uber.jar
At the "install" phase both jar are copied to the local repository. And I see little (=no) reason to have the uber jar copied to my local repository. Further more, it takes unless place on my HDD. And, anyway it will copied to right location at the "deploy" phase.
Here are those instructions :
<!-- Regular jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>package</phase>
</execution>
</executions>
<configuration>
<archive>
<manifestEntries>
<SplashScreen-Image>icons/splash.png</SplashScreen-Image>
<url>${project.url}</url>
</manifestEntries>
</archive>
</configuration>
</plugin>
<!-- Uber jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<keepDependenciesWithProvidedScope>true</keepDependenciesWithProvidedScope>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>exe</shadedClassifierName>
<finalName>${project.exe_finalname}</finalName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>myapp.MainClass</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<!-- Deploy -->
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>deploy</phase>
<configuration>
<target name="Pushing to builds repository"><!-- ... --></target>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
So how can I prevent the uber jar from being copied to the local repository ?
Thanks.

Cannot find 'manifestEntries' in class org.apache.maven.plugins.shade.resource.ServicesResourceTransformer

I am trying to create a FAT jar and combine entries in META-INF/services/io.vertx.config.spi.ConfigProcessor from vertx-config and vert-config-yaml JAR files. I do not see a need for mainfest entry options for ServicesResourceTransformer, but I am experiencing the error:
Unable to parse configuration of mojo org.apache.maven.plugins:maven-shade-plugin:3.2.1:shade for parameter manifestEntries: Cannot find 'manifestEntries' in class org.apache.maven.plugins.shade.resource.ServicesResourceTransformer -> [Help 1]
At first, I did not add the line
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
and the manifest entries did not get merged and one of the class from vert-config-yaml is missing. Now I add the line as below, and I see the error. I am using maven-shade-plugin plugin version 3.2.1. What am I doing wrong here?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven.shade.version}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/.SF</exclude>
<exclude>META-INF/.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>io.vertx.core.Launcher</Main-Class>
<Main-Verticle>${main.verticle}</Main-Verticle>
</manifestEntries>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/services/io.vertx.core.spi.VerticleFactory</resource>
</transformer>
</transformers>
<artifactSet>
</artifactSet>
<outputFile>${project.build.directory}/${project.artifactId}-${project.version}-fat.jar</outputFile>
</configuration>
</execution>
</executions>
</plugin>
Try adding <id> to your execution:
<execution>
<id>shade-my-jar</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
explanation (kinda symmetric question): https://stackoverflow.com/a/56154292

How to use maven-shade and felix to generate a shaded jar with a new manifest

I'm currently working on a project that is attempting to integrate use both shade and felix. The goal is to create a shaded jar that contains only the code we need, then use felix to create the manifest we need. The build part of my pom is as follows:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>false</shadedArtifactAttached>
<artifactSet>
<includes>
<include>${project.groupId}:*</include>
</includes>
</artifactSet>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>package</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
<configuration>
<manifestLocation>${project.build.directory}</manifestLocation>
<niceManifest>true</niceManifest>
</configuration>
</plugin>
</plugins>
</build>
Now the issue I'm running in to is something I've seen elsewhere, but all of those threads seem to die right at this point. So the shaded jar is correctly created, then Felix runs afterwards and puts the MANIFEST.MF file (which is correct as far as I can tell) in target/classes/META-INF/ but it doesn't put that same manifest in the shaded jar. The one inside the jar is the same manifest that existed before Felix ran.
It almost seems like I need Shade to run, then Felix, then re-run the jar creation. Am I missing something?
I'm trying to figure out how to, for lack of a better term, re-package the JAR with the new manifest.
Your main problem is that the manifest must be generated in the jar file, you can generate your Manifest file from the shade plugin (adapt with your needs):
<configuration>
<transformers>
<!-- This bit sets the main class for the executable jar as you otherwise -->
<!-- would with the assembly plugin -->
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Import-Package>org.apache.common</Import-Package>
<Export-Package>org.test</Export-Package>
<Main-Class>com.br.iacit.tutorialdoJar.ImageLab</Main-Class>
<Specification-Title>Java Advanced Imaging Image I/O Tools</Specification-Title>
<Specification-Version>1.1</Specification-Version>
<Specification-Vendor>Sun Microsystems, Inc.</Specification-Vendor>
<Implementation-Title>com.sun.media.imageio</Implementation-Title>
<Implementation-Version>1.1</Implementation-Version>
<Implementation-Vendor>Sun Microsystems, Inc.</Implementation-Vendor>
</manifestEntries>
</transformer>
<!-- This bit merges the various GeoTools META-INF/services files -->
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
</transformers>
</configuration>
Output Manifest:
Manifest-Version: 1.0
Toto: test
Export-Package: org.test
Archiver-Version: Plexus Archiver
Built-By: NG673AB
X-Compile-Target-JDK: 1.7
Import-Package: org.apache.common
X-Compile-Source-JDK: 1.7
Created-By: Apache Maven 3.3.3
Build-Jdk: 1.8.0_66
Main-Class: tt.tt.main
Edit: I managed to make it so that it compiles correctly, see below:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.DontIncludeResourceTransformer">
<resource>META-INF/MANIFEST.MF</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.IncludeResourceTransformer">
<resource>META-INF/MANIFEST.MF</resource>
<file>src/main/resources/MANIFEST.MF</file>
</transformer>
</transformers>
<shadedArtifactAttached>false</shadedArtifactAttached>
<artifactSet>
<includes>
<include>${project.groupId}:*</include>
</includes>
</artifactSet>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<executions>
<execution>
<id>bundle-manifest</id>
<phase>package</phase>
<goals>
<goal>manifest</goal>
</goals>
</execution>
</executions>
<configuration>
<manifestLocation>src/main/resources/</manifestLocation>
<niceManifest>true</niceManifest>
<instructions>
<Export-Package>test</Export-Package>
</instructions>
</configuration>
</plugin>
</plugins>
</build>

Why maven does not include dependencies in resulting jar

I am trying to build an uber jar with maven-shade-plugin 2.1. I expect it to include all the classes in my jar and dependency jars. But I see that it does not include classes from dependency jars. What could I be doing wrong? Following is my usage of maven-shade-plugin in pom.xml. Could it be because finalName is same as project.artifactid?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<minimizeJar>false</minimizeJar>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
</transformer>
</transformers>
<createDependencyReducedPom>false</createDependencyReducedPom>
<finalName>${project.artifactId}</finalName>
</configuration>
</execution>
</executions>
</plugin>
I tested your code and it works if it is inside <build> <plugins>, like this :
<build>
<plugins>
<plugin>
<!-- your code here -->
</plugin>
</plugins>
</build>
All dependencies are correctly included in the final jar. Also, make sure the dependencies you want to include in the shaded jar are inside the <dependencies> element, not the <dependencyManagement> element.

Maven Shade Plugin not including resources of dependency

I'm using the Maven Shade Plugin to include all dependencies during package phase.
That works fine for classes, but dependent resources aren't included.
Here's the layout of the dependent jar:
./config.properties <-- this is the missing resource
./META-INF
./META-INF/MANIFEST.MF
./META-INF/maven
./META-INF/maven/com.example
./META-INF/maven/com.example/bar
./META-INF/maven/com.example/bar/pom.properties
./META-INF/maven/com.example/bar/pom.xml
Here's the shade plugin configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>com.example.foo.Foo</Main-Class>
<!-- <X-Compile-Source-JDK>${maven.compile.source}</X-Compile-Source-JDK>.
<X-Compile-Target-JDK>${maven.compile.target}</X-Compile-Target-JDK> -->
</manifestEntries>
</transformer>
</transformers>
<filters>
<filter>
<!--
Exclude files that sign a jar
(one or multiple of the dependencies).
One may not repack a signed jar without
this, or you will get a
SecurityException at program start.
-->
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.RSA</exclude>
<exclude>META-INF/*.INF</exclude> <!-- This one may not be required -->
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
It's embarrasing, but there was a typo in the version of the dependency and that version didn't have the file.

Resources