How do I upgrade the MongoDB driver in a Kogito Quarkus project? - java

I'm new to Kogito and Quarkus, so help me a little bit here.
Our application has been recently affected by this bug:
https://jira.mongodb.org/browse/JAVA-4018
Now I want to upgrade the Mongo DB driver version to use the version with the fix but I'm not sure where do I need to do that.
I see these two in the pom.xml:
<project>
...
<dependencies>
...
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-mongodb-client</artifactId>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-addons-quarkus-persistence-mongodb</artifactId>
</dependency>
</dependencies>
</project>
But I'm not sure if I should look for the driver referenced by these dependencies and then add the version tag for any of them...
Can you point me the direction where I need to look to upgrade the driver version?

Which Kogito version are you using? The latest Kogito Quarkus version already uses the latest MongoDB driver:
[INFO] ----< org.kie.kogito.examples:process-mongodb-persistence-quarkus >-----
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # process-mongodb-persistence-quarkus ---
[INFO] org.kie.kogito.examples:process-mongodb-persistence-quarkus:jar:2.0.0-SNAPSHOT
[INFO] +- org.kie.kogito:kogito-addons-quarkus-persistence-mongodb:jar:2.0.0-SNAPSHOT:compile
[INFO] | +- org.kie.kogito:kogito-addons-persistence-mongodb:jar:2.0.0-SNAPSHOT:compile
[INFO] | \- io.quarkus:quarkus-mongodb-client:jar:2.13.0.Final:compile
[INFO] | +- org.mongodb:mongodb-driver-sync:jar:4.7.1:compile
[INFO] | | +- org.mongodb:bson:jar:4.7.1:compile
[INFO] | | \- org.mongodb:mongodb-driver-core:jar:4.7.1:compile
[INFO] | | \- org.mongodb:bson-record-codec:jar:4.7.1:runtime
[INFO] | +- org.mongodb:mongodb-driver-reactivestreams:jar:4.7.1:compile
[INFO] | \- org.mongodb:mongodb-crypt:jar:1.5.2:compile
[INFO] | | +- org.testcontainers:mongodb:jar:1.17.3:test
Can you try upgrading to Kogito 1.27.0.Final?
MongoDB 4.7.1 includes the fix you're looking for.

Related

Eclipse uses wrong maven dependency in launch configuration

I'm working on a project that uses Maven for dependency / building / whatever (project life cycle management or sth), and I'm using Eclipse to develop and test.
The project uses Vert.x (latest) and I'm trying to use Hazelcast for some cluster management, but I encountered a bug with the Hazelcast version that Vert.x declares as a dependency (3.6.3) and the solution apparently is to upgrade to a more recent version.
I've added an updated Hazelcast dependency in my pom.xml as such:
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<version>[3.7,)</version>
</dependency>
And maven indeed updates the dependency (actually Eclipse called maven to update as soon as I save the pom.xml file - pretty neat), and so I get the dependency tree:
$ mvn dependency:tree
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building project 3.8.4
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for jfree:jfreechart:jar:1.0.8 is missing, no dependency information available
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # project ---
[INFO] my.group:project:jar:3.8.4
[INFO] +- some.private.dep ...
[INFO] | +- org.junit:junit4-engine:jar:5.0.0-ALPHA:compile (version selected from constraint [4,))
[INFO] | | \- org.junit:junit-engine-api:jar:5.0.0-ALPHA:compile
[INFO] | | +- org.junit:junit-commons:jar:5.0.0-ALPHA:compile
[INFO] | | \- org.opentest4j:opentest4j:jar:1.0.0-ALPHA:compile
[INFO] | +- io.vertx:vertx-hazelcast:jar:3.3.3:compile (version selected from constraint [3.0.0,))
[INFO] | \- io.vertx:vertx-web:jar:3.4.0.Beta1:compile (version selected from constraint [3.0.0,))
[INFO] | \- io.vertx:vertx-auth-common:jar:3.4.0.Beta1:compile
[INFO] +- io.vertx:vertx-core:jar:3.4.0.Beta1:compile
[INFO] | +- io.netty:netty-common:jar:4.1.8.Final:compile
[INFO] | +- io.netty:netty-buffer:jar:4.1.8.Final:compile
[INFO] | +- io.netty:netty-transport:jar:4.1.8.Final:compile
[INFO] | +- io.netty:netty-handler:jar:4.1.8.Final:compile
[INFO] | | \- io.netty:netty-codec:jar:4.1.8.Final:compile
[INFO] | +- io.netty:netty-handler-proxy:jar:4.1.8.Final:compile
[INFO] | | \- io.netty:netty-codec-socks:jar:4.1.8.Final:compile
[INFO] | +- io.netty:netty-codec-http:jar:4.1.8.Final:compile
[INFO] | +- io.netty:netty-codec-http2:jar:4.1.8.Final:compile
[INFO] | +- io.netty:netty-resolver:jar:4.1.8.Final:compile
[INFO] | \- io.netty:netty-resolver-dns:jar:4.1.8.Final:compile
[INFO] | \- io.netty:netty-codec-dns:jar:4.1.8.Final:compile
[INFO] +- junit:junit:jar:4.12:test
...
[INFO] +- com.hazelcast:hazelcast:jar:3.8-EA:compile
[INFO] \- org.slf4j:slf4j-jdk14:jar:1.7.22:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.785 s
[INFO] Finished at: 2017-02-06T09:52:46+02:00
[INFO] Final Memory: 25M/435M
[INFO] ------------------------------------------------------------------------
When I run mvn package to create the shaded Jar, I get the correct version of Hazelcast.
The problem is that if I create an Eclipse launch configuration for running the project or its unit tests, it inserts both the old version of Hazelcast as well as the new version of Hazelcase into the classpath - here's an example command line from a unit test being run:
/usr/lib/jvm/java-8-openjdk-amd64/bin/java -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:33123 -ea -Dfile.encoding=UTF-8
-classpath ...:
$HOME/.m2/repository/io/vertx/vertx-hazelcast/3.3.3/vertx-hazelcast-3.3.3.jar:
$HOME/.m2/repository/com/hazelcast/hazelcast/3.6.3/hazelcast-3.6.3.jar:
...
$HOME/.m2/repository/com/hazelcast/hazelcast/3.8-EA/hazelcast-3.8-EA.jar:
...
-version 3 -port 38387 -testLoaderClass org.eclipse.jdt.internal.junit4.runner.JUnit4TestLoader
-loaderpluginname org.eclipse.jdt.junit4.runtime
-classNames my.group.project.SomeTest
Now because both versions are loaded into the classpath, the first one (the older) "wins" and I get the bug instead of getting the newer fixed version.
The launch configuration "Classpath" tab looks very standard:
+ Bootstrap Entries
\- JRE System Library
+ User Enties
\- project
\- Maven Dependencies
And the "Maven Dependencies" "folder" in the "Project Explorer" view shows only the newer Hazelcast version.
What is going on?
Update:
As per the discussion in the comments, I added exclusions to the pom.xml file to prevent vertx-hazelcast from adding the old hazelcast dependency. Because vertx-hazelcast is loaded from yet another (private) dependency, the new setup is a bit more involved and looks like this:
<dependency>
<groupId>some.private</groupId>
<artifactId>dependency</artifactId>
<version>[1.3,)</version>
<exclusions>
<exclusion>
<groupId>io.vertx</groupId>
<artifactId>vertx-hazelcast</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
<version>[3.0.0,)</version>
</dependency>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<version>[3.7,)</version>
</dependency>
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-hazelcast</artifactId>
<version>[3.0.0,)</version>
<exclusions>
<exclusion>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
</exclusion>
</exclusions>
</dependency>
I then removed the old launch configuration and recreated it (by right clicking the JUnit test case and choosing "Debug as Junit") - But that does not change the Eclipse behavior - some jars in the classpath have moved around a bit, but the result is still that vertx-hazelcast and its hazelcast-3.6.3.jar dependency are loaded before hazelcast-3.8.jar.
Note This answer is a summary from discussion with the OP
It looks like vertex-hazelcast declares both compile and test scoped dependencies on hazelcast. These scopes are not transitive so it's my understanding that this version will be included in the classpath by design. #Echnalb suggestion to use an exclusion is the recommended way to resolve this.
As that hasn't worked, it could be an ancestor is also declaring a dependency which would also need to be excluded.
After looking through some other dependencies that were declared in vertex-hazelcast, I checked hazelcast-client to see if it also declared a dependency on the earlier version of hazelcast the assumption being that the ancestral dependency was being added to the classpath despite the exclusion from the parent.
It did include such a dependency:
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<scope>test</scope>
<version>${project.parent.version}</version>
<classifier>tests</classifier>
</dependency>
I suggest(ed) adding an exclusion for hazelcast-client which seems to have solved the problem.
#Guss comments
Prior to the exclusion, running dependency:tree, hazelcast-client is
not listed at all
It is interesting that dependency:tree does not detect test scoped dependencies. Is there's a way to force it to switch scopes?

Unable to load CoreNLP Shift-Reduce model into CoreNLP jar

I don't understand how to load CoreNLP's Shift-Reduce Constituency Parser (SRCP) from my java app.
I'm using Apache Maven to manage my project's dependencies. Per the docs, the SRCP model is not bundled with CoreNLP, so I have downloaded stanford-srparser-2014-10-23-models.jar separately (http://nlp.stanford.edu/software/srparser.shtml) and placed that file in:
~/.m2/repository/edu/stanford/nlp/stanford-corenlp/3.5.2/stanford-srparser-2014-10-23-models.jar
That is the same directory as the core dependency jar
~/.m2/repository/edu/stanford/nlp/stanford-corenlp/3.5.2/stanford-corenlp-3.5.2.jar
Here is the relevant portion of my project's pom.xml:
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.5.2</version>
</dependency>
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-corenlp</artifactId>
<version>3.5.2</version>
<classifier>models</classifier>
</dependency>
Compiling is successful:
mvn clean compile
But when I try to load the app, I receive:
java.lang.reflect.InvocationTargetException
...
Caused by: edu.stanford.nlp.io.RuntimeIOException: java.io.IOException: Unable to resolve "edu/stanford/nlp/models/srparser/englishSR.ser.gz" as either class path, filename or URL
I unzipped the compiled project war, and "edu/stanford/nlp/models/srparser/englishSR.ser.gz" is not present.
Here is how I'm calling the model in my app:
// Initialize a CoreNLP pipeline
public static Properties props = new Properties();
public static StanfordCoreNLP pipeline;
// Set the CoreNLP pipeline annotators.
props.setProperty("annotators", "tokenize, ssplit, parse, sentiment");
props.setProperty("parse.model", "edu/stanford/nlp/models/srparser/englishSR.ser.gz");
pipeline = new StanfordCoreNLP(props);
How can I update my Maven config to force my CoreNLP dependency to include the srparser model? Keep in mind that I need this configuration to run in other developers' environments, so the solution should be clean and reusable if possible.
Thanks!
EDIT:
In response to #jah's comment, below are the results of mvn dependency:tree. The build succeeds, but the srparser model is not compiled/present:
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) # [REDACTED] ---
Downloading:
...
[INFO] com.[REDACTED].nlp:nlp:war:0.1.0
[INFO] +- com.strategicgains:RestExpress:jar:0.11.2:compile
[INFO] | +- com.strategicgains:RestExpress-Common:jar:0.11.2:compile
[INFO] | +- com.strategicgains:DateAdapterJ:jar:1.1.4:compile
[INFO] | +- com.thoughtworks.xstream:xstream:jar:1.4.7:compile
[INFO] | | +- xmlpull:xmlpull:jar:1.1.3.1:compile
[INFO] | | \- xpp3:xpp3_min:jar:1.1.4c:compile
[INFO] | +- io.netty:netty-all:jar:4.0.29.Final:compile
[INFO] | +- org.owasp.encoder:encoder:jar:1.1.1:compile
[INFO] | \- com.jcraft:jzlib:jar:1.1.3:compile
[INFO] +- junit:junit:jar:4.11:test
[INFO] | \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- edu.stanford.nlp:stanford-corenlp:jar:3.5.2:compile
[INFO] | +- com.io7m.xom:xom:jar:1.2.10:compile
[INFO] | | +- xml-apis:xml-apis:jar:1.3.03:compile
[INFO] | | +- xerces:xercesImpl:jar:2.8.0:compile
[INFO] | | \- xalan:xalan:jar:2.7.0:compile
[INFO] | +- joda-time:joda-time:jar:2.1:compile
[INFO] | +- de.jollyday:jollyday:jar:0.4.7:compile
[INFO] | | \- javax.xml.bind:jaxb-api:jar:2.2.7:compile
[INFO] | +- com.googlecode.efficient-java-matrix-library:ejml:jar:0.23:compile
[INFO] | \- javax.json:javax.json-api:jar:1.0:compile
[INFO] +- edu.stanford.nlp:stanford-corenlp:jar:models:3.5.2:compile
[INFO] +- org.json:json:jar:20151123:compile
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.6.4:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.6.0:compile
[INFO] | \- com.fasterxml.jackson.core:jackson-core:jar:2.6.4:compile
[INFO] \- commons-io:commons-io:jar:1.3.2:compile
First, download the srparser jar and place it in your project root: http://nlp.stanford.edu/software/stanford-srparser-2014-10-23-models.jar
Second, from the project root, execute the following command to install the srparser model dependency via Maven:
mvn install:install-file -Dfile=stanford-srparser-2014-10-23-models.jar -DgroupId=edu.stanford.nlp -DartifactId=stanford-srparser -Dversion=3.5.2 -Dpackaging=jar
Note the custom artifactId and lack of classifier in the command -- this is to prevent namespace confusion with the other CoreNLP modules.
Third, add the dependency to the Maven project's pom.xml:
<dependencies>
...
<dependency>
<groupId>edu.stanford.nlp</groupId>
<artifactId>stanford-srparser</a‌​rtifactId>
<version>3.5.2</version>
</dependency>
...
</dependencies>
Finally, clean install:
mvn clean install
If you continue to experience issues, it may be helpful to clear your Maven dependencies:
mvn dependency:purge-local-repository
And don't forget to add the download/install commands to your project README/environment bootstrap file!
(Thanks for your help #jah and #GaborAngeli.)
To run the shift-reduce parser, you need to include the shift-reduce models jar, which can be found at: http://nlp.stanford.edu/software/srparser.shtml
Not sure if it's on maven, but it appears not?
If you run the mvn command from the folder where the stanford-srparser-2014-10-23-models.jar is placed, then the following command should do the trick.
mvn install:install-file -Dfile=stanford-srparser-2014-10-23-models.jar -DgroupId=edu.stanford.nlp -DartifactId=stanford-corenlp -Dversion=3.5.2 -Dclassifier=models -Dpackaging=jar

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.

Maven Dependancy Refereing old Poi Version

I am using Apache Poi version 3.8 in my POM. But it is still downloading poi-3.2 along with poi-3.8 as (may be) due to some internal dependency. The strange behavior for me is My project using poi-3.2 when even I have mentioned 3.8 version in POM. I have Googled a lot for the same, but found myself unlucky.
Here is my POM entry :
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.8</version>
<type>jar</type>
</dependency>
I have checked the poi jar my project using in classpath by the code:
ClassLoader classloader =
org.apache.poi.poifs.filesystem.POIFSFileSystem.class.getClassLoader();
URL res = classloader.getResource(
"org/apache/poi/poifs/filesystem/POIFSFileSystem.class");
String path = res.getPath();
System.out.println("Core POI came from " + path);
This prints :
Core POI came from file:/D:/Software/Softwares/apache-tomcat-6.0.33/webapps/scd-web/WEB-INF/lib/poi-3.2.jar!/org/apache/poi/poifs/filesystem/POIFSFileSystem.class
There is a poi-3.8.jar in same folder but classpath picking up 3.2.
My question is :
What should I do to so that My project uses poi-3.8.jar instead of poi-3.2.jar.
Many Thanks !!
Edited:
Output of mvn dependency:tree
[INFO] Building SCD-common [INFO] task-segment: [dependency:tree]
[INFO]
------------------------------------------------------------------------
[WARNING] While downloading xmlbeans:xmlbeans:2.3.0 This artifact has been relocated to org.apache.xmlbeans:xmlbeans:2.3.0.
[INFO] [dependency:tree] [INFO] com.idc:scd-common:jar:4.2.0.5
[INFO] +- org.springframework:spring-webmvc:jar:2.5.6:compile
[INFO] | +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] | +- org.springframework:spring-beans:jar:2.5.6:compile
[INFO] | +- org.springframework:spring-context-support:jar:2.5.6:compile
[INFO] | \- org.springframework:spring-web:jar:2.5.6:compile
[INFO] +- com.idc.worldwide.keystones:service-single-signon-dynamo-api:jar:1.0:compile
[INFO] +- com.idc.worldwide.keystones:service-single-signon-dynamo-database-impl:jar:1.0.3:compile
[INFO] | +- org.apache:commons-dbcp:jar:1.2.2:compile
[INFO] | +- org.apache:commons-pool:jar:1.4:compile
[INFO] | \- com.idc.worldwide.webchannel:sage-core:jar:3.2.0.001:compile
[INFO] | +- com.idc.webchannel.legacy.sage-dependencies:aspose-slides:jar:1. 0:compile
[INFO] | +- com.servlets:cos:jar:09May2002:compile
[INFO] | +- com.sun:jai_codec:jar:1.1.3:compile
[INFO] | +- com.sun:jai_core:jar:1.1.3:compile
[INFO] | +- com.verity:k2:jar:5.00.3177.0:compile
[INFO] | +- org.apache:poi:jar:3.2:compile
[INFO] | +- org.apache:poi_contrib:jar:3.2:compile
[INFO] | +- org.apache:poi_scratchpad:jar:3.2:compile
[INFO] | \- org.springframework:spring:jar:2.5.6:compile
[INFO] +- org.springframework:spring-core:jar:3.0.5.RELEASE:compile
[INFO] | \- org.springframework:spring-asm:jar:3.0.5.RELEASE:compile
[INFO] +- org.springframework:spring-aop:jar:3.0.5.RELEASE:compile
There are various mvn command to help solving this issue:
mvn dependency:analyze-dep-mgt
will print details about dependency resolving.
mvn dependency:tree
will print the dependency tree (very helpful to see dependencies of your dependencies)
mvn help:effective-pom
will print the pom resulting from the merge of your pom hierarchy.
If you don't find any references to poi-3.2 with maven, you can take a look at your classpath in your IDE. Do you add any jar by-passing maven ?
Editing your question with the result of those commands can be useful for us to help you.
Looks like
org.apache:poi:jar:3.2
is a compile dependency of
com.idc.worldwide.keystones:service-single-signon-dynamo-database-impl
(although I think you may have cut something)
and
org.apache.poi:poi:jar:3.8
is not a dependency (it's not in the dependency tree).
Make sure your <dependency> entry is within the <dependencies> tag.
Run
mvn dependency:tree
to check which library has a transitive dependency to poi 3.2. You can then exclude it in your pom.
<dependency>
<groupId>sample.group</groupId>
<artifactId>sample-artifactB</artifactId>
<version>1</version>
<exclusions>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
</exclusion>
</exclusions>
</dependency>
Maybe you are mixing normal dependency with plugin dependency, see here (not too fitting answer).
Use dependency management in the root POM if you have child projects.

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