New to Scala, I'm on step one of implementing a ScalaTest with https://github.com/embeddedkafka/embedded-kafka according to the second example at the top of that README:
import net.manub.embeddedkafka.EmbeddedKafka
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpecLike
class MinimalTest extends AnyWordSpecLike with Matchers {
"runs with embedded kafka" should {
"work" in {
EmbeddedKafka.start()
1 + 1 shouldBe 2
// ... code goes here
EmbeddedKafka.stop()
}
}
}
Running this test, the failure is at a lower level than I am familiar with:
MinimalTest:
runs with embedded kafka
*** RUN ABORTED ***
java.lang.NoClassDefFoundError: scala/collection/GenTraversableOnce
at com.myorganization.api.MinimalTest.$anonfun$new$2(MinimalTest.scala:13)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
at org.scalatest.OutcomeOf.outcomeOf(OutcomeOf.scala:85)
at org.scalatest.OutcomeOf.outcomeOf$(OutcomeOf.scala:83)
at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
at org.scalatest.Transformer.apply(Transformer.scala:22)
at org.scalatest.Transformer.apply(Transformer.scala:20)
at org.scalatest.wordspec.AnyWordSpecLike$$anon$3.apply(AnyWordSpecLike.scala:1076)
at org.scalatest.TestSuite.withFixture(TestSuite.scala:196)
at org.scalatest.TestSuite.withFixture$(TestSuite.scala:195)
...
Cause: java.lang.ClassNotFoundException: scala.collection.GenTraversableOnce
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
at com.myorganization.api.MinimalTest.$anonfun$new$2(MinimalTest.scala:13)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.scala:18)
at org.scalatest.OutcomeOf.outcomeOf(OutcomeOf.scala:85)
at org.scalatest.OutcomeOf.outcomeOf$(OutcomeOf.scala:83)
at org.scalatest.OutcomeOf$.outcomeOf(OutcomeOf.scala:104)
at org.scalatest.Transformer.apply(Transformer.scala:22)
at org.scalatest.Transformer.apply(Transformer.scala:20)
...
I suspect a mismatch of dependency versions, but can't spot it. Here's my relevant build.gradle contents:
plugins {
id 'java'
id 'scala'
}
task spec(dependsOn: ['testClasses'], type: JavaExec) {
main = 'org.scalatest.tools.Runner'
args = ['-R', 'build/classes/scala/test', '-o']
classpath = sourceSets.test.runtimeClasspath
}
dependencies {
compile 'io.confluent:kafka-streams-avro-serde:5.4.0'
compile 'io.github.embeddedkafka:embedded-kafka-streams_2.12:2.4.0'
compile 'io.github.embeddedkafka:embedded-kafka_2.12:2.4.0'
compile 'org.apache.avro:avro:1.9.1'
compile 'org.apache.kafka:kafka-clients:2.4.0'
compile 'org.apache.kafka:kafka-streams:2.4.0'
compile 'org.apache.kafka:kafka_2.13:2.4.0'
compile 'org.scala-lang:scala-reflect:2.12.6'
testCompile 'io.github.embeddedkafka:embedded-kafka-schema-registry_2.12:5.4.0' // match schema registry version
testCompile 'io.github.embeddedkafka:embedded-kafka-streams_2.13:2.4.0' // match kafka streams version
testCompile 'io.github.embeddedkafka:embedded-kafka_2.13:2.4.0' // match kafka version
testCompile 'org.scala-lang:scala-library:2.13.2'
testCompile 'org.scalatest:scalatest_2.13:3.1.2'
testImplementation 'junit:junit:4.11'
testRuntime 'org.pegdown:pegdown:1.4.2'
}
Gradle can indeed be a bit funny with transitive dependencies for Scala - in the sense that it will not automatically calculate a coherent set of versions.
The "missing" class scala/collection/GenTraversableOnce is part of the scala-library and is available in 2.12.x
So you should be able to fix this by:
a. Explicitly declaring the scala library version on your runtime classpath:
implementation group: 'org.scala-lang', name: 'scala-library', version: '2.12.6'
b. Checking all your other dependencies for 2.13 versions of the libraries (as #ShankarShastri suggested). Seems like embedded-kafka does have a 2.12 compatible build here: https://mvnrepository.com/artifact/io.github.embeddedkafka/embedded-kafka_2.12/2.5.0
Once you have done this, assuming your IDE is set up to sync with your build.gradle file, you should be able to look at the dependencies (declared and transitive) that gradle has calculated. If you still have problems, go through these manually and see if the org.scala-lang:scala-library library is missing or declared twice. If you have multiple declarations you can look at each library's dependencies in mvncentral.com .
N.B. the reason for step (a) is that you have scala artefacts in your 'compile' dependencies, so I assume that all your code (not just your test code) is using scala.
I can confirm the fix is validation dependencies. Or more technically check the test dependencies.
For me I upgraded my SpringBoot version which changed my spring-kafka-test version which intern included kafka 2.13.x which finally included scala libs.
I used mvn dependency:tree on my project's build file and searched for '2.12' to find where the old dependency was coming from. Example dependency tree (unrelated dependencies removed). Notice org.apache.kafka:kafka_2.11:jar:0.10.0.0 included as part of my.company.riptide.api:ness-logger:jar:1.0.0 but org.springframework.kafka:spring-kafka-test:jar:2.7.9 includes a newer version org.apache.kafka:kafka_2.13:jar:2.7.2
My solution was to exclude kafaka_2.11 from my ness-logger dependency like this:
<dependency>
<groupId>my.company.riptide.api</groupId>
<artifactId>ness-logger</artifactId>
<version>1.0.0</version>
<exclusions>
<exclusion>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka_2.11</artifactId>
</exclusion>
</exclusions>
</dependency>
Truncated output of mvn dependency:tree:
[INFO] +- my.company.riptide.api:ness-logger:jar:1.0.0:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-validation:jar:2.5.7:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-el:jar:9.0.55:compile
[INFO] | | \- org.hibernate.validator:hibernate-validator:jar:6.2.0.Final:compile
[INFO] | | \- jakarta.validation:jakarta.validation-api:jar:2.0.2:compile
[INFO] | +- commons-io:commons-io:jar:2.7:compile
[INFO] | +- my.company.eis:ness-logging-package:jar:4.0.1:compile
[INFO] | | +- org.apache.avro:avro:jar:1.8.2:compile
[INFO] | | | +- org.codehaus.jackson:jackson-core-asl:jar:1.9.13:compile
[INFO] | | | +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13:compile
[INFO] | | | +- com.thoughtworks.paranamer:paranamer:jar:2.7:compile
[INFO] | | | \- org.tukaani:xz:jar:1.5:compile
[INFO] | | +- org.apache.avro:avro-compiler:jar:1.8.2:compile
[INFO] | | | +- org.apache.velocity:velocity:jar:1.7:compile
[INFO] | | | \- joda-time:joda-time:jar:2.7:compile
[INFO] | | +- org.apache.kafka:kafka_2.11:jar:0.10.0.0:compile
[INFO] | | | +- com.101tec:zkclient:jar:0.8:compile
[INFO] | | | \- org.scala-lang.modules:scala-parser-combinators_2.11:jar:1.0.4:compile
[INFO] | | \- com.netflix.hystrix:hystrix-core:jar:1.5.18:compile
[INFO] | | +- com.netflix.archaius:archaius-core:jar:0.4.1:compile
[INFO] | | \- io.reactivex:rxjava:jar:1.3.8:compile
[INFO] | +- org.springframework.boot:spring-boot-loader-tools:jar:2.5.7:compile
[INFO] | | \- org.apache.commons:commons-compress:jar:1.21:compile
[INFO] | \- my.company.riptide.springboot:graceful-shutdown:jar:1.0.2:compile
[INFO] +- org.springframework.kafka:spring-kafka:jar:2.7.9:compile
[INFO] | +- org.springframework:spring-messaging:jar:5.3.13:compile
[INFO] | +- org.springframework:spring-tx:jar:5.3.13:compile
[INFO] | +- org.springframework.retry:spring-retry:jar:1.3.1:compile
[INFO] | | \- javax.annotation:javax.annotation-api:jar:1.3.2:compile
[INFO] | +- org.apache.kafka:kafka-clients:jar:2.7.2:compile
[INFO] | | +- com.github.luben:zstd-jni:jar:1.4.5-6:compile
[INFO] | | +- org.lz4:lz4-java:jar:1.7.1:compile
[INFO] | | \- org.xerial.snappy:snappy-java:jar:1.1.7.7:compile
[INFO] | \- com.google.code.findbugs:jsr305:jar:3.0.2:compile
[INFO] +- junit:junit:jar:4.13.2:test
[INFO] | \- org.hamcrest:hamcrest-core:jar:2.2:compile
[INFO] +- io.cucumber:cucumber-spring:jar:7.0.0:test
[INFO] | \- org.apiguardian:apiguardian-api:jar:1.1.2:test
[INFO] +- io.cucumber:cucumber-core:jar:7.0.0:test
[INFO] | +- io.cucumber:cucumber-gherkin:jar:7.0.0:test
[INFO] | +- io.cucumber:cucumber-gherkin-messages:jar:7.0.0:test
[INFO] | +- io.cucumber:messages:jar:17.1.1:test
[INFO] | +- io.cucumber:tag-expressions:jar:4.0.2:test
[INFO] | +- io.cucumber:cucumber-expressions:jar:13.0.1:test
[INFO] | +- io.cucumber:datatable:jar:7.0.0:test
[INFO] | +- io.cucumber:cucumber-plugin:jar:7.0.0:test
[INFO] | +- io.cucumber:docstring:jar:7.0.0:test
[INFO] | +- io.cucumber:html-formatter:jar:17.0.0:test
[INFO] | \- io.cucumber:create-meta:jar:6.0.1:test
[INFO] +- org.springframework.kafka:spring-kafka-test:jar:2.7.9:test
[INFO] | +- org.apache.kafka:kafka-clients:jar:test:2.7.2:test
[INFO] | +- org.apache.kafka:kafka-streams:jar:2.7.2:test
[INFO] | | +- org.apache.kafka:connect-json:jar:2.7.2:test
[INFO] | | | \- org.apache.kafka:connect-api:jar:2.7.2:test
[INFO] | | \- org.rocksdb:rocksdbjni:jar:5.18.4:test
[INFO] | +- org.apache.kafka:kafka-streams-test-utils:jar:2.7.2:test
[INFO] | +- org.apache.kafka:kafka_2.13:jar:2.7.2:test
[INFO] | | +- org.apache.kafka:kafka-raft:jar:2.7.2:test
[INFO] | | +- com.fasterxml.jackson.module:jackson-module-scala_2.13:jar:2.12.5:test
[INFO] | | +- com.fasterxml.jackson.dataformat:jackson-dataformat-csv:jar:2.12.5:test
[INFO] | | +- net.sf.jopt-simple:jopt-simple:jar:5.0.4:compile
[INFO] | | +- com.yammer.metrics:metrics-core:jar:2.2.0:compile
[INFO] | | +- org.scala-lang.modules:scala-collection-compat_2.13:jar:2.2.0:test
[INFO] | | +- org.scala-lang.modules:scala-java8-compat_2.13:jar:0.9.1:test
[INFO] | | +- org.scala-lang:scala-library:jar:2.13.3:compile
[INFO] | | +- org.scala-lang:scala-reflect:jar:2.13.3:test
[INFO] | | +- com.typesafe.scala-logging:scala-logging_2.13:jar:3.9.2:test
[INFO] | | +- org.apache.zookeeper:zookeeper:jar:3.5.9:compile
[INFO] | | | +- org.apache.zookeeper:zookeeper-jute:jar:3.5.9:compile
[INFO] | | | +- org.apache.yetus:audience-annotations:jar:0.5.0:compile
[INFO] | | | \- io.netty:netty-transport-native-epoll:jar:4.1.70.Final:compile
[INFO] | | \- commons-cli:commons-cli:jar:1.4:test
[INFO] | +- org.apache.kafka:kafka_2.13:jar:test:2.7.2:test
[INFO] | \- org.junit.jupiter:junit-jupiter-api:jar:5.7.2:test
[INFO] | +- org.opentest4j:opentest4j:jar:1.2.0:test
[INFO] | \- org.junit.platform:junit-platform-commons:jar:1.7.2:test
Related
I'm migrating a project from Spring Boot 2.6.1 to Spring Boot 3.0.2 and I'm having problems with log4j dependencies versions. I have modified all the dependencies that were giving me problems but I still couldn't solve the problem. The error is as follows:
Java HotSpot(TM) 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
SLF4J: No SLF4J providers were found.
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See https://www.slf4j.org/codes.html#noProviders for further details.
SLF4J: Class path contains SLF4J bindings targeting slf4j-api versions 1.7.x or earlier.
SLF4J: Ignoring binding found at [jar:file:/C:/Users/Pablo/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.18.0/log4j-slf4j-impl-2.18.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See https://www.slf4j.org/codes.html#ignoredBindings for an explanation.
ERROR [2023-01-27 11:54:41] [ org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter report 40]
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
org.springframework.boot.logging.log4j2.Log4J2LoggingSystem.initialize(Log4J2LoggingSystem.java:242)
The following method did not exist:
'void org.apache.logging.log4j.util.PropertiesUtil.addPropertySource(org.apache.logging.log4j.util.PropertySource)'
The calling method's class, org.springframework.boot.logging.log4j2.Log4J2LoggingSystem, was loaded from the following location:
jar:file:/C:/Users/Pablo/.m2/repository/org/springframework/boot/spring-boot/3.0.2/spring-boot-3.0.2.jar!/org/springframework/boot/logging/log4j2/Log4J2LoggingSystem.class
The called method's class, org.apache.logging.log4j.util.PropertiesUtil, is available from the following locations:
jar:file:/C:/Users/Pablo/.m2/repository/org/apache/logging/log4j/log4j-api/2.18.0/log4j-api-2.18.0.jar!/org/apache/logging/log4j/util/PropertiesUtil.class
The called method's class hierarchy was loaded from the following locations:
org.apache.logging.log4j.util.PropertiesUtil: file:/C:/Users/Pablo/.m2/repository/org/apache/logging/log4j/log4j-api/2.18.0/log4j-api-2.18.0.jar
Action:
Correct the classpath of your application so that it contains compatible versions of the classes org.springframework.boot.logging.log4j2.Log4J2LoggingSystem and org.apache.logging.log4j.util.PropertiesUtil
Process finished with exit code 0
And the service dependencies are:
--- maven-dependency-plugin:2.8:tree (default-cli) # core ---
[INFO] es._3xs.adp:core:jar:1.0-SNAPSHOT
[INFO] +- es._3xs.adp:library:jar:1.0-SNAPSHOT:compile
[INFO] | +- org.springframework.boot:spring-boot-configuration-processor:jar:3.0.2:compile
[INFO] | +- org.springframework:spring-websocket:jar:6.0.4:compile
[INFO] | | \- org.springframework:spring-context:jar:6.0.4:compile
[INFO] | +- org.springframework.retry:spring-retry:jar:2.0.0:compile
[INFO] | +- com.opencsv:opencsv:jar:5.5.2:compile
[INFO] | | +- org.apache.commons:commons-lang3:jar:3.12.0:compile
[INFO] | | +- org.apache.commons:commons-text:jar:1.9:compile
[INFO] | | +- commons-beanutils:commons-beanutils:jar:1.9.4:compile
[INFO] | | | +- commons-logging:commons-logging:jar:1.2:compile
[INFO] | | | \- commons-collections:commons-collections:jar:3.2.2:compile
[INFO] | | \- org.apache.commons:commons-collections4:jar:4.4:compile
[INFO] | \- org.apache.httpcomponents:httpclient:jar:4.5.14:compile
[INFO] | \- commons-codec:commons-codec:jar:1.15:compile
[INFO] +- org.springframework.data:spring-data-redis:jar:3.0.1:compile
[INFO] | +- org.springframework.data:spring-data-keyvalue:jar:3.0.1:compile
[INFO] | | \- org.springframework.data:spring-data-commons:jar:3.0.1:compile
[INFO] | +- org.springframework:spring-tx:jar:6.0.4:compile
[INFO] | +- org.springframework:spring-oxm:jar:6.0.4:compile
[INFO] | +- org.springframework:spring-aop:jar:6.0.4:compile
[INFO] | +- org.springframework:spring-context-support:jar:6.0.4:compile
[INFO] | \- org.slf4j:slf4j-api:jar:2.0.6:compile
[INFO] +- redis.clients:jedis:jar:3.7.0:compile
[INFO] | \- org.apache.commons:commons-pool2:jar:2.11.1:compile
[INFO] +- org.springframework.boot:spring-boot-starter-websocket:jar:3.0.2:compile
[INFO] | \- org.springframework:spring-messaging:jar:6.0.4:compile
[INFO] +- commons-io:commons-io:jar:2.6:compile
[INFO] +- org.springframework.boot:spring-boot-starter-mail:jar:3.0.2:compile
[INFO] | +- org.springframework.boot:spring-boot-starter:jar:3.0.2:compile
[INFO] | | +- jakarta.annotation:jakarta.annotation-api:jar:2.1.1:compile
[INFO] | | \- org.yaml:snakeyaml:jar:1.33:compile
[INFO] | \- org.eclipse.angus:jakarta.mail:jar:1.0.0:compile
[INFO] | \- org.eclipse.angus:angus-activation:jar:1.0.0:runtime
[INFO] +- uk.org.webcompere:system-stubs-junit4:jar:1.2.0:test
[INFO] | \- uk.org.webcompere:system-stubs-core:jar:1.2.0:test
[INFO] +- com.h2database:h2:jar:1.4.200:compile
[INFO] +- org.apache.httpcomponents.client5:httpclient5:jar:5.2.1:compile
[INFO] | +- org.apache.httpcomponents.core5:httpcore5:jar:5.1.5:compile
[INFO] | \- org.apache.httpcomponents.core5:httpcore5-h2:jar:5.1.5:compile
[INFO] +- org.apache.httpcomponents:httpcore:jar:4.4.13:compile
[INFO] +- org.springframework.boot:spring-boot-starter-thymeleaf:jar:3.0.2:compile
[INFO] | \- org.thymeleaf:thymeleaf-spring6:jar:3.1.1.RELEASE:compile
[INFO] | \- org.thymeleaf:thymeleaf:jar:3.1.1.RELEASE:compile
[INFO] | +- org.attoparser:attoparser:jar:2.0.6.RELEASE:compile
[INFO] | \- org.unbescape:unbescape:jar:1.1.6.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-rest:jar:3.0.2:compile
[INFO] | \- org.springframework.data:spring-data-rest-webmvc:jar:4.0.1:compile
[INFO] | \- org.springframework.data:spring-data-rest-core:jar:4.0.1:compile
[INFO] | +- org.springframework.hateoas:spring-hateoas:jar:2.0.1:compile
[INFO] | +- org.springframework.plugin:spring-plugin-core:jar:3.0.0:compile
[INFO] | \- org.atteo:evo-inflector:jar:1.3:compile
[INFO] +- org.thymeleaf.extras:thymeleaf-extras-springsecurity5:jar:3.0.4.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-devtools:jar:3.0.2:compile
[INFO] | +- org.springframework.boot:spring-boot:jar:3.0.2:compile
[INFO] | \- org.springframework.boot:spring-boot-autoconfigure:jar:3.0.2:compile
[INFO] +- org.springframework.ldap:spring-ldap-core:jar:2.3.6.RELEASE:compile
[INFO] | +- org.springframework:spring-beans:jar:6.0.4:compile
[INFO] | \- org.springframework:spring-core:jar:6.0.4:compile
[INFO] | \- org.springframework:spring-jcl:jar:6.0.4:compile
[INFO] +- com.github.wvengen:proguard-maven-plugin:jar:2.6.0:compile
[INFO] | +- org.apache.ant:ant:jar:1.10.12:compile
[INFO] | | \- org.apache.ant:ant-launcher:jar:1.10.12:compile
[INFO] | +- org.apache.maven:maven-archiver:jar:2.4:compile
[INFO] | | +- org.apache.maven:maven-artifact:jar:2.0:compile
[INFO] | | +- org.apache.maven:maven-model:jar:2.0:compile
[INFO] | | +- org.apache.maven:maven-project:jar:2.0:compile
[INFO] | | | +- org.apache.maven:maven-profile:jar:2.0:compile
[INFO] | | | +- org.apache.maven:maven-artifact-manager:jar:2.0:compile
[INFO] | | | | +- org.apache.maven:maven-repository-metadata:jar:2.0:compile
[INFO] | | | | \- org.apache.maven.wagon:wagon-provider-api:jar:1.0-alpha-5:compile
[INFO] | | | \- org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-8:compile
[INFO] | | | \- classworlds:classworlds:jar:1.1-alpha-2:compile
[INFO] | | +- org.codehaus.plexus:plexus-archiver:jar:1.0-alpha-11:compile
[INFO] | | | +- org.codehaus.plexus:plexus-component-api:jar:1.0-alpha-15:compile
[INFO] | | | \- org.codehaus.plexus:plexus-io:jar:1.0-alpha-3:compile
[INFO] | | +- org.codehaus.plexus:plexus-utils:jar:1.4.9:compile
[INFO] | | \- org.codehaus.plexus:plexus-interpolation:jar:1.6:compile
[INFO] | \- org.apache.maven:maven-plugin-api:jar:3.8.6:compile
[INFO] | +- org.eclipse.sisu:org.eclipse.sisu.plexus:jar:0.3.5:compile
[INFO] | | +- javax.annotation:javax.annotation-api:jar:1.2:compile
[INFO] | | +- org.eclipse.sisu:org.eclipse.sisu.inject:jar:0.3.5:compile
[INFO] | | \- org.codehaus.plexus:plexus-component-annotations:jar:1.5.5:compile
[INFO] | \- org.codehaus.plexus:plexus-classworlds:jar:2.6.0:compile
[INFO] +- org.projectlombok:lombok:jar:1.18.22:compile
[INFO] +- javax.validation:validation-api:jar:2.0.1.Final:compile
[INFO] +- org.springframework.cloud:spring-cloud-starter-oauth2:jar:2.2.5.RELEASE:compile
[INFO] | +- org.springframework.cloud:spring-cloud-starter-security:jar:2.2.5.RELEASE:compile
[INFO] | | \- org.springframework.cloud:spring-cloud-security:jar:2.2.5.RELEASE:compile
[INFO] | | \- org.springframework.boot:spring-boot-starter-security:jar:3.0.2:compile
[INFO] | +- org.springframework.security.oauth.boot:spring-security-oauth2-autoconfigure:jar:2.1.2.RELEASE:compile
[INFO] | | +- org.springframework.security.oauth:spring-security-oauth2:jar:2.3.4.RELEASE:compile
[INFO] | | | +- org.springframework.security:spring-security-core:jar:6.0.1:compile
[INFO] | | | +- org.springframework.security:spring-security-config:jar:6.0.1:compile
[INFO] | | | +- org.springframework.security:spring-security-web:jar:6.0.1:compile
[INFO] | | | \- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13:compile
[INFO] | | | \- org.codehaus.jackson:jackson-core-asl:jar:1.9.13:compile
[INFO] | | \- org.springframework.security:spring-security-jwt:jar:1.0.9.RELEASE:compile
[INFO] | | \- org.bouncycastle:bcpkix-jdk15on:jar:1.56:compile
[INFO] | | \- org.bouncycastle:bcprov-jdk15on:jar:1.56:compile
[INFO] | \- javax.activation:javax.activation-api:jar:1.2.0:compile
[INFO] +- org.glassfish.jaxb:jaxb-runtime:jar:2.3.2:compile
[INFO] | +- jakarta.xml.bind:jakarta.xml.bind-api:jar:4.0.0:compile
[INFO] | +- org.glassfish.jaxb:txw2:jar:4.0.1:compile
[INFO] | +- com.sun.istack:istack-commons-runtime:jar:4.1.1:compile
[INFO] | +- org.jvnet.staxex:stax-ex:jar:2.1.0:compile
[INFO] | +- com.sun.xml.fastinfoset:FastInfoset:jar:2.1.0:compile
[INFO] | \- jakarta.activation:jakarta.activation-api:jar:2.1.1:compile
[INFO] +- com.sun.xml.bind:jaxb-core:jar:3.0.2:compile
[INFO] | \- com.sun.activation:jakarta.activation:jar:2.0.1:compile
[INFO] +- com.sun.xml.bind:jaxb-impl:jar:2.3.0:compile
[INFO] +- javax.xml.bind:jaxb-api:jar:2.4.0-b180830.0359:compile
[INFO] +- com.fasterxml.jackson.dataformat:jackson-dataformat-xml:jar:2.13.0:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-core:jar:2.14.1:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.14.1:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-databind:jar:2.14.1:compile
[INFO] | +- org.codehaus.woodstox:stax2-api:jar:4.2.1:compile
[INFO] | \- com.fasterxml.woodstox:woodstox-core:jar:6.2.6:compile
[INFO] +- net.sourceforge.jtds:jtds:jar:1.3.1:compile
[INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:3.0.2:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-aop:jar:3.0.2:compile
[INFO] | | \- org.aspectj:aspectjweaver:jar:1.9.19:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-jdbc:jar:3.0.2:compile
[INFO] | | +- com.zaxxer:HikariCP:jar:5.0.1:compile
[INFO] | | \- org.springframework:spring-jdbc:jar:6.0.4:compile
[INFO] | +- org.hibernate.orm:hibernate-core:jar:6.1.6.Final:compile
[INFO] | | +- jakarta.persistence:jakarta.persistence-api:jar:3.1.0:compile
[INFO] | | +- jakarta.transaction:jakarta.transaction-api:jar:2.0.1:compile
[INFO] | | +- org.jboss.logging:jboss-logging:jar:3.5.0.Final:runtime
[INFO] | | +- org.hibernate.common:hibernate-commons-annotations:jar:6.0.2.Final:runtime
[INFO] | | +- org.jboss:jandex:jar:2.4.2.Final:runtime
[INFO] | | +- com.fasterxml:classmate:jar:1.5.1:runtime
[INFO] | | +- net.bytebuddy:byte-buddy:jar:1.12.22:runtime
[INFO] | | +- jakarta.inject:jakarta.inject-api:jar:2.0.0:runtime
[INFO] | | \- org.antlr:antlr4-runtime:jar:4.10.1:runtime
[INFO] | +- org.springframework.data:spring-data-jpa:jar:3.0.1:compile
[INFO] | | \- org.springframework:spring-orm:jar:6.0.4:compile
[INFO] | \- org.springframework:spring-aspects:jar:6.0.4:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:3.0.2:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-json:jar:3.0.2:compile
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.14.1:compile
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.14.1:compile
[INFO] | | \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.14.1:compile
[INFO] | +- org.springframework:spring-web:jar:6.0.4:compile
[INFO] | \- org.springframework:spring-webmvc:jar:6.0.4:compile
[INFO] | \- org.springframework:spring-expression:jar:6.0.4:compile
[INFO] +- org.apache.logging.log4j:log4j-core:jar:2.18.0:compile
[INFO] +- org.apache.logging.log4j:log4j-api:jar:2.18.0:compile
[INFO] +- org.apache.logging.log4j:log4j-jul:jar:2.18.0:compile
[INFO] +- org.apache.logging.log4j:log4j-slf4j-impl:jar:2.18.0:compile
[INFO] +- org.springframework.boot:spring-boot-starter-log4j2:jar:2.6.3:compile
[INFO] | \- org.slf4j:jul-to-slf4j:jar:2.0.6:compile
[INFO] +- org.springframework.boot:spring-boot-starter-jetty:jar:3.0.2:compile
[INFO] | +- jakarta.servlet:jakarta.servlet-api:jar:6.0.0:compile
[INFO] | +- jakarta.websocket:jakarta.websocket-api:jar:2.1.0:compile
[INFO] | +- jakarta.websocket:jakarta.websocket-client-api:jar:2.1.0:compile
[INFO] | +- org.apache.tomcat.embed:tomcat-embed-el:jar:10.1.5:compile
[INFO] | +- org.eclipse.jetty:jetty-servlets:jar:11.0.13:compile
[INFO] | | +- org.eclipse.jetty:jetty-http:jar:11.0.13:compile
[INFO] | | +- org.eclipse.jetty:jetty-util:jar:11.0.13:compile
[INFO] | | \- org.eclipse.jetty:jetty-io:jar:11.0.13:compile
[INFO] | +- org.eclipse.jetty:jetty-webapp:jar:11.0.13:compile
[INFO] | | +- org.eclipse.jetty:jetty-servlet:jar:11.0.13:compile
[INFO] | | | \- org.eclipse.jetty:jetty-security:jar:11.0.13:compile
[INFO] | | | \- org.eclipse.jetty:jetty-server:jar:11.0.13:compile
[INFO] | | \- org.eclipse.jetty:jetty-xml:jar:11.0.13:compile
[INFO] | +- org.eclipse.jetty.websocket:websocket-jakarta-server:jar:11.0.13:compile
[INFO] | | +- org.eclipse.jetty.websocket:websocket-jakarta-client:jar:11.0.13:compile
[INFO] | | | +- org.eclipse.jetty.websocket:websocket-jakarta-common:jar:11.0.13:compile
[INFO] | | | +- org.eclipse.jetty.websocket:websocket-core-client:jar:11.0.13:compile
[INFO] | | | \- org.eclipse.jetty:jetty-client:jar:11.0.13:compile
[INFO] | | | \- org.eclipse.jetty:jetty-alpn-client:jar:11.0.13:compile
[INFO] | | +- org.eclipse.jetty.websocket:websocket-servlet:jar:11.0.13:compile
[INFO] | | | \- org.eclipse.jetty.websocket:websocket-core-server:jar:11.0.13:compile
[INFO] | | \- org.eclipse.jetty:jetty-annotations:jar:11.0.13:compile
[INFO] | | +- org.eclipse.jetty:jetty-plus:jar:11.0.13:compile
[INFO] | | | \- org.eclipse.jetty:jetty-jndi:jar:11.0.13:compile
[INFO] | | +- org.ow2.asm:asm:jar:9.4:compile
[INFO] | | \- org.ow2.asm:asm-commons:jar:9.4:compile
[INFO] | | \- org.ow2.asm:asm-tree:jar:9.4:compile
[INFO] | \- org.eclipse.jetty.websocket:websocket-jetty-server:jar:11.0.13:compile
[INFO] | +- org.eclipse.jetty.websocket:websocket-jetty-api:jar:11.0.13:compile
[INFO] | \- org.eclipse.jetty.websocket:websocket-jetty-common:jar:11.0.13:compile
[INFO] | \- org.eclipse.jetty.websocket:websocket-core-common:jar:11.0.13:compile
[INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:3.0.2:compile
[INFO] | +- org.springframework.boot:spring-boot-actuator-autoconfigure:jar:3.0.2:compile
[INFO] | | \- org.springframework.boot:spring-boot-actuator:jar:3.0.2:compile
[INFO] | \- io.micrometer:micrometer-observation:jar:1.10.3:compile
[INFO] | \- io.micrometer:micrometer-commons:jar:1.10.3:compile
[INFO] +- org.springframework.cloud:spring-cloud-starter-netflix-eureka-client:jar:3.1.0:compile
[INFO] | +- org.springframework.cloud:spring-cloud-starter:jar:3.1.0:compile
[INFO] | | +- org.springframework.cloud:spring-cloud-context:jar:3.1.0:compile
[INFO] | | | \- org.springframework.security:spring-security-crypto:jar:6.0.1:compile
[INFO] | | +- org.springframework.cloud:spring-cloud-commons:jar:3.1.0:compile
[INFO] | | \- org.springframework.security:spring-security-rsa:jar:1.0.10.RELEASE:compile
[INFO] | +- org.springframework.cloud:spring-cloud-netflix-eureka-client:jar:3.1.0:compile
[INFO] | +- com.netflix.eureka:eureka-client:jar:1.10.17:compile
[INFO] | | +- com.netflix.netflix-commons:netflix-eventbus:jar:0.3.0:compile
[INFO] | | | +- com.netflix.netflix-commons:netflix-infix:jar:0.3.0:runtime
[INFO] | | | | +- commons-jxpath:commons-jxpath:jar:1.3:runtime
[INFO] | | | | +- joda-time:joda-time:jar:2.3:runtime
[INFO] | | | | +- org.antlr:antlr-runtime:jar:3.4:runtime
[INFO] | | | | | +- org.antlr:stringtemplate:jar:3.2.1:runtime
[INFO] | | | | | \- antlr:antlr:jar:2.7.7:runtime
[INFO] | | | | \- com.google.code.gson:gson:jar:2.9.1:runtime
[INFO] | | | \- org.apache.commons:commons-math:jar:2.2:runtime
[INFO] | | +- com.thoughtworks.xstream:xstream:jar:1.4.18:compile
[INFO] | | | \- io.github.x-stream:mxparser:jar:1.2.2:compile
[INFO] | | | \- xmlpull:xmlpull:jar:1.1.3.1:compile
[INFO] | | +- javax.ws.rs:jsr311-api:jar:1.1.1:compile
[INFO] | | +- com.netflix.servo:servo-core:jar:0.12.21:compile
[INFO] | | | \- com.google.guava:guava:jar:19.0:compile
[INFO] | | +- commons-configuration:commons-configuration:jar:1.10:compile
[INFO] | | | \- commons-lang:commons-lang:jar:2.6:compile
[INFO] | | +- com.google.inject:guice:jar:4.1.0:compile
[INFO] | | | \- javax.inject:javax.inject:jar:1:compile
[INFO] | | \- org.codehaus.jettison:jettison:jar:1.4.0:runtime
[INFO] | +- com.netflix.eureka:eureka-core:jar:1.10.17:compile
[INFO] | \- org.springframework.cloud:spring-cloud-starter-loadbalancer:jar:3.1.0:compile
[INFO] | +- org.springframework.cloud:spring-cloud-loadbalancer:jar:3.1.0:compile
[INFO] | | +- io.projectreactor:reactor-core:jar:3.5.2:compile
[INFO] | | | \- org.reactivestreams:reactive-streams:jar:1.0.4:compile
[INFO] | | \- io.projectreactor.addons:reactor-extra:jar:3.5.0:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-cache:jar:3.0.2:compile
[INFO] | \- com.stoyanr:evictor:jar:1.0.0:compile
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:3.0.2:test
[INFO] | +- org.springframework.boot:spring-boot-test-autoconfigure:jar:3.0.2:test
[INFO] | +- com.jayway.jsonpath:json-path:jar:2.7.0:compile
[INFO] | | \- net.minidev:json-smart:jar:2.4.8:compile
[INFO] | | \- net.minidev:accessors-smart:jar:2.4.8:compile
[INFO] | +- org.assertj:assertj-core:jar:3.23.1:test
[INFO] | +- org.hamcrest:hamcrest:jar:2.2:test
[INFO] | +- org.junit.jupiter:junit-jupiter:jar:5.9.2:test
[INFO] | | +- org.junit.jupiter:junit-jupiter-api:jar:5.9.2:test
[INFO] | | | +- org.opentest4j:opentest4j:jar:1.2.0:test
[INFO] | | | +- org.junit.platform:junit-platform-commons:jar:1.9.2:test
[INFO] | | | \- org.apiguardian:apiguardian-api:jar:1.1.2:test
[INFO] | | +- org.junit.jupiter:junit-jupiter-params:jar:5.9.2:test
[INFO] | | \- org.junit.jupiter:junit-jupiter-engine:jar:5.9.2:test
[INFO] | | \- org.junit.platform:junit-platform-engine:jar:1.9.2:test
[INFO] | +- org.mockito:mockito-core:jar:4.8.1:test
[INFO] | | +- net.bytebuddy:byte-buddy-agent:jar:1.12.22:test
[INFO] | | \- org.objenesis:objenesis:jar:3.2:test
[INFO] | +- org.mockito:mockito-junit-jupiter:jar:4.8.1:test
[INFO] | +- org.skyscreamer:jsonassert:jar:1.5.1:test
[INFO] | | \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
[INFO] | +- org.springframework:spring-test:jar:6.0.4:test
[INFO] | \- org.xmlunit:xmlunit-core:jar:2.9.1:test
[INFO] +- org.springframework.boot:spring-boot-test:jar:3.0.2:compile
[INFO] +- junit:junit:jar:4.13.1:test
[INFO] | \- org.hamcrest:hamcrest-core:jar:2.2:test
[INFO] +- io.micrometer:micrometer-core:jar:1.8.1:compile
[INFO] | +- org.hdrhistogram:HdrHistogram:jar:2.1.12:compile
[INFO] | \- org.latencyutils:LatencyUtils:jar:2.0.3:runtime
[INFO] \- io.micrometer:micrometer-registry-prometheus:jar:1.8.0:compile
[INFO] \- io.prometheus:simpleclient_common:jar:0.16.0:compile
[INFO] \- io.prometheus:simpleclient:jar:0.16.0:compile
[INFO] +- io.prometheus:simpleclient_tracer_otel:jar:0.16.0:compile
[INFO] | \- io.prometheus:simpleclient_tracer_common:jar:0.16.0:compile
[INFO] \- io.prometheus:simpleclient_tracer_otel_agent:jar:0.16.0:compile
[INFO]
Does anyone know which versions of the dependencies are compatible with each other?
I would hazard a guess this is because you have a property defined like so in your original project:
<log4j2.version>2.18.0</log4j2.version>
This is a very normal (and important!) thing to see with Spring Boot 2.x projects because of log4shell - by default Spring Boot 2.6.1 depends on a vulnerable version, so there must be some kind of property like this in the original pom that's bringing it up to 2.18.
Spring Boot 3.0.2 depends on log4j 2.19 which isn't vulnerable, so once again, you must have a property explicitly setting it to 2.18 for this to be an issue. Such a property isn't needed (and as you've found, is a regression that makes it incompatible anyway.)
Delete that explicit log4j2.version property, clean and rebuild, and you should be fine.
Does anyone know which versions of the dependencies are compatible with each other?
Spring-boot does. Stop forcing versions of dependencies managed by boot and you'll stop having incompatibility issues.
Also, you are changing a major version => expect breaking changes and modifications in your code.
Maybe should you refer to migration guide?
Apparently, there is some kind of incompatibility with the log4j version so I had to force it to use version 2.19.0. With that, it worked.
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.19.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.19.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jul</artifactId>
<version>2.19.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.19.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-log4j2</artifactId>
<version>3.0.2</version>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jul</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</exclusion>
</exclusions>
</dependency>
I have an Azure VM that I need to remotely control. I'm authenticating using ApplicationTokenCredentials in the expected way;
ApplicationTokenCredentials credentials = new ApplicationTokenCredentials(client,
tenant,
key,
AzureEnvironment.AZURE);
Then finding my machine:
VirtualMachine vm = Azure
.configure()
.withLogLevel(LogLevel.NONE)
.authenticate(credentials)
.withSubscription(subscription)
.virtualMachines()
.getByResourceGroup(resourceGroup, machineName);
This is essentially the same approach as the official documentation here shows;
https://learn.microsoft.com/en-us/azure/developer/java/sdk/java-sdk-manage-virtual-machines?view=azure-java-stable
This works, authenticates, and sets me up with a VirtualMachine object. I've confirmed that that's what it is and that it's the correct machine that I'm looking to control.
However when I try to start it with the start() method, this happens:
Evaluation error (NoSuchMethodError) at com.microsoft.azure.credentials.ApplicationTokenCredentials.getToken (ApplicationTokenCredentials.java:138).
My dependency tree looks fine. I'm using the newest version (1.35.0) of com.microsoft.azure (and only that) from maven central;
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure</artifactId>
<version>1.35.0</version>
</dependency>
Of course this is the parent dependency and it pulls down a bunch of artifacts. My dependency tree seems fine at a glance though:
+- com.microsoft.azure:azure:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-client-runtime:jar:1.7.0:compile
[INFO] | | \- com.microsoft.rest:client-runtime:jar:1.7.0:compile
[INFO] | | +- com.squareup.retrofit2:retrofit:jar:2.5.0:compile
[INFO] | | +- com.squareup.okhttp3:okhttp:jar:3.12.6:compile
[INFO] | | | \- com.squareup.okio:okio:jar:1.15.0:compile
[INFO] | | +- com.squareup.okhttp3:logging-
interceptor:jar:3.12.2:compile
[INFO] | | +- com.squareup.okhttp3:okhttp-
urlconnection:jar:3.12.2:compile
[INFO] | | +- com.squareup.retrofit2:converter-
jackson:jar:2.5.0:compile
[INFO] | | | \- com.fasterxml.jackson.core:jackson-
databind:jar:2.9.4:compile
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-
joda:jar:2.10.0:compile
[INFO] | | | \- com.fasterxml.jackson.core:jackson-
annotations:jar:2.10.0:compile
[INFO] | | \- com.squareup.retrofit2:adapter-rxjava:jar:2.6.2:compile
[INFO] | +- com.microsoft.azure:azure-client-
authentication:jar:1.7.0:compile
[INFO] | | \- com.microsoft.azure:azure-annotations:jar:1.10.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-resources:jar:1.35.0:compile
[INFO] | | \- io.reactivex:rxjava:jar:1.3.8:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-storage:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-network:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-graph-rbac:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-keyvault:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-batch:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-
trafficmanager:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-dns:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-redis:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-appservice:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-locks:jar:1.35.0:compile
[INFO] | +- javax.xml.bind:jaxb-api:jar:2.3.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-eventhub:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-cdn:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-sql:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-
containerinstance:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-
containerregistry:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-
containerservice:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-cosmosdb:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-search:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-msi:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-monitor:jar:1.35.0:compile
[INFO] | +- com.microsoft.azure:azure-mgmt-servicebus:jar:1.35.0:compile
[INFO] | \- com.microsoft.azure:azure-mgmt-batchai:jar:1.35.0:compile
[INFO] +- com.microsoft.azure:azure-mgmt-compute:jar:1.35.0:compile
[INFO] | \- com.google.code.gson:gson:jar:2.2.4:compile
At least I don't see anything that stands out as dependency conflict here. I really have no idea how to proceed here.
I ended up setting up a test project with just the VM management and found that working on the same dependencies.
After painstakingly comparing the dependencies between the two, I found one discrepancy; the version of the com.microsoft.azure.adal4j package was 1.6.4 on my test project, and 1.0.0 on my production app.
I have no idea how my production app ended up with an older version of this since all the root azure dependencies are identical, but I added this dependency to my production app, which fixed the issue:
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>adal4j</artifactId>
<version>1.6.4</version>
</dependency>
I have been struggling with this error for two days now. I am in a spring, maven project, using Intellij.
I have tried every question I found here in SO and nothing. I have tried with a bunch of versions and nothing.
I am completely stuck by the following exception:
java.lang.NoSuchMethodError: javassist.CtClass.getDeclaredClasses()[Ljavassist/CtClass;
at org.powermock.core.transformers.javassist.ConstructorsMockTransformer.transform(ConstructorsMockTransformer.java:50)
at org.powermock.core.transformers.javassist.AbstractJavaAssistMockTransformer.transform(AbstractJavaAssistMockTransformer.java:40)
at org.powermock.core.transformers.support.DefaultMockTransformerChain.transform(DefaultMockTransformerChain.java:43)
at org.powermock.core.classloader.MockClassLoader.transformClass(MockClassLoader.java:184)
at org.powermock.core.classloader.javassist.JavassistMockClassLoader.defineAndTransformClass(JavassistMockClassLoader.java:102)
at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:174)
at org.powermock.core.classloader.MockClassLoader.loadClassByThisClassLoader(MockClassLoader.java:102)
at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass1(DeferSupportingClassLoader.java:147)
at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:98)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:154)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:47)
at org.powermock.tests.utils.impl.AbstractTestSuiteChunkerImpl.createTestDelegators(AbstractTestSuiteChunkerImpl.java:107)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.<init>(JUnit4TestSuiteChunkerImpl.java:69)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.<init>(AbstractCommonPowerMockRunner.java:36)
at org.powermock.modules.junit4.PowerMockRunner.<init>(PowerMockRunner.java:34)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.junit.internal.builders.AnnotatedBuilder.buildRunner(AnnotatedBuilder.java:104)
at org.junit.internal.builders.AnnotatedBuilder.runnerForClass(AnnotatedBuilder.java:86)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.builders.AllDefaultPossibilitiesBuilder.runnerForClass(AllDefaultPossibilitiesBuilder.java:26)
at org.junit.runners.model.RunnerBuilder.safeRunnerForClass(RunnerBuilder.java:59)
at org.junit.internal.requests.ClassRequest.getRunner(ClassRequest.java:33)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:49)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Here is my code:
test
package com.secondrain.utils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
#RunWith(PowerMockRunner.class)
#PrepareForTest(CompanyManager.class)
public class CompanyTest {
#Test
public void test() {}
}
Everything works perfectly if I remove PowerMock:
package com.secondrain.utils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.BlockJUnit4ClassRunner;
#RunWith(BlockJUnit4ClassRunner.class)
public class CompanyTest {
#Test
public void test() {}
}
PowerMock dependencies
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-core</artifactId>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<version>2.0.2</version>
<scope>test</scope>
</dependency>
Dependency tree
[INFO] ------------------------------------------------------------------------
[INFO] Building Workbench 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # Workbench ---
[INFO] com.secondrain:Workbench:jar:1.0.0
[INFO] +- thirdparty.secondrain:Objects:jar:jdk6:1.1:compile
[INFO] | +- thirdparty.secondrain:fr-common-db:jar:jdk6:1.0:compile
[INFO] | | +- thirdparty.secondrain:fr-common-utils:jar:jdk6:1.1:compile
[INFO] | | | +- commons-digester:commons-digester:jar:1.8.1:compile
[INFO] | | | +- thirdparty.xml-apis:xml-apis:jar:0:compile
[INFO] | | | +- thirdparty:lingpipe:jar:3.1.1:compile
[INFO] | | | +- thirdparty.activation:activation:jar:1.1.1:compile
[INFO] | | | +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] | | | +- opensymphony:quartz:jar:1.5.0:compile
[INFO] | | | +- isorelax:isorelax:jar:20030108:compile
[INFO] | | | +- thirdparty.javamail:mail:jar:1.3.1:compile
[INFO] | | | +- com.google.guava:guava:jar:14.0.1:compile
[INFO] | | | +- commons-io:commons-io:jar:2.1:compile
[INFO] | | | +- thirdparty:jce:jar:1.2.2:compile
[INFO] | | | +- thirdparty:sunjce_provider-cv:jar:1.0:compile
[INFO] | | | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.5.1:compile
[INFO] | | | +- com.fasterxml.jackson.core:jackson-core:jar:2.5.1:compile
[INFO] | | | \- com.fasterxml.jackson.core:jackson-databind:jar:2.5.1:compile
[INFO] | | +- thirdparty.secondrain:replication:jar:1.0:compile
[INFO] | | +- relaxngDatatype:relaxngDatatype:jar:20020414:compile
[INFO] | | +- xsdlib:xsdlib:jar:20030225:compile
[INFO] | | +- msv:msv:jar:20030225:compile
[INFO] | | +- commons-dbutils:commons-dbutils:jar:1.0:compile
[INFO] | | +- commons-dbcp:commons-dbcp:jar:1.2.2:compile
[INFO] | | +- org.hibernate:hibernate-entitymanager:jar:3.4.0.GA:compile
[INFO] | | | +- org.hibernate:hibernate-commons-annotations:jar:3.1.0.GA:compile
[INFO] | | | +- org.hibernate:hibernate-annotations:jar:3.4.0.GA:compile
[INFO] | | | +- dom4j:dom4j:jar:1.6.1:compile
[INFO] | | | \- javax.transaction:jta:jar:1.1:compile
[INFO] | | +- org.hibernate:hibernate-core:jar:3.3.1.GA:compile
[INFO] | | | \- antlr:antlr:jar:2.7.6:compile
[INFO] | | +- org.hibernate:hibernate-jmx:jar:3.3.1.GA:compile
[INFO] | | +- org.hibernate:hibernate-cglib-repack:jar:2.1_3:compile
[INFO] | | +- org.hibernate:hibernate-c3p0:jar:3.3.1.GA:compile
[INFO] | | | \- c3p0:c3p0:jar:0.9.1:compile
[INFO] | | +- org.slf4j:slf4j-api:jar:1.6.6:compile
[INFO] | | +- org.slf4j:slf4j-log4j12:jar:1.6.6:compile
[INFO] | | \- commons-pool:commons-pool:jar:1.6:compile
[INFO] | +- commons-lang:commons-lang:jar:2.6:compile
[INFO] | +- org.apache.xmlbeans:xmlbeans:jar:2.3.0:compile
[INFO] | +- poi:poi:jar:3.6-20091214:compile
[INFO] | +- poi:poi-ooxml:jar:3.6-20091214:compile
[INFO] | +- poi:poi-ooxml-schemas:jar:3.6-20091214:compile
[INFO] | \- commons-httpclient:commons-httpclient:jar:3.0.1:compile
[INFO] | \- commons-codec:commons-codec:jar:1.2:compile
[INFO] +- com.secondrain:Extraction:jar:1.0.0:compile
[INFO] | +- com.secondrain:ContentProducers:jar:1.0.0:compile
[INFO] | | \- javax.xml.stream:stax-api:jar:1.0-2:compile
[INFO] | +- thirdparty.secondrain:ImageServiceClient:jar:jdk6:1.0:compile
[INFO] | | +- thirdparty.secondrain:HtmlParser:jar:jdk6:1.0:compile
[INFO] | | | +- org.ccil.cowan.tagsoup:tagsoup:jar:1.2:compile
[INFO] | | | \- thirdparty.tika-app:tika-app-1.4Custom:jar:0:compile
[INFO] | | +- com.sun.jersey:jersey-client:jar:1.0.2:compile
[INFO] | | +- com.sun.jersey:jersey-core:jar:1.0.2:compile
[INFO] | | \- javax.ws.rs:jsr311-api:jar:1.0:compile
[INFO] | +- commons-beanutils:commons-beanutils:jar:1.8.0:compile
[INFO] | +- com.google.code.gson:gson:jar:2.2.4:compile
[INFO] | +- thirdparty.solr.commons:commons-csv:jar:1.0-SNAPSHOT-r609327:compile
[INFO] | +- thirdparty.jcommon:jcommon:jar:1.0.13:compile
[INFO] | +- thirdparty.lang:jsonic:jar:1.2.4:compile
[INFO] | +- org.rhq.helpers:rhq-pluginAnnotations:jar:3.0.4:compile
[INFO] | +- thirdparty.xalan:xalan:jar:2.5.2:compile
[INFO] | +- thirdparty.lang:langdetect:jar:0:compile
[INFO] | +- thirdparty.stanford-corenlp:stanford-corenlp:jar:3.3.1:compile
[INFO] | +- thirdparty.stanford-corenlpmodel:stanford-corenlpmodel:jar:models:0:compile
[INFO] | +- org.jsoup:jsoup:jar:1.8.1:compile
[INFO] | \- net.openhft:chronicle-map:jar:3.9.0:compile
[INFO] | +- net.openhft:chronicle-core:jar:1.6.2:compile
[INFO] | +- net.openhft:chronicle-values:jar:1.5.1:compile
[INFO] | | +- com.sun.java:tools:jar:1.8.0_231:system
[INFO] | | \- com.squareup:javapoet:jar:1.5.1:compile
[INFO] | +- net.openhft:chronicle-threads:jar:1.6.1:compile
[INFO] | | \- net.openhft:affinity:jar:3.0.5:compile
[INFO] | +- com.intellij:annotations:jar:12.0:compile
[INFO] | +- net.openhft:chronicle-wire:jar:1.6.2:compile
[INFO] | +- net.openhft:chronicle-bytes:jar:1.6.1:compile
[INFO] | +- net.openhft:chronicle-algorithms:jar:1.1.7:compile
[INFO] | +- net.java.dev.jna:jna:jar:4.2.1:compile
[INFO] | +- net.java.dev.jna:jna-platform:jar:4.2.1:compile
[INFO] | +- com.thoughtworks.xstream:xstream:jar:1.4.8:compile
[INFO] | | +- xmlpull:xmlpull:jar:1.1.3.1:compile
[INFO] | | \- xpp3:xpp3_min:jar:1.1.4c:compile
[INFO] | +- org.codehaus.jettison:jettison:jar:1.3.7:compile
[INFO] | | \- stax:stax-api:jar:1.0.1:compile
[INFO] | \- org.ops4j.pax.url:pax-url-aether:jar:2.4.5:compile
[INFO] | \- org.slf4j:jcl-over-slf4j:jar:1.6.6:compile
[INFO] +- com.secondrain:Tools:jar:1.0.0:compile
[INFO] | +- thirdparty.secondrain:ContentProcessingFramework:jar:jdk6:1.0:compile
[INFO] | | +- displaytag:displaytag-export-poi:jar:1.1:compile
[INFO] | | +- org.jboss:jboss-common-core:jar:2.2.13.GA:compile
[INFO] | | +- org.jboss.logging:jboss-logging-spi:jar:2.0.5.GA:compile
[INFO] | | +- org.jboss:staxmapper:jar:1.1.0.Final:compile
[INFO] | | +- org.infinispan:infinispan-core:jar:6.0.0.Final:compile
[INFO] | | | +- org.infinispan:infinispan-commons:jar:6.0.0.Final:compile
[INFO] | | | +- org.jgroups:jgroups:jar:3.4.1.Final:compile
[INFO] | | | +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:jar:1.0.1.Final:compile
[INFO] | | | +- org.jboss.marshalling:jboss-marshalling-river:jar:1.3.18.GA:compile
[INFO] | | | +- org.jboss.marshalling:jboss-marshalling:jar:1.3.18.GA:compile
[INFO] | | | \- org.jboss.logging:jboss-logging:jar:3.1.2.GA:compile
[INFO] | | \- displaytag:displaytag:jar:1.1:compile
[INFO] | | \- com.lowagie:itext:jar:1.3:compile
[INFO] | +- thirdparty.secondrain:FrameworkCommonUtils:jar:jdk6:1.0:compile
[INFO] | | +- thirdparty.fr-search.frdoc:frdoc:jar:Provided:compile
[INFO] | | +- thirdparty.fastutil:fastutil:jar:5.1.5:compile
[INFO] | | +- thirdparty.wordnet:jaws-bin:jar:1.0:compile
[INFO] | | +- com.googlecode.matrix-toolkits-java:mtj:jar:0.9.14:compile
[INFO] | | | \- com.googlecode.netlib-java:netlib-java:jar:0.9.3:compile
[INFO] | | | \- net.sourceforge.f2j:arpack_combined_all:jar:0.1:compile
[INFO] | | +- org.mapdb:mapdb:jar:1.0.7:compile
[INFO] | | \- org.apache.httpcomponents:httpclient:jar:4.4:compile
[INFO] | | \- org.apache.httpcomponents:httpcore:jar:4.4:compile
[INFO] | +- thirdparty.secondrain:FRSolrExtension:jar:jdk6:1.2:compile
[INFO] | | +- thirdparty.secondrain:FRSharedAPIServlet:jar:jdk6:1.0:compile
[INFO] | | +- net.sf.json-lib:json-lib:jar:jdk15:2.2.3:compile
[INFO] | | +- thirdparty.secondrain.solr:solr-solrj:jar:1.4.1:compile
[INFO] | | | +- commons-fileupload:commons-fileupload:jar:1.2:compile
[INFO] | | | +- org.apache.lucene:lucene-core:jar:2.9.3:compile
[INFO] | | | +- org.codehaus.woodstox:wstx-asl:jar:3.2.7:compile
[INFO] | | | \- org.apache.geronimo.specs:geronimo-stax-api_1.0_spec:jar:1.0.1:compile
[INFO] | | +- org.codehaus.jackson:jackson-core-lgpl:jar:1.5.3:compile
[INFO] | | \- org.codehaus.jackson:jackson-mapper-lgpl:jar:1.5.3:compile
[INFO] | +- thirdparty.secondrain:IndexEngine:jar:1.0.0:compile
[INFO] | | +- thirdparty.fr-search.IEngine.clientSDK.idsdk:fridsdk:jar:1.0:compile
[INFO] | | +- javax.servlet:javax.servlet-api:jar:3.0.1:compile
[INFO] | | +- thirdparty.tanukisoft:wrapper:jar:0:compile
[INFO] | | \- log4j:log4j:jar:1.2.16:compile
[INFO] | +- thirdparty.sqljdbc:sqljdbc:jar:0:compile
[INFO] | \- thirdparty.jxl:jxl:jar:0:compile
[INFO] +- org.springframework:spring-aop:jar:3.0.1.RELEASE:compile
[INFO] | +- aopalliance:aopalliance:jar:1.0:compile
[INFO] | \- org.springframework:spring-asm:jar:3.0.1.RELEASE:compile
[INFO] +- org.springframework:spring-beans:jar:3.0.1.RELEASE:compile
[INFO] +- org.springframework:spring-context:jar:3.0.1.RELEASE:compile
[INFO] +- org.springframework:spring-context-support:jar:3.0.1.RELEASE:compile
[INFO] +- org.springframework:spring-core:jar:3.0.1.RELEASE:compile
[INFO] | \- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] +- org.springframework:spring-expression:jar:3.0.1.RELEASE:compile
[INFO] +- org.springframework:spring-web:jar:3.0.1.RELEASE:compile
[INFO] +- org.springframework:spring-webmvc:jar:3.0.1.RELEASE:compile
[INFO] +- net.sf.ezmorph:ezmorph:jar:1.0.6:compile
[INFO] +- struts:struts:jar:1.2.4:compile
[INFO] +- thirdparty.jwnl:jwnl:jar:0:compile
[INFO] +- commons-net:commons-net:jar:1.2.1:compile
[INFO] | \- oro:oro:jar:2.0.8:compile
[INFO] +- xmlunit:xmlunit:jar:1.0:compile
[INFO] +- backport-util-concurrent:backport-util-concurrent:jar:3.0:compile
[INFO] +- thirdparty.secondrain:frDB:jar:jdk6:1.0:compile
[INFO] | \- org.hibernate:ejb3-persistence:jar:1.0.2.GA:compile
[INFO] +- javax.servlet:jstl:jar:1.1.2:compile
[INFO] +- taglibs:standard:jar:1.1.2:compile
[INFO] +- thirdparty.secondrain:frDocMgr:jar:1.0:compile
[INFO] | \- thirdparty.secondrain:frMessageService:jar:1.0.0:compile
[INFO] | \- thirdparty.secondrain:Jamsel:jar:1.0.0:compile
[INFO] +- thirdparty.secondrain:EntityDomainModel:jar:jdk6:1.0:compile
[INFO] | \- thirdparty.qazi:qazi:jar:Provided-1.2:compile
[INFO] +- org.powermock:powermock-core:jar:2.0.2:test
[INFO] | +- org.powermock:powermock-reflect:jar:2.0.2:test
[INFO] | | \- org.objenesis:objenesis:jar:3.0.1:test
[INFO] | +- org.javassist:javassist:jar:3.24.0-GA:test
[INFO] | +- net.bytebuddy:byte-buddy:jar:1.9.3:test
[INFO] | \- net.bytebuddy:byte-buddy-agent:jar:1.9.3:test
[INFO] +- org.powermock:powermock-module-junit4:jar:2.0.2:test
[INFO] | +- org.powermock:powermock-module-junit4-common:jar:2.0.2:test
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- org.powermock:powermock-api-mockito2:jar:2.0.2:test
[INFO] | +- org.powermock:powermock-api-support:jar:2.0.2:test
[INFO] | \- org.mockito:mockito-core:jar:2.23.0:test
[INFO] \- junit:junit:jar:4.12:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.051 s
[INFO] Finished at: 2019-11-23T09:15:59-03:00
[INFO] Final Memory: 18M/309M
[INFO] ------------------------------------------------------------------------
mvn -v
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T13:41:47-03:00)
Maven home: C:\Users\Usuario\apache-maven-3.3.9\bin\..
Java version: 1.8.0_231, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.8.0_231\jre
Default locale: es_ES, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "dos"
java -version
java version "1.8.0_231"
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.231-b11, mixed mode)
First of all, this:
javassist.CtClass.getDeclaredClasses()[Ljavassist/CtClass;
returns to a method in javassist.CtClass that has the signature
<modifier> javassist.CtClass getDeclaredClasses()
According to the published javadocs the "missing" method was added in javassist version 3.15.
So the immediate explanation is that the first JAR file for javassist that the JVM found on the runtime classpath was for an older version.
The Maven dependency tree shows that PowerMock 2.0.2 depends on
org.javassist:javassist:jar:3.24.0-GA
But clearly there was another version of the JAR on the runtime classpath when you were running the tests. Mystery!
You then say that a clean project with the same dependencies doesn't have this problem. At least that makes sense. (To me.)
How to solve this?
There must a copy or copies of older (pre 3.15) javassist JAR files on your machine. Find it or them. For example, on Linux find $HOME -name javassist\* -type f, and then eyeball the pathnames.
Next, try to find out what classpath is being used when you are running the tests.
If you are running them using a maven command, the -X (debug) option will show you a lot of extra information. According to Find classpath maven is using for running testng testcase, this includes the actual classpath.
If you are using a test runner in your IDE, check the IDE documentation.
Finally, analyse the classpath to find why there is an old javassist JAR on the path.
FWIW, my guess would be that you are running the tests in an IDE, and that somehow the IDE is adding the spurious JAR. This could have been a transitive dependency of an old (or upgraded) dependency that wasn't properly cleaned out by the IDE.
I know, it was long time ago, but I found this in a vietnamite forum; this solution excludes the spurious JAR added by the IDE ... it was useful in my case
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
In my project I have a package that uses several 3rd party libraries. Let's have a look at the dependency tree:
[INFO] +- commons-logging:commons-logging:jar:1.2:compile
[INFO] +- org.apache.directory.studio:org.apache.commons.collections:jar:3.2.1:compile
[INFO] | \- commons-collections:commons-collections:jar:3.2.2:compile
[INFO] +- xerces:xercesImpl:jar:2.11.0:compile
[INFO] | \- xml-apis:xml-apis:jar:1.4.01:compile
[INFO] +- org.apache.cxf:cxf-rt-bindings-soap:jar:3.2.2:compile
[INFO] | +- org.apache.cxf:cxf-core:jar:3.2.2:compile
[INFO] | | +- com.fasterxml.woodstox:woodstox-core:jar:5.0.3:compile
[INFO] | | | \- org.codehaus.woodstox:stax2-api:jar:3.1.4:compile
[INFO] | | \- org.apache.ws.xmlschema:xmlschema-core:jar:2.2.3:compile
[INFO] | +- org.apache.cxf:cxf-rt-wsdl:jar:3.2.2:compile
[INFO] | | +- wsdl4j:wsdl4j:jar:1.6.3:compile
[INFO] | | \- org.ow2.asm:asm:jar:5.2:compile
[INFO] | \- org.apache.cxf:cxf-rt-databinding-jaxb:jar:3.2.2:compile
[INFO] +- org.apache.wss4j:wss4j-ws-security-common:jar:2.2.1:compile
[INFO] | +- org.slf4j:slf4j-api:jar:1.7.22:compile
[INFO] | +- org.apache.santuario:xmlsec:jar:2.1.1:compile
[INFO] | | \- commons-codec:commons-codec:jar:1.10:compile
[INFO] | +- org.opensaml:opensaml-saml-impl:jar:3.3.0:compile
[INFO] | | +- org.opensaml:opensaml-profile-api:jar:3.3.0:compile
[INFO] | | | \- org.opensaml:opensaml-core:jar:3.3.0:compile
[INFO] | | | \- io.dropwizard.metrics:metrics-core:jar:3.1.2:compile
[INFO] | | +- org.opensaml:opensaml-saml-api:jar:3.3.0:compile
[INFO] | | | +- org.opensaml:opensaml-xmlsec-api:jar:3.3.0:compile
[INFO] | | | \- org.opensaml:opensaml-soap-api:jar:3.3.0:compile
[INFO] | | +- org.opensaml:opensaml-security-impl:jar:3.3.0:compile
[INFO] | | | \- org.opensaml:opensaml-security-api:jar:3.3.0:compile
[INFO] | | | +- org.cryptacular:cryptacular:jar:1.1.1:compile
[INFO] | | | \- org.bouncycastle:bcprov-jdk15on:jar:1.55:compile
[INFO] | | +- org.opensaml:opensaml-xmlsec-impl:jar:3.3.0:compile
[INFO] | | \- net.shibboleth.utilities:java-support:jar:7.3.0:compile
[INFO] | | +- com.google.guava:guava:jar:19.0:compile
[INFO] | | \- joda-time:joda-time:jar:2.7:compile
[INFO] | +- org.opensaml:opensaml-xacml-impl:jar:3.3.0:compile
[INFO] | | \- org.opensaml:opensaml-xacml-api:jar:3.3.0:compile
[INFO] | +- org.opensaml:opensaml-xacml-saml-impl:jar:3.3.0:compile
[INFO] | | \- org.opensaml:opensaml-xacml-saml-api:jar:3.3.0:compile
[INFO] | +- org.jasypt:jasypt:jar:1.9.2:compile
[INFO] | \- org.apache.geronimo.javamail:geronimo-javamail_1.4_mail:jar:1.8.4:compile
[INFO] +- org.apache.wss4j:wss4j-ws-security-dom:jar:2.2.1:compile
[INFO] | \- net.sf.ehcache:ehcache:jar:2.10.4:runtime
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.7.22:compile
[INFO] +- log4j:log4j:jar:1.2.17:compile
[INFO] \- org.testng:testng:jar:6.11:test
[INFO] +- com.beust:jcommander:jar:1.64:test
[INFO] \- org.yaml:snakeyaml:jar:1.17:test
Compiling and running works fine so far.
But when I what to start debugging with IntelliJ, I get a list of over 100 errors like:
Error:java: the unnamed module reads package org.opensaml.saml.config from both opensaml.saml.api and opensaml.saml.impl
Error:java: the unnamed module reads package javax.xml.datatype from both xml.apis and java.xml
Error:java: the unnamed module reads package javax.xml.transform.dom from both xml.apis and java.xml
....
This seems to be an error due to the new Java 9 module restrictions. But how to deal with here?
Both org.opensaml are part of wss4j-ws-security-common 2.2.1 (this is the last version, released in January 2018). opensaml.saml.api and opensaml.saml.impl are version 3.3.0 and both use org.opensaml.saml.config of the same version. So???
And why does "mvn compile" pass, but debugging with IntelliJ fails?
I had the same 100+ multititude of "ERROR: The unnamed module reads package javax.xml from both xml.apis and java.xml" in my Java 9 IntelliJ project too.
Except I would get them whenever I tried to run unit tests in IntelliJ. Everything worked perfectly building and testing with maven from the command line; just like you.
I was able to make my errors go away by...
1) Removing the following from the top-level pom of a multi-module project...
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.4.01</version>
</dependency>
...
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>${javaee.api.version}</version>
<scope>provided</scope>
</dependency>
2) Right clicking the top-level pom in IntelliJ's project navigator, then select "Maven - Reimport"
3) Doing "Build -> Build module [myModule]" from the IntelliJ menu.
Just work out which maven artifacts contain the packages listed in your 100+"ERROR" messages. Then comment them out. Reimport. Then "Build module" from the menu. That worked for me anyway.
The artifacts I removed from the pom were copy/pasted in there speculatively from another project I used as a template. But luckily I don't need any of them.
This is a known IDEA bug. Please vote for https://youtrack.jetbrains.com/issue/IDEA-171320
I am doing some static mining and I would like to have a list of the involved libraries.
Is there a way to programmatically find the dependencies used by a pom.xml file ?
I can not use the .m2 repo or anything in the like since the code DOES NOT compile.
(In other words, I'd like to recreate the "Efective POM" tab of pom.xml file as shown in Eclipse)
Note that reading the pom file of the current project (test boottstrap) gives a set of dependency when asked for - but not with external pom file.
In code :
[...]
Model model = mavenReader.read(new FileReader(pomFile));
model.setPomFile(pomFile);
proj= new MavenProject(model);
proj.setRemoteArtifactRepositories(
Arrays.asList((ArtifactRepository) new MavenArtifactRepository(
"maven-central",
"http://repo1.maven.org/maven2/",
new DefaultRepositoryLayout(),
new ArtifactRepositoryPolicy(),
new ArtifactRepositoryPolicy())));
List<Dependency> dependencies = proj.getDependencies();
for (Dependency dependency : dependencies) {
System.out.println(dependency);
}
With pomFile = new File("pom.xml") it yelds:
Dependency {groupId=com.github.javaparser, artifactId=javaparser-core, version=3.5.4, type=jar}
Dependency {groupId=com.jcabi, artifactId=jcabi-aether, version=0.7.19, type=jar}
Dependency {groupId=org.apache.maven, artifactId=maven-core, version=3.0.3, type=jar}
Dependency {groupId=org.apache.maven.plugins, artifactId=maven-dependency-plugin, version=3.0.2, type=jar}
Dependency {groupId=org.apache.maven.plugin-tools, artifactId=maven-plugin-annotations, version=3.5, type=jar}
Using XX advice, Runtime.getRuntime().exec("cmd /c mvn dependency:tree");
the output is (between others):
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # ca.umontreal.iro.logiannot ---
[INFO] ca.umontreal.iro.logiannot:ca.umontreal.iro.logiannot:jar:0.0.1-SNAPSHOT
[INFO] +- com.github.javaparser:javaparser-core:jar:3.5.4:compile
[INFO] +- com.jcabi:jcabi-aether:jar:0.7.19:compile
[INFO] | +- com.jcabi:jcabi-aspects:jar:0.7.19:compile
[INFO] | +- com.jcabi:jcabi-log:jar:0.7.19:compile
[INFO] | | +- log4j:log4j:jar:1.2.17:compile
[INFO] | | \- org.slf4j:slf4j-api:jar:1.7.5:compile
[INFO] | +- org.aspectj:aspectjrt:jar:1.7.2:compile
[INFO] | +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] | +- org.kuali.maven.wagons:maven-s3-wagon:jar:1.1.20:compile
[INFO] | | +- org.kuali.common:kuali-s3:jar:1.0.1:compile
[INFO] | | +- com.amazonaws:aws-java-sdk:jar:1.4.2:compile
[INFO] | | | +- org.apache.httpcomponents:httpclient:jar:4.1:compile
[INFO] | | | | \- org.apache.httpcomponents:httpcore:jar:4.1:compile
[INFO] | | | +- org.codehaus.jackson:jackson-core-asl:jar:1.8.9:compile
[INFO] | | | \- org.codehaus.jackson:jackson-mapper-asl:jar:1.8.9:compile
[INFO] | | +- org.springframework:spring-core:jar:3.1.2.RELEASE:compile
[INFO] | | +- org.kuali.common:kuali-threads:jar:1.0.9:compile
[INFO] | | \- org.slf4j:jcl-over-slf4j:jar:1.6.4:compile
[INFO] | +- org.sonatype.aether:aether-api:jar:1.13.1:compile
[INFO] | +- org.sonatype.aether:aether-spi:jar:1.13.1:compile
[INFO] | +- org.sonatype.aether:aether-util:jar:1.13.1:compile
[INFO] | +- org.sonatype.aether:aether-connector-file:jar:1.13.1:compile
[INFO] | +- org.sonatype.aether:aether-connector-asynchttpclient:jar:1.13.1:compile
[INFO] | | \- com.ning:async-http-client:jar:1.6.5:compile
[INFO] | | \- org.jboss.netty:netty:jar:3.2.5.Final:compile
[INFO] | +- org.sonatype.aether:aether-connector-wagon:jar:1.13.1:compile
[INFO] | +- org.sonatype.aether:aether-impl:jar:1.13.1:compile
[INFO] | +- org.apache.maven:maven-aether-provider:jar:3.0.5:compile
[INFO] | +- org.apache.maven.wagon:wagon-provider-api:jar:2.4:compile
[INFO] | \- org.apache.commons:commons-lang3:jar:3.1:compile
[INFO] +- org.apache.maven:maven-core:jar:3.0.3:compile
[INFO] | +- org.apache.maven:maven-model:jar:3.0.3:compile
[INFO] | +- org.apache.maven:maven-settings:jar:3.0.3:compile
[INFO] | +- org.apache.maven:maven-settings-builder:jar:3.0.3:compile
[INFO] | +- org.apache.maven:maven-repository-metadata:jar:3.0.3:compile
[INFO] | +- org.apache.maven:maven-artifact:jar:3.0.3:compile
[INFO] | +- org.apache.maven:maven-plugin-api:jar:3.0.3:compile
[INFO] | +- org.apache.maven:maven-model-builder:jar:3.0.3:compile
[INFO] | +- org.sonatype.sisu:sisu-inject-plexus:jar:2.1.1:compile
[INFO] | | \- org.sonatype.sisu:sisu-inject-bean:jar:2.1.1:compile
[INFO] | | \- org.sonatype.sisu:sisu-guice:jar:no_aop:2.9.4:compile
[INFO] | +- org.codehaus.plexus:plexus-interpolation:jar:1.14:compile
[INFO] | +- org.codehaus.plexus:plexus-utils:jar:2.0.6:compile
[INFO] | +- org.codehaus.plexus:plexus-classworlds:jar:2.4:compile
[INFO] | +- org.codehaus.plexus:plexus-component-annotations:jar:1.5.5:compile
[INFO] | \- org.sonatype.plexus:plexus-sec-dispatcher:jar:1.3:compile
[INFO] | \- org.sonatype.plexus:plexus-cipher:jar:1.4:compile
[INFO] +- org.apache.maven.plugins:maven-dependency-plugin:jar:3.0.2:compile
[INFO] | +- org.apache.maven.reporting:maven-reporting-api:jar:3.0:compile
[INFO] | +- org.apache.maven.reporting:maven-reporting-impl:jar:2.3:compile
[INFO] | | +- org.apache.maven.doxia:doxia-core:jar:1.2:compile
[INFO] | | | \- xerces:xercesImpl:jar:2.9.1:compile
[INFO] | | | \- xml-apis:xml-apis:jar:1.3.04:compile
[INFO] | | \- commons-validator:commons-validator:jar:1.3.1:compile
[INFO] | | +- commons-beanutils:commons-beanutils:jar:1.7.0:compile
[INFO] | | +- commons-digester:commons-digester:jar:1.6:compile
[INFO] | | \- commons-logging:commons-logging:jar:1.0.4:compile
[INFO] | +- commons-io:commons-io:jar:2.5:compile
[INFO] | +- org.apache.maven.doxia:doxia-sink-api:jar:1.4:compile
[INFO] | | \- org.apache.maven.doxia:doxia-logging-api:jar:1.4:compile
[INFO] | +- org.apache.maven.doxia:doxia-site-renderer:jar:1.4:compile
[INFO] | | +- org.apache.maven.doxia:doxia-decoration-model:jar:1.4:compile
[INFO] | | +- org.apache.maven.doxia:doxia-module-xhtml:jar:1.4:compile
[INFO] | | +- org.apache.maven.doxia:doxia-module-fml:jar:1.4:compile
[INFO] | | +- org.codehaus.plexus:plexus-i18n:jar:1.0-beta-7:compile
[INFO] | | +- org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-30:compile
[INFO] | | | \- junit:junit:jar:3.8.1:compile
[INFO] | | +- org.codehaus.plexus:plexus-velocity:jar:1.1.7:compile
[INFO] | | +- org.apache.velocity:velocity:jar:1.5:compile
[INFO] | | | \- oro:oro:jar:2.0.8:compile
[INFO] | | \- org.apache.velocity:velocity-tools:jar:2.0:compile
[INFO] | | +- commons-chain:commons-chain:jar:1.1:compile
[INFO] | | +- dom4j:dom4j:jar:1.1:compile
[INFO] | | +- sslext:sslext:jar:1.2-0:compile
[INFO] | | +- org.apache.struts:struts-core:jar:1.3.8:compile
[INFO] | | | \- antlr:antlr:jar:2.7.2:compile
[INFO] | | +- org.apache.struts:struts-taglib:jar:1.3.8:compile
[INFO] | | \- org.apache.struts:struts-tiles:jar:1.3.8:compile
[INFO] | +- org.codehaus.plexus:plexus-archiver:jar:3.4:compile
[INFO] | | +- org.apache.commons:commons-compress:jar:1.11:compile
[INFO] | | +- org.iq80.snappy:snappy:jar:0.4:compile
[INFO] | | \- org.tukaani:xz:jar:1.5:runtime
[INFO] | +- org.apache.maven.shared:file-management:jar:1.2.1:compile
[INFO] | | \- org.apache.maven.shared:maven-shared-io:jar:1.1:compile
[INFO] | +- org.codehaus.plexus:plexus-io:jar:2.4:compile
[INFO] | +- org.apache.maven.shared:maven-dependency-analyzer:jar:1.7:compile
[INFO] | | \- org.ow2.asm:asm:jar:5.0.2:compile
[INFO] | +- org.apache.maven.shared:maven-dependency-tree:jar:3.0.1:compile
[INFO] | | \- org.eclipse.aether:aether-util:jar:0.9.0.M2:compile
[INFO] | +- org.apache.maven.shared:maven-common-artifact-filters:jar:3.0.1:compile
[INFO] | +- org.apache.maven.shared:maven-artifact-transfer:jar:0.9.1:compile
[INFO] | | \- commons-codec:commons-codec:jar:1.6:compile
[INFO] | +- org.apache.maven.shared:maven-shared-utils:jar:3.2.0:compile
[INFO] | +- commons-lang:commons-lang:jar:2.6:compile
[INFO] | +- commons-collections:commons-collections:jar:3.2.2:compile
[INFO] | \- classworlds:classworlds:jar:1.1:compile
[INFO] \- org.apache.maven.plugin-tools:maven-plugin-annotations:jar:3.5:provided
Which is quite EXACTLY what I want. But the point is that I don't want to know what is my project's dependency tree like. I want to investigate other projects.
Now, with pomFile = new File("[externalPath].pom.xml") it does not find any dependency. (The file exists and contains proper pom isntructions).
You could start a separate process that runs mvn help:effective-pom. This command returns an xml with an "effective pom". Later you could parse that XML to obtain dependencies.
In case if you're interested in transitive dependencies you could use mvn dependency:tree in a similar fashion.