Maven dependencies available in one project but not another - java

I have two projects that use identical pom files (one project is an earlier version of the second). The second project compiles fine and allows me to use all the dependencies defined in the pom in my project. However the first project does not, and it appears as though the dependencies are not even recognized by the project.
I looked in my local .m2 folder and see that the dependencies have been downloaded in their respective folders. I even see the mvn install output says it has included the dependency, e.g.:
Including com.fasterxml.jackson.core:jackson-core:jar:2.9.6 in the shaded jar.
And later...
com.fasterxml.jackson.core:jackson-databind:jar:2.9.6 already exists in destination.
I've tried mvn clean and the dependency is still not recognized. I've tried examining the contents of all of the pom files in the project and I can't see any difference between the two projects.
I'm convinced that there is something wrong with my project, but I'm not a maven expert. Any ideas of where to look for the problem?
Here's an example of one of the dependencies that is not recognized:
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.4</version>
<scope>compile</scope>
</dependency>
Here is my mvn dependency:tree ouput
[INFO] SwirldsProxy:SwirldsProxy:jar:0.0.1-SNAPSHOT
[INFO] +- SwirldsPlatform:platform:jar:0.0.1-SNAPSHOT:compile
[INFO] | +- SwirldsPlatform:fc:jar:0.0.1-SNAPSHOT:compile
[INFO] | | +- SwirldsPlatform:fcfs:jar:0.0.1-SNAPSHOT:compile
[INFO] | | | +- SwirldsPlatform:fcutil:jar:0.0.1-SNAPSHOT:compile
[INFO] | | | | +- SwirldsPlatform:abcl-swirlds:jar:0.0.1-SNAPSHOT:compile
[INFO] | | | | +- org.abcl:abcl-contrib:jar:1.4.0:compile
[INFO] | | | | +- org.apache.derby:derby:jar:10.12.1.1:compile
[INFO] | | | | \- org.beanshell:bsh:jar:2.0b5:compile
[INFO] | | | \- SwirldsPlatform:fcfs-dep-fasl:jar:0.0.1-SNAPSHOT:compile
[INFO] | | +- SwirldsPlatform:fcdb:jar:0.0.1-SNAPSHOT:compile
[INFO] | | | \- SwirldsPlatform:fcdb-dep-fasl:jar:0.0.1-SNAPSHOT:compile
[INFO] | | \- junit:junit:jar:3.8.2:compile
[INFO] | +- com.offbynull.portmapper:portmapper:jar:2.0.4:compile
[INFO] | | +- org.apache.commons:commons-lang3:jar:3.4:compile
[INFO] | | +- commons-io:commons-io:jar:2.5:compile
[INFO] | | \- org.apache.commons:commons-collections4:jar:4.1:compile
[INFO] | +- org.slf4j:slf4j-nop:jar:1.7.21:compile
[INFO] | +- org.apache.logging.log4j:log4j-api:jar:2.7:compile
[INFO] | \- org.apache.logging.log4j:log4j-core:jar:2.7:compile
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.9.6:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:compile
[INFO] | \- com.fasterxml.jackson.core:jackson-core:jar:2.9.6:compile
[INFO] +- com.google.code.gson:gson:jar:2.4:compile
[INFO] +- com.rabbitmq:amqp-client:jar:4.0.2:compile
[INFO] | \- org.slf4j:slf4j-api:jar:1.7.21:compile
[INFO] \- com.github.davidmoten:flatbuffers-java:jar:1.6.0.2:compile
Apache Maven 3.5.0 Maven
Java version: 1.8.0_144-1-redhat
UPDATE 8/30/2018
So I discovered some interseting behavior. My project location was under D:\SomeDirectory. I tried moving it to C:\AnotherDirectory and performed mvn install and bingo, the dependencies were now available to my project.
I'm assuming this has something to do with the maven/java installation location, however I find it strange that I saw no errors when trying to run the maven commands, even when the project was under a different root directory (D:) compared to maven/java (C:).
Any ideas?

Related

embedded-kafka scalatest ClassNotFoundException: scala.collection.GenTraversableOnce

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

Evaluation error (NoSuchMethodError) in Azure ApplicationTokenCredentials when trying to start a VM

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>

java 9 unnamed module reads package [X] from both ... while debugging (with IntelliJ)

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

Powermock - java.lang.IllegalStateException: Failed to transform class

Description:
I am trying to test a static method from a class. I am using powerMock (1.6.2) + mockito (1.10.19) for mocking along with Junit4 (4.12) & java8.
Issue:
Getting the error: "Failed to transform class with name com.gs.ops.domain.StaticClass Reason: java.io.IOException: invalid constant type: 18"
Solutions Tried:
Googled threads for issue on with powermock - mockito & java-8
Excluded java assist from powermock and added java assist 3.19.0-GA
Tried different versions of powermock (1.5.4, 1.6.2...)
Below is the exception stack trace:
java.lang.IllegalStateException: Failed to transform class with name com.StaticClass. Reason: java.io.IOException: invalid constant type: 18
at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:266)
at org.powermock.core.classloader.MockClassLoader.loadModifiedClass(MockClassLoader.java:180)
at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:68)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:340)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:145)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.createDelegatorFromClassloader(JUnit4TestSuiteChunkerImpl.java:40)
at org.powermock.tests.utils.impl.AbstractTestSuiteChunkerImpl.createTestDelegators(AbstractTestSuiteChunkerImpl.java:244)
at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.<init>(JUnit4TestSuiteChunkerImpl.java:61)
at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.<init>(AbstractCommonPowerMockRunner.java:32)
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:408)
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.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:67)
Caused by: java.lang.RuntimeException: java.io.IOException: invalid constant type: 18
at javassist.CtClassType.getClassFile2(CtClassType.java:203)
at javassist.compiler.MemberResolver.lookupMethod(MemberResolver.java:110)
at javassist.compiler.MemberResolver.lookupMethod(MemberResolver.java:96)
at javassist.compiler.TypeChecker.atMethodCallCore(TypeChecker.java:704)
at javassist.expr.NewExpr$ProceedForNew.setReturnType(NewExpr.java:243)
at javassist.compiler.JvstTypeChecker.atCallExpr(JvstTypeChecker.java:146)
at javassist.compiler.ast.CallExpr.accept(CallExpr.java:45)
at javassist.compiler.TypeChecker.atVariableAssign(TypeChecker.java:248)
at javassist.compiler.TypeChecker.atAssignExpr(TypeChecker.java:217)
at javassist.compiler.ast.AssignExpr.accept(AssignExpr.java:38)
at javassist.compiler.CodeGen.doTypeCheck(CodeGen.java:241)
at javassist.compiler.CodeGen.atStmnt(CodeGen.java:329)
at javassist.compiler.ast.Stmnt.accept(Stmnt.java:49)
at javassist.compiler.CodeGen.atStmnt(CodeGen.java:350)
at javassist.compiler.ast.Stmnt.accept(Stmnt.java:49)
at javassist.compiler.CodeGen.atIfStmnt(CodeGen.java:404)
at javassist.compiler.CodeGen.atStmnt(CodeGen.java:354)
at javassist.compiler.ast.Stmnt.accept(Stmnt.java:49)
at javassist.compiler.Javac.compileStmnt(Javac.java:568)
at javassist.expr.NewExpr.replace(NewExpr.java:206)
at org.powermock.core.transformers.impl.MainMockTransformer$PowerMockExpressionEditor.edit(MainMockTransformer.java:418)
at javassist.expr.ExprEditor.loopBody(ExprEditor.java:211)
at javassist.expr.ExprEditor.doit(ExprEditor.java:90)
at javassist.CtClassType.instrument(CtClassType.java:1374)
at org.powermock.core.transformers.impl.MainMockTransformer.transform(MainMockTransformer.java:74)
at org.powermock.core.classloader.MockClassLoader.loadMockClass(MockClassLoader.java:251)
... 24 more
Caused by: java.io.IOException: invalid constant type: 18
at javassist.bytecode.ConstPool.readOne(ConstPool.java:1090)
at javassist.bytecode.ConstPool.read(ConstPool.java:1033)
at javassist.bytecode.ConstPool.<init>(ConstPool.java:149)
at javassist.bytecode.ClassFile.read(ClassFile.java:737)
at javassist.bytecode.ClassFile.<init>(ClassFile.java:108)
at javassist.CtClassType.getClassFile2(CtClassType.java:190)
... 49 more
Pom file:
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.6.2</version>
<exclusions>
<exclusion>
<groupId>org.junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
<exclusion>
<groupId>org.powermock</groupId>
<artifactId>powermock-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.powermock</groupId>
<artifactId>powermock-reflect</artifactId>
</exclusion>
</exclusions>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.19.0-GA</version>
</dependency>
Powermock 1.6.3 uses javassist 3.15.2-GA which does not support certain types. Using 3.18.2-GA javassist worked for me. You may want to override dependency in your project.
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.18.2-GA</version>
</dependency>
You may face another problem for which the solution lies here Mockito + PowerMock LinkageError while mocking system class
Hope this helps.
So there seems to be issue with javassist (bytecode toolkit) prior to 3.18.2, as there's a resolved JIRA ticket-223.
1 - To find javassist version in your pom.xml, can use mvn dependency task
$ mvn dependency:tree | grep javassist
[INFO] | \- org.javassist:javassist:jar:3.14.0-GA:compile
which is used by the powermock-module-junit4-rule ,
[INFO] +- org.powermock:powermock-module-junit4-rule:jar:1.4.9:test
[INFO] | +- org.powermock:powermock-classloading-base:jar:1.4.9:test
[INFO] | \- org.powermock:powermock-core:jar:1.4.9:compile
[INFO] | \- org.javassist:javassist:jar:3.14.0-GA:compile
2 - So, updating the javassist version by explicitly to any versions >= 3.18.2 should work.
As, in my case, I am using use 3.20.0-GA
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.20.0-GA</version>
</dependency>
Working eg. with scalatest
#PowerMockIgnore(Array("javax.management.*"))
#RunWith(classOf[PowerMockRunner])
#PrepareForTest(Array(classOf[Configurator]))
class LogServiceSpec {
#Test
def initialises_log4j2_on_each_instance_call() {
PowerMockito.mockStatic(classOf[Configurator])
val logService1 = new LogService
PowerMockito.verifyStatic(Mockito.times(1))
Configurator.initialize(Matchers.anyString(), Matchers.eq("log4j.config"))
}
}
This is caused because of the conflict of dependencies. Resolving the dependency conflicts is one way to resolve this issue and the other way is to reorder <dependency></dependency> elements in your pom.xml. Move the powermock dependency declarations to the top of the <dependencies></dependencies> section. This is a complete hack and the right way to resolve it would be to resolve the dependency conflicts.
To identify those conflict you may use the command "mvn dependency:tree". Here is the dependency tree for my application for which I came across this same problem. Notice that there are two dependencies of "javassist" in the tree.
[INFO] +- org.mockito:mockito-core:jar:1.10.19:test
[INFO] | +- org.hamcrest:hamcrest-core:jar:1.1:compile
[INFO] | \- org.objenesis:objenesis:jar:2.1:compile
[INFO] +- org.powermock:powermock-module-junit4:jar:1.6.4:test
[INFO] | \- org.powermock:powermock-module-junit4-common:jar:1.6.4:test
[INFO] | +- org.powermock:powermock-core:jar:1.6.4:compile
[INFO] | <span style="background-color: #FFFF00">| \- org.javassist:javassist:jar:3.20.0-GA:compile</span>
[INFO] | \- org.powermock:powermock-reflect:jar:1.6.4:compile
[INFO] +- org.powermock:powermock-api-mockito:jar:1.6.4:compile
[INFO] | \- org.powermock:powermock-api-support:jar:1.6.4:compile
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.7.14:compile
[INFO] | +- org.slf4j:slf4j-api:jar:1.7.14:compile
[INFO] | \- log4j:log4j:jar:1.2.17:compile
[INFO] | +- org.apache.struts:struts2-core:jar:2.3.16.3-atlassian-6:provided
[INFO] | | \- ognl:ognl:jar:3.0.6:provided
<span style="background-color: #FFFF00">
[INFO] | | \- javassist:javassist:jar:3.11.0.GA:provided</span>
[INFO] | +- com.atlassian:webwork-compat:jar:1.24:provided
[INFO] | +- org.freemarker:freemarker:jar:2.3.16-atlassian-34:provided
[INFO] | | \- logkit:logkit:jar:1.2:provided
[INFO] | +- opensymphony:sitemesh:jar:2.5-atlassian-6:provided
[INFO] | +- commons-fileupload:commons-fileupload:jar:1.3.1:provided
[INFO] | +- org.tuckey:urlrewritefilter:jar:4.0.3:provided
[INFO] | +- velocity-tools:velocity-tools:jar:1.2:provided
[INFO] | +- commons-dbutils:commons-dbutils:jar:1.3:provided
[INFO] | +- org.hamcrest:hamcrest-all:jar:1.3:provided
[INFO] | +- com.atlassian.bamboo:atlassian-user-crowd-provider:jar:5.10.0:provided
[INFO] | | +- com.atlassian.crowd:crowd-integration-client-rest:jar:2.7.2:provided
[INFO] | | | \- com.atlassian.crowd:crowd-integration-client-common:jar:2.7.2:provided
[INFO] | | | \- com.atlassian.security:atlassian-cookie-tools:jar:3.2:provided
[INFO] | | +- com.atlassian.crowd:crowd-integration-api:jar:2.7.2:provided
[INFO] | | | \- com.atlassian.crowd:embedded-crowd-api:jar:2.7.2:provided
[INFO] | | +- com.atlassian.user:atlassian-user-api:jar:4.1.1:provided
[INFO] | | | \- com.opensymphony.propertyset:api:jar:1.6.0-m1:provided
[INFO] | | +- com.atlassian.user:atlassian-user-ldap:jar:4.1.1:provided
[INFO] | | +- org.acegisecurity:acegi-security:jar:1.0.4:provided
[INFO] | | | \- oro:oro:jar:2.0.8:provided
[INFO] | | \- com.atlassian.crowd:crowd-integration-seraph25:jar:2.7.2:provided
[INFO] | +- javax.xml.stream:stax-api:jar:1.0-2:provided
[INFO] | +- com.atlassian.core:atlassian-core:jar:5.0.2:provided
[INFO] | | \- com.atlassian.image:atlassian-image-consumer:jar:1.0.1:provided
[INFO] | +- org.apache.maven:maven-embedder:jar:3.0.4:provided
[INFO] | | +- org.apache.maven:maven-settings:jar:3.0.4:provided
[INFO] | | +- org.apache.maven:maven-plugin-api:jar:3.0.4:provided
[INFO] | | +- org.apache.maven:maven-model-builder:jar:3.0.4:provided
[INFO] | | +- org.apache.maven:maven-compat:jar:3.0.4:provided
[INFO] | | +- org.codehaus.plexus:plexus-classworlds:jar:2.4:provided
[INFO] | | +- org.sonatype.sisu:sisu-inject-plexus:jar:2.3.0:provided
[INFO] | | | \- org.sonatype.sisu:sisu-inject-bean:jar:2.3.0:provided
[INFO] | | +- org.codehaus.plexus:plexus-component-annotations:jar:1.5.5:provided
[INFO] | | +- org.sonatype.plexus:plexus-sec-dispatcher:jar:1.3:provided
[INFO] | | +- org.sonatype.plexus:plexus-cipher:jar:1.7:provided
[INFO] | | \- commons-cli:commons-cli:jar:1.2:provided
[INFO] | +- org.apache.maven:maven-model:jar:3.0.4:provided
[INFO] | +- com.octo.captcha:jcaptcha:jar:2.0-alpha-1:provided
[INFO] | +- com.octo.captcha:jcaptcha-api:jar:2.0-alpha-1:provided
[INFO] | +- com.jhlabs:filters:jar:2.0.235:provided
[INFO] | +- org.apache.struts:struts2-sitemesh-plugin:jar:2.1.8.1:provided
[INFO] | +- org.slf4j:jul-to-slf4j:jar:1.7.10:provided
[INFO] | +- com.atlassian.plugins:atlassian-plugins-schema:jar:4.0.5:provided
[INFO] | | \- com.atlassian.plugins:atlassian-plugins-osgi:jar:4.0.5:provided
[INFO] | | +- com.atlassian.plugins:atlassian-plugins-osgi-events:jar:4.0.5:provided
[INFO] | | +- biz.aQute.bnd:biz.aQute.bndlib:jar:2.4.1:provided
[INFO] | | +- org.apache.felix:org.apache.felix.framework:jar:4.2.1:provided
[INFO] | | \- org.twdata.pkgscanner:package-scanner:jar:0.9.5:provided
[INFO] | \- xerces:xercesImpl:jar:2.11.0:provided
[INFO] | \- xml-apis:xml-apis:jar:1.4.01:provided
[INFO] +- junit:junit:jar:4.12:test
[INFO] +- info.cukes:cucumber-java:jar:1.2.4:test
[INFO] | \- info.cukes:cucumber-core:jar:1.2.4:test
[INFO] | +- info.cukes:cucumber-html:jar:0.2.3:test
[INFO] | +- info.cukes:cucumber-jvm-deps:jar:1.0.5:test
[INFO] | \- info.cukes:gherkin:jar:2.12.2:test
[INFO] +- info.cukes:cucumber-junit:jar:1.2.4:test
[INFO] +- com.atlassian.plugins:atlassian-plugins-osgi-testrunner:jar:1.2.3:test
[INFO] | +- org.apache.wink:wink-client:jar:1.1.3-incubating:test
[INFO] | | +- org.apache.wink:wink-common:jar:1.1.3-incubating:test
[INFO] | | | \- org.apache.geronimo.specs:geronimo-annotation_1.1_spec:jar:1.0:test
[INFO] | | +- javax.xml.bind:jaxb-api:jar:2.2:test
[INFO] | | \- com.sun.xml.bind:jaxb-impl:jar:2.2.1.1:test
[INFO] | +- commons-io:commons-io:jar:1.4:provided
[INFO] | \- com.atlassian.upm:upm-api:jar:2.15:test
[INFO] +- javax.ws.rs:jsr311-api:jar:1.1.1:provided
[INFO] +- com.google.code.gson:gson:jar:2.2.2-atlassian-1:compile
[INFO] +- com.mashape.unirest:unirest-java:jar:1.3.3:compile
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.3.1:compile
[INFO] | +- org.apache.httpcomponents:httpcore:jar:4.3:compile
[INFO] | \- commons-codec:commons-codec:jar:1.6:compile
[INFO] +- org.apache.httpcomponents:httpasyncclient:jar:4.0:compile
[INFO] | \- org.apache.httpcomponents:httpcore-nio:jar:4.3:compile
[INFO] +- org.apache.httpcomponents:httpmime:jar:4.3.1:compile
[INFO] +- org.json:json:jar:20090211:compile
[INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.3.3:compile
[INFO] \- com.fasterxml.jackson.core:jackson-databind:jar:2.3.3:compile
[INFO] \- com.fasterxml.jackson.core:jackson-annotations:jar:2.3.0:compile
I hope this helps.
In my case, a "java.io.IOException: invalid constant type: 18" was caused by multiple versions of javassist libraries in my classpath - both 3.12.1.GA and 3.18.2-GA. The problem disappeared when i removed the older one.
Not really an answer! I got a similar error when running a Maven build with JDK8 and generating Java6 byte code. My pom looks like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<compilerVersion>1.6</compilerVersion>
<source>1.6</source>
<target>1.6</target>
<maxmem>2000m</maxmem>
<fork>true</fork>
</configuration>
</plugin>
When I reverted to JDK6 I no longer got the error.
In my case JRE System Library --> Execution Environment was set up on JavaSE-1.7, but the only installed JRE was JRE1.8. So it was pointing to java 8 in place of java 7. Once I moved to java 7 it start working fine for me.
This issue is related to a compatibility issue with Java 8. could you execute your tests on java 7 ?
Run "mvn dependency:tree | grep javassist" on terminal. If javaassist dependency is being shown in non test and test libraries. Now you only have to exclude it during runtime for tests. So the way to do this is adding a build plugin on the lines of:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<classpathDependencyExcludes>
<classpathDependencyExcludes>javassist:javassist</classpathDependencyExcludes>
</classpathDependencyExcludes>
</configuration>
</plugin>
</plugins>
Please note the classpathDependencyExcludes might change for you based on your javassist version.

How to upgrade all dependencies to a specific version

I tried doing a mvn dependency:tree and I get a tree of dependencies.
My question is, My project depends on many modules which internally depends on many spring artifacts. There are a few version clashes. I want to upgrade all spring related libraries to say the latest one (2.6.x or above). What is the preferred way to do this?
Should I declare all the deps spring-context, spring-support (and 10 other artifacts) in my pom.xml and point them to 2.6.x ? Is there any other better method ?
[INFO] +- com.xxxx:yyy-jar:jar:1.0-SNAPSHOT:compile
[INFO] | +- com.xxxx:zzz-commons:jar:1.0-SNAPSHOT:compile
[INFO] | | +- org.springframework:spring-dao:jar:2.0.7:compile
[INFO] | | +- org.springframework:spring-jdbc:jar:2.0.7:compile
[INFO] | | +- org.springframework:spring-web:jar:2.0.7:compile
[INFO] | | +- org.springframework:spring-support:jar:2.0.7:compile
[INFO] | | +- net.sf.ehcache:ehcache:jar:1.2:compile
[INFO] | | +- commons-collections:commons-collections:jar:3.2:compile
[INFO] | | +- aspectj:aspectjweaver:jar:1.5.3:compile
[INFO] | | +- betex-commons:betex-commons:jar:5.5.1-2:compile
[INFO] | | \- javax.servlet:servlet-api:jar:2.4:compile
[INFO] | +- org.springframework:spring-beans:jar:2.0.7:compile
[INFO] | +- org.springframework:spring-jmx:jar:2.0.7:compile
[INFO] | +- org.springframework:spring-remoting:jar:2.0.7:compile
[INFO] | +- org.apache.cxf:cxf-rt-core:jar:2.0.2-incubator:compile
[INFO] | | +- org.apache.cxf:cxf-api:jar:2.0.2-incubator:compile
[INFO] | | | +- org.apache.geronimo.specs:geronimo-activation_1.1_spec:jar:1.0-M1:compile
[INFO] | | | +- org.codehaus.woodstox:wstx-asl:jar:3.2.1:compile
[INFO] | | | +- org.apache.neethi:neethi:jar:2.0.2:compile
[INFO] | | | \- org.apache.cxf:cxf-common-schemas:jar:2.0.2-incubator:compile
UPDATE : I have removed the extra question about "\-" so my question is now what the subject asks for :)
End of that subtree. Nothing more than a fancy bit of ascii art - think as if its +-
There are two solutions:
The OSS way: Download the projects you depend on, migrate them to the latest version of Spring and send them a patch so everyone gets the new features
Overwrite the version of every dependency in your own POM.
Have you looked at the dependecyManagement tag? It allows you to specify the version number of each dependency a parent pom. All your other poms can then inherit the specified versions:
<properties>
<spring.version>2.5.6</spring.version>
</properties>
...
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<!-- more dependencies -->
</dependencies>
</dependencyManagement>
More information is available at the Introduction to the Dependency Mechanism.

Categories