Maven emma has error but the tests are passing - maven

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.

Related

maven plugin execution issue

I am using aspectj in a project. when i add the aspectj-maven-plugin to the build, the aspects are woven in and things work as expected. however, i get an error in the POM saying that the plugin execution is not covered by lifecycle configuration.
from what i've read in other problems, it says the solution is to simply wrap the plugin in a pluginManagement tag. that does seem to get rid of the error, however, when i do a mvn clean install, the aspectj plugin no longer runs. any idea on how to solve that problem?

Different classpath between IntelliJ and mvn

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?

How tell to maven don't bring test dependencies

I have Maven dependencies with scope test.
I add flag Dmaven.test.skip=true but Maven still brings test dependencies.
Is there a way not to bring test dependencies if I want to build only the production part?
This is how maven works - it First tries to check that ako dependencies are available, no matter their scope. Only then it continues to test phase to find out that tests should not be executed.
A possible workaround is to define your test dependencies in a separate test maven profile, which is not applied when you do not want to run tests. Profiles are resolved before any dependence are downloaded, therefore if test dependencies are not added by the profile to the effective pom, they are not downloaded at all.
the flag -Dmaven.test.skip will only skip compilation and execution of your tests within the project you run.
Its often better to use -DskipTests as this will compile the test classes but not run them. See surefire documentation.
This has nothing to do with dependencies. Those are loaded into the classpath depending on their scope and what plugins require. The surefire plugin requires resolution of scope test as it runs the unit tests.
If there are dependencies of scope test which you do not want to use you need to remove them or exclude them if they come in via transitive dependencies (dependencies of dependencies). You can execute a mvn dependency:tree to figure out why jar are in the project.
If you add some dependencies for test scope, maven will first check if the dependency is available or not then it checks the scope.
You can create a maven profile, add test dependencies under the profile and trigger the profile when -Dmaven.test.skip or -Dmaven.test.skip=true option is not present. In this way you can keep your build command unchanged.
You can check this simple project manage-test-dependencies-in-maven-the-proper-way to understand it better.

Prevent test errors in 'mvn site' goal with ROME dependency and cobertura-maven-plugin

In a Maven based project some of the JUnit tests fail, but only during a Maven site build. When executing
mvn clean package
all tests pass. But when executing:
mvn clean site
some of the tests generate the message:
Could not initialize class org.jdom2.input.sax.XMLReaders
These errors occur in a class that uses ROME to parse RSS data. For this the project has a dependency on ROME (com.rometools:rome:1.5.0), which itself has a dependency on JDOM 2.0.2.
The errors did not happen when the ROME dependency was not yet included in the project.
The Maven site configuration includes the cobertura-maven-plugin. This also has a dependency on JDOM, through Jaxen: jaxen:jaxen:1.0 -> jdom:jdom:1.0
I think that while executing the site goal the JDOM 1.0 version is used by the class under test, causing the errors in the ROME library because it uses the incorrect JDOM version.
I don't know how to configure the project to use JDOM 1.0 only in the Cobertura plugin. Does anyone know a way to do that and make the tests run successful during the site goal?
The problem was solved by setting a system value during program startup:
System.setProperty("javax.xml.parsers.SAXParserFactory",
"com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl");
Source: JDOM2: This parser does not support specification "null" version "null"

Maven3 - How do I found dependency resolution? ( mvn depedency:tree does not work for mvn3 )

With maven-3, it uses aether to resolve dependency.
Unfortunately, "mvn dependency:tree" use legacy (maven-2) resolution engine.
How do I find out the true dependency resolution for maven-3. I'm running into an issue where "exec:exec" creates different classpath then "dependency:tree".
In maven 3 - compatibility notes, it says I need to use "-X" and look at the log but there is no pointer what to look for.
Also, "assembly:assembly" brings in different 'jar' than when I print out classpath from "exec:exec".
dependency:tree is the correct way to get the project dependencies. Since version 2.5 of the plugin it now resolves the tree using aether.
exec:exec runs the maven exec plugin. The classpath it generates is based on the plugin dependencies, if specified. It is relevant only for the purpose of the plugin execution and not to be taken in the context of project.
The similar explanation holds good in case of assembly:assembly. The jars that it brings in entirely depends on the plugin and assembly-descriptor configuration.
Since version 2.5 of the Maven Dependency Plugin, dependency:tree works with Maven 3 (see the bug report, and the release notes)

Resources