sof
sof

Reputation: 9649

Use side-by-side lib versions by Maven

Below is the rough version of my POM,

<project>

    <dependencies>
        <dependency>one-java-artifact-version-X</dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <dependencies>
                    <dependency>one-java-artifact-version-Y</dependency>
                </dependencies> 
            </plugin>
        </plugins>
    </build>

</project>

I want the plugin to use one-java-artifact-version-Y but other things to use one-java-artifact-version-X. Is it possible to use different versions of a java artifact side-by-side with Maven? Specially, how to deal with the situation above?

@EDIT

In my case with Maven 3.0.4, one-java-artifact-version-Y is always shadowed by one-java-artifact-version-X, so the plugin fails to execute because of the undesirable dependency on one-java-artifact-version-X instead. However, the plugin works while other things mess up after one-java-artifact-version-Y being promoted to a global dependency below,

<project>

    <dependencies>

        <dependency>one-java-artifact-version-Y</dependency>

        <dependency>one-java-artifact-version-X</dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
            </plugin>
        </plugins>
    </build>

</project>

Upvotes: 1

Views: 105

Answers (1)

mtk
mtk

Reputation: 13709

Not sure, if that is possible in this case (i.e. one conflicting with the plugin version), but with respect to regular dependency management (i.e. between 2 dependencies using 2 different versions), maven documentation says,

"nearest definition" means that the version used will be the closest one to your project in the tree of dependencies, eg. if dependencies for A, B, and C are defined as A -> B -> C -> D 2.0 and A -> E -> D 1.0, then D 1.0 will be used when building A because the path from A to D through E is shorter. You could explicitly add a dependency to D 2.0 in A to force the use of D 2.0

Upvotes: 1

Related Questions