I'm trying to move out jmockit-coverage-0.994.jar dependency from the project to some profile not active by default, but cannot insert it to the beginning of result classpath from the profile dependencies.
views:
45answers:
4Is it possible to insert module dependency to the beginnig of the classpath in some maven profile?
Beginning with version 2.0.9 Maven orders your dependencies in the same way they are listed in your pom. That being said, once you start merging dependencies in from profiles it all becomes non-trivial. You might want to check your effective pom to see how the order looks:
mvn help:effective-pom -Pprofile
If it comes out badly then one way around would be to use the dependency:build-classpath. Another solution would be to use scopes instead of profiles to perform the inclusion.
Starting with Maven 2.0.9, the natural order of dependencies is indeed preserved when building the classpath as mentioned in the release notes of 2.0.9:
MNG-1412 / MNG-3111 introduced deterministic ordering of dependencies on the classpath. In the past, natural set ordering was used and this lead to odd results. The ordering is now preserved from your pom, with dependencies added by inheritence added last. In builds that had conflicting or duplicate dependencies, this may introduce a change to the output. In short, if you have weird issues with 2.0.9, take a look at the dependencies to see if you have conflicts somewhere.
So by playing on the order of dependencies in the POM, you can actually manipulate the classpath (this may become a bit more tricky when playing with profiles but, as you didn't provide details on the actual problem, it's hard to give more guidance).
I have rolled back the hack which using active profile above, because found more elegant way to solve my problem.
Source of the problem was transitive dependency due using of some my testutils module with compile scope dependency on JUnit (which have to be after JMockit in classpath), while in the parent POM test dependencies was defined as bellow:
...
<dependencies>
<dependency>
<groupId>mockit</groupId>
<artifactId>jmockit</artifactId>
<version>0.994</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
</dependencies>
...
<profiles>
<profile>
<id>coverage</id>
<dependencies>
<dependency>
<groupId>mockit</groupId>
<artifactId>jmockit-coverage</artifactId>
<version>0.994</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
...
The found solution was replacing JUnit scope from test to provided.
Is it better trick?
Sorry for to many answers on own question...
But now no need any trick with maven deps, because running of jmockit-coverage now can be configured by system property. See release notes of 0.955 version and related issue 22.