繁体   English   中英

Maven不会在复制依赖期间排除

[英]Maven won't exclude during copy-dependencies

我有一个使用Netty 4.0.29的项目,我有另一个依赖于netty 3.9.0的依赖项。 我进行了排除但是当我运行copy-dependencies时它仍然在3.9.0中使用。

    <dependency>
        <groupId>com.ning</groupId>
        <artifactId>async-http-client</artifactId>
        <version>1.9.31</version>
        <exclusions>
            <exclusion>
                <groupId>io.netty</groupId>
                <artifactId>netty</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

如果我运行mvn依赖:树有这个排除,我发现它确实被排除在外:

[INFO] +- com.ning:async-http-client:jar:1.9.31:compile

但是当我运行mvn clean依赖:copy-dependencies时,我看到jar 3.9.0与4.0.29一起被复制。 根据文档和Google,在排除时不应复制。

[INFO] Copying netty-3.9.0.Final.jar to /Users/udonom1/wk/141/coursecopy-api/target/dependency/netty-3.9.0.Final.jar
[INFO] Copying netty-all-4.0.29.Final.jar to /Users/udonom1/wk/141/coursecopy-api/target/dependency/netty-all-4.0.29.Final.jar

我按照下面第一个答案的建议尝试排除,但是没有用。

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.1</version>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>process-sources</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>                               <outputDirectory>${project.build.directory}/lib</outputDirectory>
                        <overWriteReleases>false</overWriteReleases>
                        <overWriteSnapshots>false</overWriteSnapshots>
                        <overWriteIfNewer>true</overWriteIfNewer>
                        <excludeArtifactIds>io.netty:netty:3.9.0.Final</excludeArtifactIds>
                    </configuration>
                </execution>
            </executions>
        </plugin>

我还添加了一个依赖项,如进一步建议:

    <dependency>
        <groupId>io.netty</groupId>
        <artifactId>netty-all</artifactId>
        <version>4.0.29.Final</version>
    </dependency>

我究竟做错了什么?

对于那些有同样问题的人。 我使用mvn -X并发现依赖:tree省略了另外两个引用netty的jar。 我为那些人添加了排除项目,我很高兴。 花了一整天的时间。

如果您正在编写非库,则可以通过简单的方法来控制项目中任何依赖项的版本 - 根目录文件中的dependencyManagement块,例如:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>io.netty</groupId>
            <artifactId>netty</artifactId>
            <version>4.0.29.Final</version>
        </dependency>
    </dependencies>
</dependencyManagement>

来自此块的额外奖励 - 您可以省略具体依赖关系中的依赖关系的版本和范围(具有相同的组ID,工件ID和包装)。

PS另外看看你的依赖关系让我问你:你确定这个依赖有单个maven工件id吗? netty-all-4.0.29.Final.jar - 似乎这个工件应该有netty-all artifact id ...如果他们有不同的工件id,我的配方就无济于事了。 在这种情况下,您应该为maven-dependency-plugin定义构建配置,例如:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.10</version>
            <configuration>
                <excludeArtifactIds>io.netty:netty:3.9.0.Final</excludeArtifactIds>
            </configuration>
        </plugin>
    </plugins>
</build>

或者只是在你的maven调用中使用-DexcludeArtifactIds参数

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM