Maven executable jar packaging vs Maven exec with Jackson not working - java

I need some help with trying to get an executable working. This is a tricky one and I've narrowed it down to the fact that something is different with the way that maven exec runs things and how either the maven shade plugin or the maven assembly plugin is packaging the files.
I'm building a REST service in Java with Netty and JAX-RS and use Jackson to translate from POJOs to JSON.
The server starts up correctly when executing either mvn exec:java or java -jar. But when making a request against the java -jar file, I get the following error:
Could not find MessageBodyWriter for response object of type: [Ljava.lang.Object; of media type: application/json
It seems like something isn't being packaged correctly, but I'm not sure what. Transitive dependencies are missing, maybe?
Here's my POM:
<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.test.myserver</groupId>
<artifactId>myserver</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>myserver</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
<repository>
<id>oss-sonatype</id>
<name>oss-sonatype</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<build>
<plugins>
<!-- For executing in maven itself (mvn exec:java) -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.test.myserver.App</mainClass>
</configuration>
</plugin>
<plugin>
<!-- for packaging (mvn package) -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.test.myserver.App</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<!-- The configuration of maven-assembly-plugin -->
<plugin>
<!-- for packaging (mvn compile assembly:single) -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<!-- The configuration of the plugin -->
<configuration>
<archive>
<manifest>
<mainClass>com.test.myserver.App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>LATEST</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.googlecode.plist</groupId>
<artifactId>dd-plist</artifactId>
<version>LATEST</version>
</dependency>
<!-- MongoDB -->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>2.12.0</version>
</dependency>
<dependency>
<groupId>org.mongojack</groupId>
<artifactId>mongojack</artifactId>
<version>2.1.0-SNAPSHOT</version>
</dependency>
<!-- REST Server -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-netty</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson2-provider</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>LATEST</version>
</dependency>
</dependencies>
Maven shade is executed with mvn package.
Maven assembly is executed with mvn compile assembly:single.
Thanks in advance!
EDIT
I checked mvn dependency:tree against the output for mvn shade and for all intents, they look the same.
Output from dependency tree
$ mvn dependency:tree
[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building myserver 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # myserver ---
[INFO] com.test.myserver:myserver:jar:1.0-SNAPSHOT
[INFO] +- junit:junit:jar:4.11:test
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- com.googlecode.plist:dd-plist:jar:1.8:compile
[INFO] +- org.mongodb:mongo-java-driver:jar:2.12.0:compile
[INFO] +- org.mongojack:mongojack:jar:2.1.0-SNAPSHOT:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-databind:jar:2.2.3:compile
[INFO] | +- de.undercouch:bson4jackson:jar:2.2.0:compile
[INFO] | +- javax.persistence:persistence-api:jar:1.0.2:compile
[INFO] | \- commons-io:commons-io:jar:2.4:compile
[INFO] +- org.jboss.resteasy:resteasy-jaxrs:jar:3.0.8.Final:compile
[INFO] | +- org.jboss.resteasy:jaxrs-api:jar:3.0.8.Final:compile
[INFO] | +- org.jboss.spec.javax.annotation:jboss-annotations-api_1.1_spec:jar:1.0.1.Final:compile
[INFO] | +- javax.activation:activation:jar:1.1:compile
[INFO] | +- org.apache.httpcomponents:httpclient:jar:4.2.1:compile
[INFO] | | +- org.apache.httpcomponents:httpcore:jar:4.2.1:compile
[INFO] | | +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] | | \- commons-codec:commons-codec:jar:1.6:compile
[INFO] | \- net.jcip:jcip-annotations:jar:1.0:compile
[INFO] +- org.jboss.resteasy:resteasy-netty:jar:3.0.8.Final:compile
[INFO] | \- io.netty:netty:jar:3.6.4.Final:compile
[INFO] +- org.jboss.resteasy:resteasy-jackson2-provider:jar:3.0.8.Final:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-core:jar:2.3.2:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.3.2:compile
[INFO] | \- com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:jar:2.3.2:compile
[INFO] | +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:jar:2.3.2:compile
[INFO] | \- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.3.2:compile
[INFO] +- org.slf4j:slf4j-api:jar:1.7.7:compile
[INFO] +- org.slf4j:slf4j-simple:jar:1.7.7:compile
[INFO] \- org.reflections:reflections:jar:0.9.9-RC1:compile
[INFO] +- com.google.guava:guava:jar:11.0.2:compile
[INFO] | \- com.google.code.findbugs:jsr305:jar:1.3.9:compile
[INFO] +- org.javassist:javassist:jar:3.16.1-GA:compile
[INFO] \- dom4j:dom4j:jar:1.6.1:compile
[INFO] \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.999 s
[INFO] Finished at: 2014-04-22T17:09:47-08:00
[INFO] Final Memory: 13M/310M
[INFO] ------------------------------------------------------------------------
Output from shade
$ mvn package
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # myserver ---
[INFO] Building jar: /myserver/target/myserver-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- maven-shade-plugin:2.2:shade (default) # myserver ---
[INFO] Including com.googlecode.plist:dd-plist:jar:1.8 in the shaded jar.
[INFO] Including org.mongodb:mongo-java-driver:jar:2.12.0 in the shaded jar.
[INFO] Including org.mongojack:mongojack:jar:2.1.0-SNAPSHOT in the shaded jar.
[INFO] Including com.fasterxml.jackson.core:jackson-databind:jar:2.2.3 in the shaded jar.
[INFO] Including de.undercouch:bson4jackson:jar:2.2.0 in the shaded jar.
[INFO] Including javax.persistence:persistence-api:jar:1.0.2 in the shaded jar.
[INFO] Including commons-io:commons-io:jar:2.4 in the shaded jar.
[INFO] Including org.jboss.resteasy:resteasy-jaxrs:jar:3.0.8.Final in the shaded jar.
[INFO] Including org.jboss.resteasy:jaxrs-api:jar:3.0.8.Final in the shaded jar.
[INFO] Including org.jboss.spec.javax.annotation:jboss-annotations-api_1.1_spec:jar:1.0.1.Final in the shaded jar.
[INFO] Including javax.activation:activation:jar:1.1 in the shaded jar.
[INFO] Including org.apache.httpcomponents:httpclient:jar:4.2.1 in the shaded jar.
[INFO] Including org.apache.httpcomponents:httpcore:jar:4.2.1 in the shaded jar.
[INFO] Including commons-logging:commons-logging:jar:1.1.1 in the shaded jar.
[INFO] Including commons-codec:commons-codec:jar:1.6 in the shaded jar.
[INFO] Including net.jcip:jcip-annotations:jar:1.0 in the shaded jar.
[INFO] Including org.jboss.resteasy:resteasy-netty:jar:3.0.8.Final in the shaded jar.
[INFO] Including io.netty:netty:jar:3.6.4.Final in the shaded jar.
[INFO] Including org.jboss.resteasy:resteasy-jackson2-provider:jar:3.0.8.Final in the shaded jar.
[INFO] Including com.fasterxml.jackson.core:jackson-core:jar:2.3.2 in the shaded jar.
[INFO] Including com.fasterxml.jackson.core:jackson-annotations:jar:2.3.2 in the shaded jar.
[INFO] Including com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:jar:2.3.2 in the shaded jar.
[INFO] Including com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:jar:2.3.2 in the shaded jar.
[INFO] Including com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.3.2 in the shaded jar.
[INFO] Including org.slf4j:slf4j-api:jar:1.7.7 in the shaded jar.
[INFO] Including org.slf4j:slf4j-simple:jar:1.7.7 in the shaded jar.
[INFO] Including org.reflections:reflections:jar:0.9.9-RC1 in the shaded jar.
[INFO] Including com.google.guava:guava:jar:11.0.2 in the shaded jar.
[INFO] Including com.google.code.findbugs:jsr305:jar:1.3.9 in the shaded jar.
[INFO] Including org.javassist:javassist:jar:3.16.1-GA in the shaded jar.
[INFO] Including dom4j:dom4j:jar:1.6.1 in the shaded jar.
[INFO] Including xml-apis:xml-apis:jar:1.0.b2 in the shaded jar.
[INFO] Replacing original artifact with shaded artifact.
[INFO] Replacing /myserver/target/myserver-1.0-SNAPSHOT.jar with /myserver/target/myserver-1.0-SNAPSHOT-shaded.jar
[INFO] Dependency-reduced POM written at: /myserver/dependency-reduced-pom.xml
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.658 s
[INFO] Finished at: 2014-04-22T17:05:50-08:00
[INFO] Final Memory: 39M/310M
[INFO] ------------------------------------------------------------------------

The shade plugin configuration is missing the service transformer which merges the META-INF/services files used by the service discovery mechanism.
Here is an example:
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.example.helloworld.HelloWorldApplication</mainClass>
</transformer>
</transformers>

It's interesting because I asked myself the question yesterday, "why do I need an über jar?" And, as it turns out, I don't and probably shouldn't be using an über jar. Alexey correctly answered the question to solve the immediate problem, but I also wanted to post an alternate solution that I figured out for doing things a little bit differently.
Rather than using the shade plugin to build an über jar, I decided to create a standard jar and export all the dependencies needed to run my application. This means that I now use the Maven Jar Plugin to create my jar and the Maven Dependency Plugin to export the libraries. Here's what the build section of the pom.xml looks like:
<build>
<plugins>
<!-- For copying the libraries to the output directory -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</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>
</configuration>
</execution>
</executions>
</plugin>
<!-- Create the executable jar -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.test.myserver.App</mainClass>
<useUniqueVersions>false</useUniqueVersions>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
Since my output directory is target/, my jar is generated as target/myserver-1.0-SNAPSHOT.jar and all the dependencies are in target/lib/. The maven-jar-plugin also build the classpath and points them correctly to the lib/ directory, so I'm pretty much set. This also makes it easier in the future to replace individual libraries as they are updated, rather than uploading an entirely new jar.
Building the jar and copying the dependencies is simply mvn install from the command line.

Related

How do I debug why unit tests sometimes fail due to Kotlin libs not being available?

We have a really annoying issue with some flaky tests: they work 9/10 times, but every now and then they fail with a ClassNotFoundException when invoking some Kotlin code:
java.lang.ClassNotFoundException: kotlin.collections.Map
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:375)
at my-project.server.config.KConfigLoader.load(KConfigLoader.kt:77)
at my-project.server.config.KConfigLoader.load(KConfigLoader.kt:53)
at my-project.server.config.KConfigLoaderTest.loader_shold_register_unknown_properties(KConfigLoaderTest.kt:65)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:567)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.apache.maven.surefire.junitcore.pc.Scheduler$1.run(Scheduler.java:405)
at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1130)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:630)
at java.base/java.lang.Thread.run(Thread.java:831)
This happens on our CI server and sometimes locally. What I do not get is the flakyness aspect. Either the Kotlin standard library is on the classpath or not, right? I don't see how it can randomly fail at times.
Debugging info
Kotlin related stuff in parent pom
ag -C2 kotlin ../pom.xml
35: <kotlin.version>1.5.20</kotlin.version>
36: <kotlin.compiler.incremental>false</kotlin.compiler.incremental>
37-
38- <maven.build.timestamp.format>yyyy-MM-dd'T'HH:mm:ss'Z'</maven.build.timestamp.format>
--
47- </plugin>
48- <plugin>
49: <groupId>org.jetbrains.kotlin</groupId>
50: <artifactId>kotlin-maven-plugin</artifactId>
51: <version>${kotlin.version}</version>
52- <executions>
53- <execution>
--
59- <configuration>
60- <sourceDirs>
61: <sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
62- <sourceDir>${project.basedir}/src/main/java</sourceDir>
63- </sourceDirs>
--
71- <configuration>
72- <sourceDirs>
73: <sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
74- <sourceDir>${project.basedir}/src/test/java</sourceDir>
75- </sourceDirs>
--
229- <dependency>
230- <groupId>com.fasterxml.jackson.module</groupId>
231: <artifactId>jackson-module-kotlin</artifactId>
232- <version>${jackson.version}</version>
233- </dependency>
--
273- </dependency>
274- <dependency>
275: <groupId>org.jetbrains.kotlin</groupId>
276: <artifactId>kotlin-stdlib</artifactId>
277: <version>${kotlin.version}</version>
278- </dependency>
279- <dependency>
280: <groupId>org.jetbrains.kotlin</groupId>
281: <artifactId>kotlin-test-junit</artifactId>
282: <version>${kotlin.version}</version>
283- </dependency>
284- <dependency>
285: <groupId>org.jetbrains.kotlin</groupId>
286: <artifactId>kotlin-reflect</artifactId>
287: <version>${kotlin.version}</version>
288- </dependency>
289- <dependency>
Plugin config
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/main/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<goals>
<goal>test-compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/test/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>${jdk.version}</release>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
<!--https://issues.apache.org/jira/browse/MCOMPILER-209-->
<useIncrementalCompilation>false</useIncrementalCompilation>
<compilerArgs>
<arg>-Xlint:all</arg>
<!--Silence class version ignore/deprecation warnings -->
<arg>-Xlint:-classfile</arg>
<!-- http://jdbi.org/#_compiling_with_parameter_names -->
<arg>-parameters</arg>
</compilerArgs>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
<executions>
<!-- Replacing default-compile as it is treated specially by maven -->
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<!-- Replacing default-testCompile as it is treated specially by maven -->
<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>
</plugin>
Kotlin related in project pom
Pretty much everything happens in the parent pom wrt setup.
369- <dependency>
370: <groupId>org.jetbrains.kotlin</groupId>
371: <artifactId>kotlin-stdlib</artifactId>
372- </dependency>
373- <dependency>
374: <groupId>org.jetbrains.kotlin</groupId>
375: <artifactId>kotlin-reflect</artifactId>
376- </dependency>
Output from dependency:tree
This is what I get when running mvn dependency:tree -Dincludes=*jetbrains* in the folder containing the root pom:
22:39:55,407 [INFO] Scanning for projects...
22:39:55,542 [INFO] ------------------------------------------------------------------------
22:39:55,542 [INFO] Reactor Build Order:
22:39:55,542 [INFO]
22:39:55,547 [INFO] my-project [pom]
22:39:55,547 [INFO] my-project-commons [jar]
22:39:55,547 [INFO] my-project-my-app-backend [jar]
22:39:55,547 [INFO] my-project-people-backend [jar]
22:39:55,957 [INFO]
22:39:55,958 [INFO] ----------------------< no.ACME.my-project:my-project >-----------------------
22:39:55,959 [INFO] Building my-project 0.0.1-SNAPSHOT [1/4]
22:39:55,959 [INFO] --------------------------------[ pom ]---------------------------------
22:39:55,971 [INFO]
22:39:55,971 [INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # my-project ---
22:39:57,889 [INFO]
22:39:57,891 [INFO] ------------------< no.ACME.my-project:my-project-commons >-------------------
22:39:57,892 [INFO] Building my-project-commons 0.0.1-SNAPSHOT [2/4]
22:39:57,892 [INFO] --------------------------------[ jar ]---------------------------------
22:39:58,354 [INFO]
22:39:58,354 [INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # my-project-commons ---
22:39:58,385 [INFO] no.ACME.my-project:my-project-commons:jar:0.0.1-SNAPSHOT
22:39:58,385 [INFO] +- com.fasterxml.jackson.module:jackson-module-kotlin:jar:2.12.2:compile
22:39:58,385 [INFO] | \- org.jetbrains.kotlin:kotlin-reflect:jar:1.5.20:compile
22:39:58,385 [INFO] | \- org.jetbrains.kotlin:kotlin-stdlib:jar:1.5.20:compile
22:39:58,385 [INFO] | +- org.jetbrains:annotations:jar:21.0.1:compile
22:39:58,385 [INFO] | \- org.jetbrains.kotlin:kotlin-stdlib-common:jar:1.5.20:compile
22:39:58,385 [INFO] \- org.jetbrains.kotlin:kotlin-test-junit:jar:1.5.20:test
22:39:58,385 [INFO] \- org.jetbrains.kotlin:kotlin-test:jar:1.5.20:test
22:39:58,386 [INFO]
22:39:58,386 [INFO] ---------------< no.ACME.my-project:my-project-my-app-backend >---------------
22:39:58,386 [INFO] Building my-project-my-app-backend 0.0.1-SNAPSHOT [3/4]
22:39:58,386 [INFO] --------------------------------[ jar ]---------------------------------
22:39:59,524 [INFO]
22:39:59,525 [INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # my-project-my-app-backend ---
22:39:59,568 [INFO] no.ACME.my-project:my-project-my-app-backend:jar:0.0.1-SNAPSHOT
22:39:59,568 [INFO] +- org.jetbrains.kotlin:kotlin-stdlib:jar:1.5.20:compile
22:39:59,568 [INFO] | +- org.jetbrains:annotations:jar:21.0.1:compile
22:39:59,569 [INFO] | \- org.jetbrains.kotlin:kotlin-stdlib-common:jar:1.5.20:compile
22:39:59,569 [INFO] \- org.jetbrains.kotlin:kotlin-reflect:jar:1.5.20:compile
22:39:59,569 [INFO]
22:39:59,569 [INFO] ---------------< no.ACME.my-project:my-project-people-backend >---------------
22:39:59,569 [INFO] Building my-project-people-backend 0.0.1-SNAPSHOT [4/4]
22:39:59,569 [INFO] --------------------------------[ jar ]---------------------------------
22:39:59,656 [INFO]
22:39:59,657 [INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # my-project-people-backend ---
22:39:59,670 [INFO] no.ACME.my-project:my-project-people-backend:jar:0.0.1-SNAPSHOT
22:39:59,671 [INFO] +- no.ACME.my-project:my-project-commons:jar:0.0.1-SNAPSHOT:compile
22:39:59,671 [INFO] | \- com.fasterxml.jackson.module:jackson-module-kotlin:jar:2.12.2:compile
22:39:59,671 [INFO] | \- org.jetbrains.kotlin:kotlin-reflect:jar:1.5.20:compile
22:39:59,671 [INFO] \- xyz.capybara:clamav-client:jar:2.0.2:compile
22:39:59,671 [INFO] \- org.jetbrains.kotlin:kotlin-stdlib:jar:1.5.20:compile
22:39:59,671 [INFO] +- org.jetbrains:annotations:jar:21.0.1:compile
22:39:59,671 [INFO] \- org.jetbrains.kotlin:kotlin-stdlib-common:jar:1.5.20:compile
22:39:59,671 [INFO] ------------------------------------------------------------------------
22:39:59,671 [INFO] Reactor Summary for my-project 0.0.1-SNAPSHOT:
22:39:59,671 [INFO]
22:39:59,674 [INFO] my-project ............................................. SUCCESS [ 1.932 s]
22:39:59,677 [INFO] my-project-commons ..................................... SUCCESS [ 0.497 s]
22:39:59,677 [INFO] my-project-my-app-backend .............................. SUCCESS [ 1.183 s]
22:39:59,678 [INFO] my-project-people-backend .............................. SUCCESS [ 0.102 s]
22:39:59,678 [INFO] ------------------------------------------------------------------------
22:39:59,678 [INFO] BUILD SUCCESS
22:39:59,678 [INFO] ------------------------------------------------------------------------
22:39:59,679 [INFO] Total time: 4.295 s
22:39:59,681 [INFO] Finished at: 2021-09-14T22:39:59+02:00
22:39:59,686 [INFO] ------------------------------------------------------------------------
Maven version
When this happens, it is usually on TeamCity when running Maven, but we sometimes see it in IntelliJ (not via Maven) as well.
Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)

How do we set/modify the name for a specific dependency defined in pom.xml for a Java project?

Right now, the name is set to 'name + version'. I need to exclude the version from the final name.
Eg - For
<dependency>
<groupId>group-a</groupId>
<artifactId>artifact-b</artifactId>
<version>1.0</version>
</dependency>
I am seeing artifact-b-1.0.jar getting generated in my build, but I want it named artifact-b.jar so that I need need to alter all the scripts using the jar every time the version changes.
During build, your jar is generated to target. You can change the name for target using the finalName parameter. If you use install, the artifact is installed to the local repository (you cannot influence the name in the local repository). If you do deploy ,the artifact is deployed to a remote repository (there you cannot also not influence the name).
You can do like this:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>package.class.main.Method</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>${project.artifactId}</finalName>
<appendAssemblyId>false</appendAssemblyId>
</configuration>
</plugin>
</plugins>
</build>
You can use the install-file goal of the Maven Install Plugin:
<groupId>group-a</groupId>
<artifactId>artifact-b</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>3.0.0-M1</version>
<executions>
<execution>
<id>install-file-${project.artifactId}</id>
<goals>
<goal>install-file</goal>
</goals>
<phase>install</phase>
<configuration>
<file>${project.build.directory}/${project.build.finalName}.jar</file>
<artifactId>artifact</artifactId>
<version>b</version>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
mvn install output:
[INFO] ...
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # so58011949 ---
[INFO] Building jar: ...\target\so58011949-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:3.0.0-M1:install (default-install) # artifact-b ---
[INFO] Installing ...\target\artifact-b-0.0.1-SNAPSHOT.jar
to ...\.m2\repository\group-a\artifact-b\0.0.1-SNAPSHOT\artifact-b-0.0.1-SNAPSHOT.jar
[INFO] Installing ...\pom.xml
to ...\.m2\repository\group-a\artifact-b\0.0.1-SNAPSHOT\artifact-b-0.0.1-SNAPSHOT.pom
[INFO]
[INFO] --- maven-install-plugin:3.0.0-M1:install-file (install-file-artifact-b) # artifact-b ---
[INFO] Installing ...\target\artifact-b-0.0.1-SNAPSHOT.jar
to ...\.m2\repository\group-a\artifact\b\artifact-b.jar
[INFO] Installing ...\AppData\Local\Temp\artifact-b-0.0.1-SNAPSHOT7551062015093608214.pom
to ...\.m2\repository\group-a\artifact\b\artifact-b.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] ...
Local repository:
|
+- group-a
| +- artifact
| +- b
| +- artifact-b.jar
| +- artifact-b.pom
| +- artifact-b
| +- 0.0.1-SNAPSHOT
| +- artifact-b-0.0.1-SNAPSHOT.jar
| +- artifact-b-0.0.1-SNAPSHOT.pom
|

Jar not attaching to new executable jar

I have a java/maven project that runs some database stuff perfectly (classpath is working great). I use a proprietary database jar in order to connect to the database. When I go to package up my software into a shaded jar the proprietary jar isn't referenced. When I check the log files I see this error:
Exception: java.lang.ClassNotFoundException: com.sybase.jdbc4.jdbc.SybDriver
I'm trying to put everything into a shaded jar using Maven. Is there something that I'm not doing? Why is the database jar not working in my new shaded jar?
Adding the shade plugin configuration:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>package.class</mainClass>
</transformer>
</transformers>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>launcher</shadedClassifierName>
</configuration>
</execution>
</executions>
</plugin>
I have followed the instructions about setting up a file repository since we don't have a corporate repository.
I created a folder at c:\my-repo and put the lone jconn4.jar file inside. I then added this to my pom.xml:
<repositories>
<repository>
<id>my-local-repo</id>
<url>file://${basedir}/my-repo</url>
</repository>
</repositories>
and
<dependency>
<groupId>company</groupId>
<artifactId>jconn4.jar</artifactId>
<version>16.0</version>
</dependency>
Finally, at a command prompt I ran the command:
$ mvn org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file -Dfile=C:\my-repo\jconn4.jar -DgroupId=company -DartifactId=jconn4.jar -Dversion=16.0 -Dpackaging=jar -DlocalRepositoryPath=C:\my-repo
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building My_Project 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.3.1:install-file (default-cli) # My_Project ---
[INFO] Installing C:\my-repo\jconn4.jar to C:\my-repo\company\jconn4.jar\16.0\jconn4.jar-16.0.jar
[INFO] Installing C:\Users\jsmith\AppData\Local\Temp\mvninstall7806841451724024532.pom to C:\my-repo\company\jconn4.jar\16.0\jconn4.jar-16.0.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.613 s
[INFO] Finished at: 2016-12-08T10:26:08-05:00
[INFO] Final Memory: 7M/245M
[INFO] ------------------------------------------------------------------------
That's all well and good but I keep getting this error in my pom.xml now "Missing artifact company:jconn4.jar:jar:16.0"
Have I implemented something incorrectly?

Cannot import webservice stubs in client

I am trying to learn about jax-ws and created a simple Bottom-Up HelloWorld webservice in order to train myself:
import org.jboss.annotation.ejb.LocalBinding;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
#WebService(serviceName = "HelloWorldWebServiceExperiment",
portName = "HelloWorldPort",
name = "HelloWorld")
#SOAPBinding(style = SOAPBinding.Style.DOCUMENT,
use = SOAPBinding.Use.LITERAL,
parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
#Stateless
#Remote
#LocalBinding(jndiBinding = "training.webservice.HelloWorldWebServiceRemote/local")
public class HelloWorldWebServiceBean {
private static final String HELLO_WORLD = "Hello World";
#WebMethod
public String helloWorld() {
return HELLO_WORLD;
}
}
When I deploy this webservice I can access the wsdl, so that seems to work fine.
Then I tried to generate a webservice client. And to do so I needed to create stubs, which I tried to create with the maven plugin jaxws-maven-plugin. Here is my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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>training.webservice</groupId>
<artifactId>HelloWorldWebServiceExperiment</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<wsdlPath>${project.build.directory}</wsdlPath>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<targetPath>WEB-INF</targetPath>
<directory>src/main/webapp/WEB-INF</directory>
<includes>
<include>web.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<id>genwsdl</id>
<phase>process-classes</phase>
<goals>
<goal>wsgen</goal>
</goals>
<configuration>
<genWsdl>true</genWsdl>
<sei>training.webservice.HelloWorldWebServiceBean</sei>
</configuration>
</execution>
<execution>
<id>consumeWsdlForStubs</id>
<phase>process-classes</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlDirectory>target/jaxws/wsgen/wsdl</wsdlDirectory>
<wsdlFiles>
<wsdlFile>HelloWorldWebServiceExperiment.wsdl</wsdlFile>
</wsdlFiles>
<keep>true</keep>
<destDir>target/classes</destDir>
<sourceDestDir>target/stubs</sourceDestDir>
<verbose>true</verbose>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>package-wsclient-jars</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>target/stubs</classesDirectory>
<classifier>wsclient</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<!-- JAX-WS Annotations -->
<dependency>
<groupId>javax.jws</groupId>
<artifactId>jsr181-api</artifactId>
<version>1.0-MR1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jboss</groupId>
<artifactId>jbossws-spi</artifactId>
<version>1.0.0.GA</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-ejb3x</artifactId>
<version>4.2.2</version>
<!--<scope>provided</scope>-->
</dependency>
<dependency>
<groupId>jboss</groupId>
<artifactId>jboss-annotations-ejb3</artifactId>
<version>4.2.2.GA</version>
<!--<scope>provided</scope>-->
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-jaxws</artifactId>
<version>4.2.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
The Build with maven will generate the follwoing output and a .jar file with generated .java files:
> mvn clean install
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - training.webservice:HelloWorldWebServiceExperiment:war:1.0-SNAPSHOT
[INFO] task-segment: [clean, install]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean {execution: default-clean}]
[INFO] Deleting directory ---/HelloWorldWebServiceExperiment/target
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] [compiler:compile {execution: default-compile}]
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 2 source files to ---/HelloWorldWebServiceExperiment/target/classes
[INFO] [compiler:compile {execution: default}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [jaxws:wsgen {execution: genwsdl}]
[INFO] [jaxws:wsimport {execution: consumeWsdlForStubs}]
[INFO] Processing: ---/HelloWorldWebServiceExperiment/target/jaxws/wsgen/wsdl/HelloWorldWebServiceExperiment.wsdl
[INFO] jaxws:wsimport args: [-s, ---/ /HelloWorldWebServiceExperiment/target/jaxws/wsimport/java, -d, ---/HelloWorldWebServiceExperiment/target/classes, -verbose, -Xnocompile, ---/HelloWorldWebServiceExperiment/target/jaxws/wsgen/wsdl/HelloWorldWebServiceExperiment.wsdl]
parsing WSDL...
generating code...
training/webservice/HelloWorld.java
training/webservice/HelloWorldResponse.java
training/webservice/HelloWorldWebServiceExperiment.java
training/webservice/HelloWorld_Type.java
training/webservice/ObjectFactory.java
training/webservice/package-info.java
[INFO] [resources:testResources {execution: default-testResources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory ---/HelloWorldWebServiceExperiment/src/test/resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [surefire:test {execution: default-test}]
[INFO] No tests to run.
[INFO] [war:war {execution: default-war}]
[INFO] Packaging webapp
[INFO] Assembling webapp[HelloWorldWebServiceExperiment] in [---/HelloWorldWebServiceExperiment/target/HelloWorldWebServiceExperiment-1.0-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp webResources[---/HelloWorldWebServiceExperiment/src/main/webapp/WEB-INF] to[---/HelloWorldWebServiceExperiment/target/HelloWorldWebServiceExperiment-1.0-SNAPSHOT]
[INFO] Copying webapp resources[---/HelloWorldWebServiceExperiment/src/main/webapp]
[INFO] Webapp assembled in[33 msecs]
[INFO] Building war: ---/HelloWorldWebServiceExperiment/target/HelloWorldWebServiceExperiment-1.0-SNAPSHOT.war
[INFO] [jar:jar {execution: package-wsclient-jars}]
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar: ---/HelloWorldWebServiceExperiment/target/HelloWorldWebServiceExperiment-1.0-SNAPSHOT-wsclient.jar
[INFO] [install:install {execution: default-install}]
[INFO] Installing ---/HelloWorldWebServiceExperiment/target/HelloWorldWebServiceExperiment-1.0-SNAPSHOT.war to ~/.m2/repository/training/webservice/HelloWorldWebServiceExperiment/1.0-SNAPSHOT/HelloWorldWebServiceExperiment-1.0-SNAPSHOT.war
[INFO] Installing ---/HelloWorldWebServiceExperiment/target/HelloWorldWebServiceExperiment-1.0-SNAPSHOT-wsclient.jar to ~/.m2/repository/training/webservice/HelloWorldWebServiceExperiment/1.0-SNAPSHOT/HelloWorldWebServiceExperiment-1.0-SNAPSHOT-wsclient.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Tue Aug 25 09:31:20 CEST 2015
[INFO] Final Memory: 32M/487M
[INFO] ------------------------------------------------------------------------
EDIT (for precision): When I try use the stub archive in another project to create a webclient, (i do this with intellij idea), idea automatically finds the file from my maven repository and suggests it to me, generating the following dependency:
<dependency>
<groupId>training.webservice</groupId>
<artifactId>HelloWorldWebServiceExperiment</artifactId>
<version>1.0-SNAPSHOT-wsclient</version>
</dependency>
however none of the genereated .java files can actually be imported and used in code! E.g. idea fails on usage or import
import training.webservice.HelloWorld;
private training.webservice.HelloWorld helloWorld;
with the error message "Cannot resolve symbol 'HelloWorld'"
What am I doing wrong? Is this connected to the fact that my stub only contains .java files, but no .class files? Obviously the plugin jaxws-maven-plugin runs wsimport with the -xnocompile flag, but I haven't been able to figure out how to configure maven not to do that, none of the options keep, destDir or sourceDestDir have had any effect on that! Or is this completely irrelevant, as the project importing the stubs should be able to compile them itself and the problem is somewhere else? Any help would be greatly appreciated!
I found a temporary work arround:
I generate a client stub .jar file manually. As my company still works with Java 1.5, I had to install metro in order to use wsimport (I chose version 1.6.2) and then I could call:
wsimport target/generated-sources/wsdl/HelloWorldWebServiceExperiment.wsdl -d target/generated-sources/wsdl/ -keep
afterwards I had .java and .class files which I could manually package into a .jar file, then I moved that .jar into the ressource folder of my webservice client project and manually added the dependency into my pom.xml:
<dependency>
<groupId>training.webservice</groupId>
<artifactId>HelloWorldWebServiceExperiment</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/client.jar</systemPath>
</dependency>
I would prefer an automatic build and deploy from maven, and I am now sure that the problem must lie within my maven setup, however I have still no clue how to do it any better. At least I can continue working on the webservice client for now, and revisit the issue at a later point again!

Excluding transitive dependency more than one level

I have this pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework</groupId>
<artifactId>gs-maven</artifactId>
<packaging>jar</packaging>
<version>0.1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>hello.HelloWorld</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.4.Final</version>
<exclusions>
<exclusion>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>ch.simas.qlrm</groupId>
<artifactId>qlrm</artifactId>
<version>1.5.1</version>
<exclusions>
<exclusion>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
The dependency:tree is
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building gs-maven 0.1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # gs-maven ---
[INFO] org.springframework:gs-maven:jar:0.1.0
[INFO] +- org.hibernate:hibernate-core:jar:4.1.4.Final:compile
[INFO] | +- antlr:antlr:jar:2.7.7:compile
[INFO] | +- org.jboss.logging:jboss-logging:jar:3.1.0.GA:compile
[INFO] | +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:jar:1.0.0.Final:compile
[INFO] | +- dom4j:dom4j:jar:1.6.1:compile
[INFO] | +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
[INFO] | +- org.javassist:javassist:jar:3.15.0-GA:compile
[INFO] | \- org.hibernate.common:hibernate-commons-annotations:jar:4.0.1.Final:compile
[INFO] \- ch.simas.qlrm:qlrm:jar:1.5.1:compile
[INFO] +- org.eclipse.persistence:eclipselink:jar:2.5.1:compile
[INFO] | +- org.eclipse.persistence:javax.persistence:jar:2.1.0:compile
[INFO] | \- org.eclipse.persistence:commonj.sdo:jar:2.1.1:compile
[INFO] \- com.h2database:h2:jar:1.3.170:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.142 s
[INFO] Finished at: 2015-01-23T15:43:19+05:30
[INFO] Final Memory: 8M/81M
[INFO] ------------------------------------------------------------------------
Even though I have excluded javax.persistence I'm getting the following warnings while build
[WARNING] javax.persistence-2.1.0.jar, hibernate-jpa-2.0-api-1.0.1.Final.jar define 92 overlappping classes:
[WARNING] - javax.persistence.SecondaryTable
[WARNING] - javax.persistence.TableGenerator
[WARNING] - javax.persistence.NamedNativeQueries
[WARNING] - javax.persistence.TransactionRequiredException
[WARNING] - javax.persistence.SecondaryTables
[WARNING] - javax.persistence.JoinTable
[WARNING] - javax.persistence.Id
[WARNING] - javax.persistence.Embedded
[WARNING] - javax.persistence.EntityResult
[WARNING] - javax.persistence.EntityManager
[WARNING] - 82 more...
[WARNING] javax.persistence-2.1.0.jar, eclipselink-2.5.1.jar define 24 overlappping classes:
[WARNING] - javax.persistence.NamedStoredProcedureQuery
[WARNING] - javax.persistence.ConstructorResult
[WARNING] - javax.persistence.ParameterMode
[WARNING] - javax.persistence.Index
[WARNING] - javax.persistence.AttributeConverter
[WARNING] - javax.persistence.NamedStoredProcedureQueries
[WARNING] - javax.persistence.Subgraph
[WARNING] - javax.persistence.ConstraintMode
[WARNING] - javax.persistence.Converts
[WARNING] - javax.persistence.criteria.CriteriaUpdate
[WARNING] - 14 more...
[WARNING] javax.persistence-2.1.0.jar, eclipselink-2.5.1.jar, hibernate-jpa-2.0-api-1.0.1.Final.jar define 80 overlappping classes:
[WARNING] - javax.persistence.criteria.SetJoin
[WARNING] - javax.persistence.criteria.Predicate
[WARNING] - javax.persistence.CacheRetrieveMode
[WARNING] - javax.persistence.TupleElement
[WARNING] - javax.persistence.metamodel.PluralAttribute
[WARNING] - javax.persistence.AccessType
[WARNING] - javax.persistence.Access
[WARNING] - javax.persistence.metamodel.ManagedType
[WARNING] - javax.persistence.metamodel.ListAttribute
[WARNING] - javax.persistence.criteria.CriteriaBuilder$Trimspec
[WARNING] - 70 more...
[WARNING] maven-shade-plugin has detected that some .class files
[WARNING] are present in two or more JARs. When this happens, only
[WARNING] one single version of the class is copied in the uberjar.
[WARNING] Usually this is not harmful and you can skeep these
[WARNING] warnings, otherwise try to manually exclude artifacts
[WARNING] based on mvn dependency:tree -Ddetail=true and the above
[WARNING] output
[WARNING] See http://docs.codehaus.org/display/MAVENUSER/Shade+Plugin
[INFO] Replacing original artifact with shaded artifact.
[INFO] Replacing /Users/sivakr/Documents/java/maven_1/target/gs-maven-0.1.0.jar with /Users/sivakr/Documents/java/maven_1/target/gs-maven-0.1.0-shaded.jar
[INFO] Dependency-reduced POM written at: /Users/sivakr/Documents/java/maven_1/dependency-reduced-pom.xml
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.214 s
[INFO] Finished at: 2015-01-23T15:43:11+05:30
[INFO] Final Memory: 7M/81M
[INFO] ------------------------------------------------------------------------
How to exclude the duplicate jar's ? And eliminate warnings
UPDATED dependency:tree
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building gs-maven 0.1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # gs-maven ---
[INFO] org.springframework:gs-maven:jar:0.1.0
[INFO] +- org.hibernate:hibernate-core:jar:4.1.4.Final:compile
[INFO] | +- antlr:antlr:jar:2.7.7:compile
[INFO] | +- org.jboss.logging:jboss-logging:jar:3.1.0.GA:compile
[INFO] | +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:jar:1.0.0.Final:compile
[INFO] | +- dom4j:dom4j:jar:1.6.1:compile
[INFO] | +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
[INFO] | +- org.javassist:javassist:jar:3.15.0-GA:compile
[INFO] | \- org.hibernate.common:hibernate-commons-annotations:jar:4.0.1.Final:compile
[INFO] \- ch.simas.qlrm:qlrm:jar:1.5.1:compile
[INFO] +- org.eclipse.persistence:eclipselink:jar:2.5.1:compile
[INFO] | \- org.eclipse.persistence:commonj.sdo:jar:2.1.1:compile
[INFO] \- com.h2database:h2:jar:1.3.170:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.138 s
[INFO] Finished at: 2015-01-23T18:11:06+05:30
[INFO] Final Memory: 8M/81M
[INFO] ------------------------------------------------------------------------
The POM change to exclude a dependency more than one level away is the same as excluding a dependency exactly one level away.
According to the documentation
if the dependency graph is as follows
Project-A
-> Project-B
-> Project-D
-> Project-E <!-- Exclude this dependency -->
-> Project-F
-> Project C
to exclude project E in project A POM
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>sample.ProjectA</groupId>
<artifactId>Project-A</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
...
<dependencies>
<dependency>
<groupId>sample.ProjectB</groupId>
<artifactId>Project-B</artifactId>
<version>1.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>sample.ProjectE</groupId> <!-- Exclude Project-E from Project-B -->
<artifactId>Project-E</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
Maven depdendcy plugin output format is:
[groupId]:[artifactId]:[type]:[version]
for the dependency:
org.eclipse.persistence:javax.persistence:jar:2.1.0:compile
The group is org.eclipse.persistence and the artifactId is javax.persistence
Your exclusion rule is wrong, the group and artifact are reversed. It should be:
<exclusions>
<exclusion>
<artifactId>javax.persistence</artifactId>
<groupId>org.eclipse.persistence</groupId>
</exclusion>
</exclusions>
EDIT: Add maven-shade-plugin configuration
To exclude the dependency from maven-shade-plugin try to add the exclusions to the plugin configuration:
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<excludes>
<exclude>org.eclipse.persistence:javax.persistence</exclude>
</excludes>
</artifactSet>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>hello.HelloWorld</mainClass>
</transformer>
</transformers>
</configuration>
</execution>

Categories