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

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

Related

Exclude specific files from all dependencies in pom

I want to exclude pdf files from all the dependencies. When I use filter property and specify the folder name for a pariticular dependency as below it works.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>com.test:myexample</artifact>
<excludes>
<exclude>TESTCASES/VFX/**/**/**/*.pdf</exclude>
<exclude>Test/**/*.pdf</exclude>
</excludes>
</filter>
</filters>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.test.CLI</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
However it does'nt work, when I used the configuration below. Reference link: https://maven.apache.org/plugins/maven-jar-plugin/examples/include-exclude.html
Do I need to follow any specific fileset pattern?
<configuration>
<excludes>
<exclude>**/*.pdf</exclude>
</excludes>
</configuration>
After adding the filter property as below it works.
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>**/*.pdf</exclude>
</excludes>
</filter>
</filters>

Running maven-shade-plugin only for package phase

Within my pom.xml I define following plugins - maven-shade, maven-compiler and maven-failsafe:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>shade-main</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<outputFile>target/assembly/${project.artifactId}.jar</outputFile>
<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.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>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>java-compile</id>
<phase>compile</phase>
<goals> <goal>compile</goal> </goals>
</execution>
<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<goals> <goal>testCompile</goal> </goals>
</execution>
</executions>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.20.1</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
When I run mvn package it nicely compiles the project and builds a jar with shade-plugin. However when I run mvn verify the shade-plugin should not be run, but it does and it takes unnecessary time before the tests are executed.
How can I prevent the shade plugin to run on mvn verify?
EDIT:
After some comments I want to clarify I still need to do the package phase, I just want to skip the execution of shade plugin.

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

when my use maven-shade-plugin package a execute jar, then Failed, and print error message:Cannot find 'resource' in class org.apache.maven.plugins.shade.resource.ManifestResourceTransformer
follow is my config:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.0.0</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>cn.rongcapital.pa.ingester.IngestJobBootstrap</Main-Class>
<!--<X-Compile-Source-JDK>1.8</X-Compile-Source-JDK>-->
<!--<X-Compile-Target-JDK>1.8</X-Compile-Target-JDK>-->
<!--<Class-Path>target</Class-Path>-->
</manifestEntries>
</transformer>
</transformers>
<relocations>
<relocation>
<pattern>io.netty</pattern>
<shadedPattern>rongcapital.io.netty</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
who can tell me why, and how to resolve it . thanks.

Submitting spring boot application jar to spark-submit

I am pretty new to spark, and i am trying to try out spark submit. I created an application in spring boot , used mvn package to create a jar . But when i am trying to submit the jar to spark-submit , it is not able to find the Main class . But the main class is present in the jar.
spark-submit --class com.dip.sparkapp.SparkappApplication --master local target/sparkapp-0.0.1-SNAPSHOT.jar
We ran into the same problem, actually, on the same day you posted this. Our solutions was to use the shade plugin for maven to edit our build a bit. We found that when packaging with the spring-boot-maven plugin it nested our classes in BOOT-INF/classes which spark didn't like. I'll paste the relevant section so you can try it out on your own application -- good luck!
<build>
<plugins>
<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>
<configuration>
<keepDependenciesWithProvidedScope>false</keepDependenciesWithProvidedScope>
<createDependencyReducedPom>false</createDependencyReducedPom>
<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.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer
implementation="org.springframework.boot.maven.PropertiesMergingResourceTransformer">
<resource>META-INF/spring.factories</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>${start-class}</mainClass>
</transformer>
</transformers>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I have found that simply skipping the class name from spark-submit works, i.e. --class com.dip.sparkapp.SparkappApplication
If your are using gradle this will work for shadow plugin:
import com.github.jengelman.gradle.plugins.shadow.transformers.*
...
plugins {
id 'com.github.johnrengelman.shadow' version '2.0.4'
}
...
shadowJar {
zip64 true
mergeServiceFiles()
append 'META-INF/spring.handlers'
append 'META-INF/spring.schemas'
append 'META-INF/spring.tooling'
transform(PropertiesFileTransformer) {
paths = ['META-INF/spring.factories' ]
mergeStrategy = "append"
}
}
Taken from here: https://github.com/spring-projects/spring-boot/issues/1828#issuecomment-607352468
This works for me
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>packagename.classname</Main-Class>
</manifestEntries>
</transformer>

How to build a jar from a module of maven with dependencies from other module?

I have some modules in maven, and I want to build a jar of a module which has a dependency of just other module.
How can I include in the jar both modules?
Edit:
I have the followings modules:
myproject-core/
myproject-api/
myproject-dependencie/
myproject-api-web/
And I want to build a jar in myproject-api with myproject-dependencie. I have more dependencies in myproject-api and I only need to have in this jar myproject-api and myproject-dependencie.
Thanks!
I guess the maven-shade-plugin will be your friend:
https://maven.apache.org/plugins/maven-shade-plugin/
In you plugins section Something like:
...
<properties>
<shade-main-class>{your-main-class}</shade-main-class>
</properties>
...
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<filters>
<filter>
<artifact>*:*</artifact>
<includes>
<include>com/yourcompany/**</include>
</includes>
<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>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>${shade-main-class}</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
...

Resources