Maven - Different Dependency Version in Test

前端 未结 2 1223
清歌不尽
清歌不尽 2021-01-25 11:19

I\'m suffering an issue similar to Maven 2 - different dependency versions in test and compile but the specified answer there does not work.

In my project I need to depe

相关标签:
2条回答
  • 2021-01-25 11:52

    What you desire, is no longer valid for Maven 3 (this used to be valid for Maven 2). Maven 3 will attempt to obtain the nearest dependency, effectively ensuring that only one of the compile or test scoped dependency is used for both the compile and test phases.

    In your case org.apache.hadoop:hadoop-core:1.0.0:test overrides org.apache.hadoop:hadoop-core:0.20.2-cdh3u2:compile and hence becomes the nearest dependency. You may see the following warning displayed by Maven when running the mvn dependency:list goal, that alludes to this being a problem in your project model:

    [WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.apache.hadoop:hadoop-core:jar -> version 0.20.2-cdh3u2 vs 1.0.0 @ line xyz, column xyz

    To 'fix' this, it would be better to split your tests into a separate project whose project model can define a separate set of test dependencies.

    0 讨论(0)
  • 2021-01-25 11:53

    Looks like a maven bug - or if not, something that is fishy enough I wouldn't trust the documentation if there were any.

    In your case, I would probably:

    1. upgrade maven and see if the issue is fixed in the latest m3
    2. try repackaging one of the hadoop versions with another artifact id or group name. maven-shade-plugin, don't bother changing the package name, but just introduce something maven won't know is no different from org.apache.hadoop:hadoop-core
    3. try moving the tests to a separate project downstream
    4. start debugging maven and understand what's going on exactly (and then fall back on 1 or 2...)
    0 讨论(0)
提交回复
热议问题