I am trying to run a Junit test from Intellij, which is failing. The same test is succeeding if I use my terminal and mvn.
I noticed that the classpath used when Intellij runs the test is different from the classpath that mvn test uses. I believe this is causing some conflicts during the execution in Intellij and causing it to fail.
Versions:
Maven: 3.1.0 Same maven is used by Intellij and Terminal
Java: 1.6.0_65 both by Intellij Module and maven
Anyone has any pointers on how to resolve this?
Related
In my surefire configuration I have a classpathDependencyExcludes entry.
For some reason Intellij does not seem to pick up this configuration (mvn test, does). Is there any way to have Intellij notice my surfire configuration?
Ps.
It seems like something similar has been reported a long long time ago at Intellij ( IDEA-52286 ), but never fixed.
Both IDEA-101185 IntelliJ does not use systemPropertyVariables defined in maven-surefire-plugin configuration and IDEA-122783 Unit test runner ignores maven surefire classpath configuration have been already fixed.
But IDEA still ignores properties from systemPropertiesFile.
I have some Unit tests, that when I try to run, it automatically creates Maven run/debug configuration, instead of JUnit (the integrated IDEA tab).
For some tests it does use JUnit run\debug configuration and manually - I can create both Maven and JUnit.
How do I make JUnit to be the default test runner ?
The problems is that I had maven runner plugin installed, causing all my tests to run with Maven
You can use the maven option "-Dskip=true" to suppress the maven test execution, and you can add your own test configuration to the build process. This screenshot was taken form IntelliJ 15.0.2.
Update: maven option
I'm currently facing severe classpath problems with Jenkins 1.532.2 and Maven 3.0.3. Locally, the classpath order is correct and all JUnit test work. On Jenkins though, the classpath is ordered alphabetically, not like in the pom defined.
Output of mvn dependencies:build-classpath on Jenkins (partly redacted):
axis/axis/1.4/axis-1.4.jar
axis/axis-wsdl4j/1.5.1/axis-wsdl4j-1.5.1.jar
com/company/ownlibrary.jar
com/microsoft/sqljdbc4/3.0/sqljdbc4-3.0.jar
com/oracle/ojdbc6/11.2.0.1.0/ojdbc6-11.2.0.1.0.jar
commons-codec/commons-codec/1.5/commons-codec-1.5.jar
commons-discovery/commons-discovery/0.2/commons-discovery-0.2.jar
commons-lang/commons-lang/2.4/commons-lang-2.4.jar
commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.jar
junit/junit/4.11/junit-4.11.jar
log4j/log4j/1.2.17/log4j-1.2.17.jar
org/apache/axis/axis-jaxrpc/1.4/axis-jaxrpc-1.4.jar
org/apache/axis/axis-saaj/1.4/axis-saaj-1.4.jar
org/apache/poi/poi/3.8/poi-3.8.jar
org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar
org/mockito/mockito-core/1.9.5/mockito-core-1.9.5.jar
org/objenesis/objenesis/1.0/objenesis-1.0.jar
org/slf4j/slf4j-api/1.7.5/slf4j-api-1.7.5.jar
This is the output of mvn dependencies:build-classpath locally executed (partly redacted):
com\oracle\ojdbc6\11.2.0.1.0\ojdbc6-11.2.0.1.0.jar
commons-logging\commons-logging\1.1.1\commons-logging-1.1.1.jar
org\apache\poi\poi\3.8\poi-3.8.jar
commons-codec\commons-codec\1.5\commons-codec-1.5.jar
de\company\xyz.jar
de\company\xyz2.jar
com\company\own.jar
log4j\log4j\1.2.17\log4j-1.2.17.jar
commons-lang\commons-lang\2.4\commons-lang-2.4.jar
com\microsoft\sqljdbc4\3.0\sqljdbc4-3.0.jar
axis\axis\1.4\axis-1.4.jar
org\apache\axis\axis-jaxrpc\1.4\axis-jaxrpc-1.4.jar
org\apache\axis\axis-saaj\1.4\axis-saaj-1.4.jar
axis\axis-wsdl4j\1.5.1\axis-wsdl4j-1.5.1.jar
commons-discovery\commons-discovery\0.2\commons-discovery-0.2.jar
org\slf4j\slf4j-api\1.7.5\slf4j-api-1.7.5.jar
junit\junit\4.11\junit-4.11.jar
org\hamcrest\hamcrest-core\1.3\hamcrest-core-1.3.jar
org\mockito\mockito-core\1.9.5\mockito-core-1.9.5.jar
org\objenesis\objenesis\1.0\objenesis-1.0.jar
I use Maven 3.0.3 so it should use the pom-defined ordering of dependencies.
What can be the source of this problem and how can I solve this?
Additional info: As you can see on the classpath items, I'm building locally on Windows and Jenkins runs on a Linux OS.
New information: The Maven process on Linux also does not work correctly. I tried to build it locally on the machine, on which Jenkins runs, and the result is the same. The classpath is ordered, although I tried Maven 3.0.3 and 3.2.1
Updating Maven to 3.2.1 helped with the sorting classpath, but not the classpath problem. The classpath is not sorted anymore on Jenkins, but the resources are loaded in a false order nonetheless.
IMHO, class path order should not matter. If you have issues, it means you are loading more than one version of the same jar. You should not rely on class path order.
You should understand why it happens and if you cannot avoid it, use the mvn dependency:tree to figure out where the "bad" jar is coming from, and add an exclude in the dependency that's responsible for it.
I hope this helps.
my junit test are passing when i am running
mvn test
but
mvn emma:emma
it has errors.
How can i find out which classes are executed?
The errors that i have are related to spring
java.lang.NoSuchMethodError: org.springframework.beans.BeanUtils.instantiateClass(Ljava/lang/Class;Ljava/lang/Class;)Ljava/lang/Object;
at org.springframework.test.context.ContextLoaderUtils.resolveContextLoader(ContextLoaderUtils.java:87)
since the same config is working fine, i think that there are some problems with the classpath when i run emma.
Any advice is apreciated,
10x
Your spring-test version disagrees with your spring-beans version. Use mvn dependency:tree to find what's pulling in the relevant versions and use explicit top-level dependencies or dependency exclusions to manage them.
I am working on a simple multi module maven project under Eclipse using m2eclipse with maven 3 and jetty plugin version 7. One of my module is a jar and the other module is a war which has a dependency on the jar.
Even though the workspace dependency resolution is enabled, the call to mvn jetty:run fails if I don't run mvn install before.
Having read about workspace dependency, I am not sure why a call to mvn install is required. I would like to be able to run the jetty plugin without installing the artifacts to my local repository. Is it possible?
Thanks in advance.
There is an integration module between m2eclipse and the WTP (Web Tool Platform).
WTP allow starting Jetty/Tomcat/... from Eclipse, debugging inside Eclipse, redeploy on change,...
Here is it: m2eclipse Extras