Maven Transitive Dependency问题

时间:2012-04-02 10:58:50

标签: maven transitive-dependency

在构建我的项目时,有两个版本的org.bouncy-castle:bcprov required

  • org.bouncy-castle:bcprov-jdk12
  • org.bouncy-castle:bcprov-jdk16

因此,在列出依赖关系时,我将获得 jdkversion12

有没有办法以首先列出jdkversion16的方式修改POM文件?

1 个答案:

答案 0 :(得分:3)

您可以通过像这样指定依赖项来排除依赖项 - 在您的情况下,您将排除jdk12一个:

    <dependency>
            <groupId>group</groupId>
            <artifactId>artifact</artifactId>
            <version>1.0.0</version>
            <exclusions>
                    <exclusion>
                            <groupId>org.bouncycastle</groupId>
                            <artifactId>bcprov-jdk12</artifactId>
                    </exclusion>
            </exclusions>
    </dependency>

这样,只应引入jdk16

如果您需要根据您正在构建的位置和安装的JDK版本拉入其中一个,您可以使用配置文件来区分,例如:像这样:

<profile>
    <id>jdk12</id>
    <activation>
        <activeByDefault>true</activeByDefault>
        <jdk>1.2</jdk>
    </activation>
    <dependencies>
        <dependency>
            <groupId>group</groupId>
            <artifactId>artifact</artifactId>
            <version>1.0.0</version>
            <exclusions>
                <exclusion>
                    <groupId>org.bouncycastle</groupId>
                    <artifactId>bcprov-jdk16</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
</profile>
<profile>
    <id>jdk16</id>
    <activation>
        <jdk>1.6</jdk>
    </activation>
    <dependencies>
        <dependency>
            <groupId>group</groupId>
            <artifactId>artifact</artifactId>
            <version>1.0.0</version>
            <exclusions>
                <exclusion>
                    <groupId>org.bouncycastle</groupId>
                    <artifactId>bcprov-jdk12</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
</profile>

示例摘自:http://svn.apache.org/repos/asf/webservices/wss4j/trunk/pom.xml