views:

45

answers:

4

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.

+1  A: 

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.

Lars Tackmann
Lot of thanks! Your answer help me find following W/A quicker:I have moved list of dependencies from the project to the profile active by default ('nexus' in my case) and copied the same list to the 'coverage' profile but with the required dependency inserted in the beginning:
Andriy Plokhotnyuk
<dependencies><!-- Empty to allow insert the jmockit-coverage dependency to the beginning of the classpath list --></dependencies><profiles><profile><id>coverage</id><dependencies><dependency><groupId>mockit</groupId><artifactId>jmockit-coverage</artifactId><version>0.994</version></dependency><!-- List of other dependencies --></dependencies></profile><profile><id>nexus</id><dependencies><!-- List of other dependencies --></dependencies></profile></profiles>
Andriy Plokhotnyuk
But more convenient method to arrange position of dependencies in the classpath will be greatly appreciated to resolve this kind of issues.
Andriy Plokhotnyuk
The better solution would be moving coverage building to the site reporting lifecycle, but I don't know how...
Andriy Plokhotnyuk
+1  A: 

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).

Pascal Thivent
A: 

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?

Andriy Plokhotnyuk
A: 

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.

Andriy Plokhotnyuk