How to resolve "scanned from multiple locations" warnings caused by jersey - java

I have a Google App Engine project that I'm building with maven. I added jax-rs to it by adding the following bom to my pom:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-bom</artifactId>
<version>0.73.0-alpha</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey</groupId>
<artifactId>jersey-bom</artifactId>
<version>2.27</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
Also I needed these three dependencies:
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<exclusions>
<exclusion><!-- Exclude this repackaged javax.inject. -->
<groupId>org.glassfish.hk2.external</groupId>
<artifactId>javax.inject</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<exclusions>
<exclusion><!-- Exclude this repackaged javax.inject. -->
<groupId>org.glassfish.hk2.external</groupId>
<artifactId>javax.inject</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-binding</artifactId>
</dependency>
As you can see I have excluded some of the repackaged to get rid of some runtime warnings about duplicate classes being found. To be clear, every rest call using the jax-rs api's works fine and I don't see the warnings on google app engine itself, just locally. (full code at https://github.com/Leejjon/blindpool) When running it on the local jetty runtime using 'mvn appengine:run', it still complains about every json related class in the javax.json-1.1.jar and javax.json-api-1.1.jar.
Example
[INFO] GCLOUD: 2018-12-11 22:01:13.495:WARN:oeja.AnnotationParser:main: Unknown asm implementation version, assuming version 393216
[INFO] GCLOUD: 2018-12-11 22:01:13.780:WARN:oeja.AnnotationParser:qtp551734240-15: javax.json.Json scanned from multiple locations: jar:file:///C:/Users/Leejjon/IdeaProjects/Blindpool/backend/target/blindpool-1.0-SNAPSHOT/WEB-INF/lib/javax.json-api-1.1.jar!/javax/json/Json.class, jar:file:///C:/Users/Leejjon/IdeaProjects/Blindpool/backend/target/blindpool-1.0-SNAPSHOT/WEB-INF/lib/javax.json-1.1.jar!/javax/json/Json.class
When I look at my 'mvn dependency:tree' output I can see that my 'jersey-media-json-binding' dependency has both javax.json-1.1 and javax.json-api-1.1 in it. And they have classes that have the same names.
[INFO] +- org.glassfish.jersey.media:jersey-media-json-binding:jar:2.27:compile
[INFO] | +- org.glassfish:javax.json:jar:1.1:compile
[INFO] | +- org.eclipse:yasson:jar:1.0:compile
[INFO] | | +- javax.json:javax.json-api:jar:1.1:compile
[INFO] | | \- javax.enterprise:cdi-api:jar:2.0:compile
[INFO] | | +- javax.el:javax.el-api:jar:3.0.0:compile
[INFO] | | \- javax.interceptor:javax.interceptor-api:jar:1.2:compile
[INFO] | \- javax.json.bind:javax.json.bind-api:jar:1.0:compile
Full dependency tree (https://pastebin.com/JfwzavDX).
I have tried to exclude them but failed to do so in a way that didn't cause me to actually break my web app and get errors like: javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: java.lang.ExceptionInInitializerError
TLDR: What dependency to I exclude here to get rid of the duplicate location warning thrown by the 'mvn appengine:run' command without breaking the jax-rs application.
Hoping for that jax-rs/maven/jetty/jersey/google app engine god to pass by and point me in the right direction :)

Related

gRPC exception related with NameResolverProvider

I have a gRPC server written in Java, that is trying to access Firestore and other services, through a Service Account that has Project Owner roles. The server ran successfully plenty of times, but when I tried to run again, this happened:
Exception in thread "main" java.util.ServiceConfigurationError: io.grpc.NameResolverProvider: Provider io.grpc.grpclb.SecretGrpclbNameResolverProvider$Provider could not be instantiated
at java.util.ServiceLoader.fail(ServiceLoader.java:232)
at java.util.ServiceLoader.access$100(ServiceLoader.java:185)
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:384)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:404)
at java.util.ServiceLoader$1.next(ServiceLoader.java:480)
at io.grpc.ServiceProviders.loadAll(ServiceProviders.java:67)
at io.grpc.NameResolverRegistry.getDefaultRegistry(NameResolverRegistry.java:101)
at io.grpc.internal.AbstractManagedChannelImplBuilder.<init>(AbstractManagedChannelImplBuilder.java:107)
at io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder.<init>(NettyChannelBuilder.java:136)
at io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder.<init>(NettyChannelBuilder.java:131)
at io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder.forAddress(NettyChannelBuilder.java:117)
at io.grpc.netty.shaded.io.grpc.netty.NettyChannelProvider.builderForAddress(NettyChannelProvider.java:37)
at io.grpc.netty.shaded.io.grpc.netty.NettyChannelProvider.builderForAddress(NettyChannelProvider.java:23)
at io.grpc.ManagedChannelBuilder.forAddress(ManagedChannelBuilder.java:39)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createSingleChannel(InstantiatingGrpcChannelProvider.java:270)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.access$1500(InstantiatingGrpcChannelProvider.java:71)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider$1.createSingleChannel(InstantiatingGrpcChannelProvider.java:202)
at com.google.api.gax.grpc.ChannelPool.create(ChannelPool.java:72)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createChannel(InstantiatingGrpcChannelProvider.java:209)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.getTransportChannel(InstantiatingGrpcChannelProvider.java:192)
at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:155)
at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:122)
at com.google.cloud.firestore.spi.v1.GrpcFirestoreRpc.<init>(GrpcFirestoreRpc.java:122)
at com.google.cloud.firestore.FirestoreOptions$DefaultFirestoreRpcFactory.create(FirestoreOptions.java:90)
at com.google.cloud.firestore.FirestoreOptions$DefaultFirestoreRpcFactory.create(FirestoreOptions.java:82)
at com.google.cloud.ServiceOptions.getRpc(ServiceOptions.java:561)
at com.google.cloud.firestore.FirestoreOptions.getFirestoreRpc(FirestoreOptions.java:385)
at com.google.cloud.firestore.FirestoreImpl.<init>(FirestoreImpl.java:67)
at com.google.cloud.firestore.FirestoreOptions$DefaultFirestoreFactory.create(FirestoreOptions.java:73)
at com.google.cloud.firestore.FirestoreOptions$DefaultFirestoreFactory.create(FirestoreOptions.java:66)
at com.google.cloud.ServiceOptions.getService(ServiceOptions.java:541)
at services.FirestoreServiceActions.<init>(FirestoreServiceActions.java:25)
at CNTextServer.main(CNTextServer.java:47)
Caused by: java.lang.VerifyError: Cannot inherit from final class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:756)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:468)
at java.net.URLClassLoader.access$100(URLClassLoader.java:74)
at java.net.URLClassLoader$1.run(URLClassLoader.java:369)
at java.net.URLClassLoader$1.run(URLClassLoader.java:363)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:362)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
at java.lang.Class.getConstructor0(Class.java:3075)
at java.lang.Class.newInstance(Class.java:412)
at java.util.ServiceLoader$LazyIterator.nextService(ServiceLoader.java:380)
... 30 more
To simplify things and to turnaround some major problems that may happen on IntelliJ Idea,
I've created a much simpler (Maven) project that just has some code to start the server, and it worked fine, the server runs perfectly.
Although, when I add the line that initializes the Firestore service, the same Exceptions are thrown.
I have an environment variable (GOOGLE_APPLICATION_CREDENTIALS) pointing to a key of a service account that has Project Owner roles, just like I've mentioned before. I've also tried the FileInputStream alternative, pointing to the key, with no success.
The code of my simpler (Maven) project is:
private static final int SERVICE_PORT = 8000;
private Firestore firestoreService
public static void main(String[] args) {
try {
System.out.println("--> SETTING UP THE SERVER...");
GoogleCredentials credentials = GoogleCredentials.fromStream(new FileInputStream(SERVICE_ACCOUNT_KEY_PATH));
this.firestoreService = FirestoreOptions.newBuilder().setCredentials(credentials).build().getService();
Server service = ServerBuilder
.forPort(SERVICE_PORT)
.addService(new CNTextServer())
.build();
service.start();
System.out.println("--- SERVER STARTED. LISTENING ON PORT " + SERVICE_PORT);
System.out.println("--> PRESS 'ENTER' TO STOP THE SERVER");
Scanner scanner = new Scanner(System.in);
scanner.nextLine();
System.out.println("<-- SERVER SHUTTING DOWN...");
service.shutdown();
} catch (Exception ex) {
System.out.println("### EXCEPTION ON SERVER.MAIN() ###\n" + ex.getMessage());
}
}
The dependencies on the Maven pom.xml file are:
<dependencies>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
<version>1.28.0</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
<version>1.28.0</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
<version>1.28.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-firestore</artifactId>
<version>1.34.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>1.108.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-pubsub</artifactId>
<version>1.106.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-compute</artifactId>
<version>0.118.0-alpha</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-vision</artifactId>
<version>1.99.3</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-translate</artifactId>
<version>1.94.5</version>
</dependency>
<dependency>
<groupId>leic.cn.li62d-g04</groupId>
<artifactId>CNTextContract</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/../CNTextContract/target/CNTextContract-1.0-SNAPSHOT.jar</systemPath>
</dependency>
</dependencies>
Running mvn dependency:tree we see:
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # examples ---
[INFO] com.example:examples:jar:1.0.0
[INFO] +- io.grpc:grpc-netty-shaded:jar:1.28.0:compile
[INFO] | \- io.grpc:grpc-core:jar:1.28.0:compile (version selected from constraint [1.28.0,1.28.0])
[INFO] +- io.grpc:grpc-protobuf:jar:1.28.0:compile
[INFO] | +- io.grpc:grpc-api:jar:1.28.0:compile
[INFO] | +- com.google.protobuf:protobuf-java:jar:3.11.0:compile
[INFO] | +- com.google.guava:guava:jar:28.1-android:compile
[INFO] | +- com.google.api.grpc:proto-google-common-protos:jar:1.17.0:compile
[INFO] | \- io.grpc:grpc-protobuf-lite:jar:1.28.0:compile
[INFO] +- io.grpc:grpc-stub:jar:1.28.0:compile
[INFO] +- com.google.cloud:google-cloud-firestore:jar:1.34.0:compile
[INFO] | +- com.google.cloud:google-cloud-core-grpc:jar:1.93.5:compile
...
[INFO] | +- io.grpc:grpc-context:jar:1.29.0:compile
[INFO] | +- com.google.api:gax:jar:1.56.0:compile
[INFO] | +- com.google.auth:google-auth-library-oauth2-http:jar:0.20.0:compile
[INFO] | +- com.google.errorprone:error_prone_annotations:jar:2.3.4:compile
[INFO] | +- org.codehaus.mojo:animal-sniffer-annotations:jar:1.18:compile
[INFO] | +- com.google.api:gax-grpc:jar:1.56.0:compile
[INFO] | +- io.grpc:grpc-auth:jar:1.29.0:compile
[INFO] | +- io.grpc:grpc-alts:jar:1.29.0:compile
[INFO] | +- io.grpc:grpc-grpclb:jar:1.29.0:compile
The problem is that grpc-core is too old. You can see io.grpc:grpc-core:jar:1.28.0 and io.grpc:grpc-grpclb:jar:1.29.0:compile. grpclb depends on grpc-core 1.29.0. In 1.29.0 GrpclbNameResolver was added that extends DnsNameResolver from grpc-core. But in 1.28.0 DnsNameResolver was final. Downgrades are very likely to cause breakages.
To fix the version problem(s) (there's several), move the io.grpc dependencies to the end bump their versions to 1.29.0.
<dependencies>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-firestore</artifactId>
<version>1.34.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-storage</artifactId>
<version>1.108.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-pubsub</artifactId>
<version>1.106.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-compute</artifactId>
<version>0.118.0-alpha</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-vision</artifactId>
<version>1.99.3</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-translate</artifactId>
<version>1.94.5</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
<version>1.29.0</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
<version>1.29.0</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
<version>1.29.0</version>
</dependency>
</dependencies>
Maven has poor transitive dependency resolution, and happily downgrades packages without any warning. It is good practice to use maven-enforcer's requireUpperBoundDeps to detect issues like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<id>enforce</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireUpperBoundDeps/>
</rules>
</configuration>
</execution>
</executions>
</plugin>
With your broken dependencies, it would have noticed the downgrades:
[WARNING] Rule 0: org.apache.maven.plugins.enforcer.RequireUpperBoundDeps failed with message:
Failed while enforcing RequireUpperBoundDeps. The error(s) are [
Require upper bound dependencies error for io.grpc:grpc-netty-shaded:1.28.0 paths to dependency are:
+-com.example:examples:1.0.0
+-io.grpc:grpc-netty-shaded:1.28.0
and
+-com.example:examples:1.0.0
+-com.google.cloud:google-cloud-firestore:1.34.0
+-io.grpc:grpc-netty-shaded:1.29.0
,
Require upper bound dependencies error for io.grpc:grpc-protobuf:1.28.0 paths to dependency are:
+-com.example:examples:1.0.0
+-io.grpc:grpc-protobuf:1.28.0
and
+-com.example:examples:1.0.0
+-com.google.cloud:google-cloud-firestore:1.34.0
+-io.grpc:grpc-protobuf:1.29.0
and
+-com.example:examples:1.0.0
+-com.google.cloud:google-cloud-pubsub:1.106.0
+-io.grpc:grpc-protobuf:1.29.0
...

Changing from info.cukes to io.cucumber with testNG Maven. Throwing runtime error

I have a selenium cucumber testng framework using maven. I was hoping to get step descriptions when I run my cucumber tests with testng. It was an old project so I have changed my dependencies from info.cukes to the latest version of io.cucumber. However it seems to be throwing out errors whenever I run the runner test file.
java.lang.NoSuchMethodError: cucumber.runtime.RuntimeOptions.getPluginFormatterNames()Ljava/util/List;
at cucumber.runtime.formatter.Plugins.createPlugins(Plugins.java:64)
at cucumber.runtime.formatter.Plugins.<init>(Plugins.java:37)
at cucumber.api.testng.TestNGCucumberRunner.<init>(TestNGCucumberRunner.java:56)
at cucumber.api.testng.AbstractTestNGCucumberTests.setUpClass(AbstractTestNGCucumberTests.java:16)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.MethodInvocationHelper.invokeMethodConsideringTimeout(MethodInvocationHelper.java:59)
at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:458)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:222)
at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:142)
at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:168)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:105)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)
I have the following maven dependencies but have no idea if it is a dependency that I am missing to get the test to run? Any Help would be greatly appreciated. As when I have search this issue it seems that it is mostly solved by having the same version dependencies of all the io.cucumber files which I do.
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-junit -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>4.2.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>4.2.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-testng -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-testng</artifactId>
<version>4.2.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.21.0</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/tag-expressions -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>tag-expressions</artifactId>
<version>1.1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-expressions -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-expressions</artifactId>
<version>6.2.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/messages -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>messages</artifactId>
<version>2.1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/cucumber-java8 -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java8</artifactId>
<version>4.2.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.github.mkolisnyk/cucumber-report-generator -->
<dependency>
<groupId>com.github.mkolisnyk</groupId>
<artifactId>cucumber-report-generator</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.14.3</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/io.cucumber/gherkin -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>gherkin</artifactId>
<version>6.0.14</version>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/gherkin -->
<!--<dependency>
<groupId>info.cukes</groupId>
<artifactId>gherkin</artifactId>
<version>2.12.2</version>
<scope>provided</scope>
</dependency>-->
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-core -->
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
<version>4.2.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/ru.sbtqa.tag/cucumber-runner -->
<dependency>
<groupId>ru.sbtqa.tag</groupId>
<artifactId>cucumber-runner</artifactId>
<version>1.0.7</version>
</dependency>
Check maven pom.xml cucumber-core cucumber-java cucumber-junit
These files should have the same version. In your example, cucumber-java artifact id has a different version than the rest.
Try changing it.
Find below some snippets to break down the problem
check if there is a transitive dependency to groupid info.cukes
$ mvn dependency:tree | grep 'info.cuke'
[INFO] | +- info.cukes:cucumber-junit:jar:1.2.5:compile
[INFO] | | \- info.cukes:cucumber-core:jar:1.2.5:compile
[INFO] | | +- info.cukes:cucumber-html:jar:0.2.3:compile
[INFO] | | \- info.cukes:cucumber-jvm-deps:jar:1.0.5:compile
[INFO] | +- info.cukes:cucumber-testng:jar:1.2.5:compile
[INFO] | +- info.cukes:cucumber-java:jar:1.2.5:compile
[INFO] | +- info.cukes:gherkin:jar:2.12.2:compile
when checking the full output reveals which of your dependency depends on it
...
[INFO] +- com.github.mkolisnyk:cucumber-report-generator:jar:1.3:compile
...
[INFO] | +- info.cukes:cucumber-junit:jar:1.2.5:compile
...
[INFO] | +- info.cukes:cucumber-testng:jar:1.2.5:compile
...
[INFO] \- ru.sbtqa.tag:cucumber-runner:jar:1.0.7:compile
[INFO] \- ru.sbtqa.tag:cucumber-runner:jar:1.0.7:compile
[INFO] +- ru.yandex.qatools.allure:allure-cucumber-jvm-adaptor:jar:1.6.4:compile
...
[INFO] | +- info.cukes:cucumber-core:jar:1.2.5:compile
...
[INFO] | +- info.cukes:cucumber-java:jar:1.2.5:compile
[INFO] | +- info.cukes:gherkin:jar:2.12.2:compile
...
[INFO] +- info.cukes:cucumber-junit:jar:1.2.5:compile
as there might be an overlapping of classed with the same qualified name, exclude those transient dependencies in the pom.xml
<dependency>
<groupId>com.github.mkolisnyk</groupId>
<artifactId>cucumber-report-generator</artifactId>
<version>1.3</version>
<exclusions>
<exclusion>
<groupId>info.cukes</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
running the test again it throws an exception
java.lang.NoClassDefFoundError: gherkin/IGherkinDialectProvider
as we explicitly define the dependency io.cucumber:gherkin it might be related to the specified <version>, comment it out to see if another version is fetched
<!--<dependency>-->
<!--<groupId>io.cucumber</groupId>-->
<!--<artifactId>gherkin</artifactId>-->
<!--<version>6.0.14</version>-->
<!--</dependency>-->
this reveals that io.cucumber:cucumber-core:jar:4.2.0 depends on version 5.1.0 of io.cucumber:gherkin
$ mvn dependency:tree
...
[INFO] +- io.cucumber:cucumber-core:jar:4.2.0:compile
[INFO] | +- io.cucumber:cucumber-html:jar:0.2.7:compile
[INFO] | +- io.cucumber:gherkin:jar:5.1.0:compile
With those changes at least the TestNG unit test is running.
As the dependencies com.github.mkolisnyk:cucumber-report-generator and ru.sbtqa.tag:cucumber-runner depending on the info.cuke dependencies they might not work correctly anymore. To solve this kind of problem you could:
check for a newer version which might not depend on group id info.cuke
use earlier version of io.cucumber dependencies
use a more finegrained exclusion of the info.cuke dependencies, instead of excluding all artifact ids
a combination of above points
something else, depending on your use case and requirements
Maybe those steps help you to find a solution working for you.

Elastic Search 5.6.4 pom transport issue

We are pointing to Elasticsearch 5.6.4. I used below entry in pom.xml:
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>5.6.4</version>
</dependency>
When I created the dependency tree:
[INFO] +- org.elasticsearch.client:transport:jar:5.6.4:compile
[INFO] | +- org.elasticsearch:elasticsearch:jar:2.4.4:compile (version
managed from 5.6.4)
[INFO] | | +- org.apache.lucene:lucene-core:jar:5.5.2:compile
[INFO] | | +- org.apache.lucene:lucene-backward-codecs:jar:5.5.2:compile
Can someone help to resolve this. I need elasticsearch-5.6.4.jar, but I am getting run time issues.
<pre>
this resolved my issue
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>5.6.4</version>
</dependency>
</dependencies>
</dependencyManagement>
</pre>

Why are my nested maven dependencies not showing up when compiling

I have a library named my-library which I packaged with Maven and stored on a private Nexus repository. It compiles and gets uploaded to my repo correctly and has the following dependencies specified in its pom.xml file:
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.13</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.1.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
I am including this dependency in another project, my-child-project, using the following pom.xml blocks:
<repositories>
<repository>
<id>MyRepo</id>
<name>My Maven Repository</name>
<url>http://localhost:8081/nexus/repo</url>
</repository>
</repositories>
...
<dependencies>
<dependency>
<groupId>com.my.group</groupId>
<artifactId>my-library</artifactId>
<scope>compile</scope>
<version>1.0.0</version>
</dependency>
</dependencies>
When i run mvn clean install in my-child-project, it appears that maven is able to find and download my-library but not the nested dependency on com.google.protobuf unless i include it explicitly in the pom.xml for my-child-project. I can confirm that Maven can see my dependency but not the nested one when running mvn dependency:tree:
...
[INFO] +- org.springframework.data:spring-data-redis:jar:1.7.1.RELEASE:compile
[INFO] | +- org.springframework.data:spring-data-keyvalue:jar:1.1.1.RELEASE:compile
[INFO] | \- org.springframework:spring-oxm:jar:4.2.5.RELEASE:compile
[INFO] +- redis.clients:jedis:jar:2.8.1:compile
[INFO] +- javax.servlet:javax.servlet-api:jar:3.1.0:provided
[INFO] +- com.my.group:my-library:jar:1.0.0:compile
[INFO] +- com.fasterxml.jackson.core:jackson-annotations:jar:2.4.4:compile
...
Is this how a nested library dependency is supposed to work? I thought nested dependencies in other dependencies are automatically resolved and downloaded by Maven in compile scope. I was hoping to only list the nested dependency in my-library and not in my-child-project but it seems that doesn't work.
First, the parent pom.xml should add dependencyManagement tag outside the dependencies tag. This is just to manage the modules dependencies in one place, but not actually import them into your project.
You still have to declare it in your child module's pom. (But you can leave out the version tag, as that will be inherited from the parent pom)
#herokingsley's answer got me to the correct configuration. I was hesitating to try it because the answer seemed to suggest that i need to redeclare the nested dependency in my child. When i finally did try it i purposely did not declare the nested dependency in my-child-project and it still worked like a charm. Here is the code that solved my problem. I changed the code in my-library to the following:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.1.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.13</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
The above change was enough as it resulted in the following output when running mvn dependency:tree:
...
[INFO] +- org.springframework.data:spring-data-redis:jar:1.7.1.RELEASE:compile
[INFO] | +- org.springframework.data:spring-data-keyvalue:jar:1.1.1.RELEASE:compile
[INFO] | \- org.springframework:spring-oxm:jar:4.2.5.RELEASE:compile
[INFO] +- redis.clients:jedis:jar:2.8.1:compile
[INFO] +- javax.servlet:javax.servlet-api:jar:3.1.0:provided
[INFO] +- com.my.group:my-library:jar:1.0.0:compile
[INFO] | \- com.google.protobuf:protobuf-java:jar:3.1.0:compile
[INFO] +- com.fasterxml.jackson.core:jackson-annotations:jar:2.4.4:compile
...

Issue with Maven war Plugin

I am using maven to package my war file. I have some dependencies with provided as scope. When i do a maven clean install, the war is created successfully, but the transitive dependencies of the jars with scope as provided are included in my lib directory. Is there any way to remove them ?
Example scenario: Below is one of my dependency in pom
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>${resteasy.version}</version>
<scope>provided</scope>
</dependency>
this one is including the jar activation-1.1.jar. Also the dependency tree for resteasy-jaxrs is like below.
[INFO] +- org.jboss.resteasy:resteasy-jaxrs:jar:2.3.6.Final:provided
[INFO] | +- org.jboss.resteasy:jaxrs-api:jar:2.3.6.Final:provided
[INFO] | +- javax.annotation:jsr250-api:jar:1.0:compile
[INFO] | +- javax.activation:activation:jar:1.1:compile
[INFO] | +- org.apache.httpcomponents:httpclient:jar:4.1.2:provided
[INFO] | | \- org.apache.httpcomponents:httpcore:jar:4.1.2:provided
[INFO] | \- net.jcip:jcip-annotations:jar:1.0:compile
The easiest way is to create a <dependencyManagement> tag and put the sub-dependency inside and set the scope to provided:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>jsr250-api</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
</dependencyManagement>
That way the scope of your transitive-dependency is overwritten:
[INFO] | +- javax.annotation:jsr250-api:jar:1.0:provided (scope managed from compile)
[INFO] | +- javax.activation:activation:jar:1.1:provided (scope managed from compile)
Be sure to do a Maven-> Update Project and check the Force Update checkbox before checking the dependency:tree.
The above mentioned solution is not possible in case i have so many transitive dependencies coming in my lib. Finally got the maven exclusion which is working fine.
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>${resteasy.version}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<artifactId>*</artifactId>
<groupId>*</groupId>
</exclusion>
</exclusions>
</dependency>

Categories