maven - 排除从父 POM 继承的 Artifact ?

标签 maven maven-3 maven-plugin

我的项目 B 继承自项目 A。在项目 A 中,我必须将从 Maven 下载的 jar 文件复制到 lib 文件夹中。项目A的pom文件:

<groupId>com.penguin.com.projecta</groupId>
<artifactId>penguin-common--pom</artifactId>
<packaging>pom</packaging>
<version>${com.penguin.common.projecta}</version>
<name>Penguin COMMON POM</name>

<modules>
    <module>projectb</module>
</modules>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-jars</id>
                    <phase>process-sources</phase>
                    <goals>
                        <goal>copy</goal>
                    </goals>
                    <configuration>
                        <overWriteIfNewer>true</overWriteIfNewer>                
                        <artifactItems>
                            <artifactItem>
                                <groupId>ant-contrib</groupId>
                                <artifactId>ant-contrib</artifactId>
                                <version>1.1</version>
                                <type>jar</type>
                                <destFileName>ant-contrib.jar</destFileName>
                                <outputDirectory>lib</outputDirectory>
                            </artifactItem>
                        </artifactItems>
                    </configuration>
                </execution>
            </executions>
        </plugin>        
    </plugins>
</build>

当我构建时,maven 将 jar 文件复制到 lib 文件夹,但它还在项目 B 中创建 lib 文件夹,并将项目 A 的 pom 文件中定义的 jar 文件复制到其中。现在我想在项目 B 中排除它。我尝试使用下面的脚本,但它不起作用。

<dependencies>
    <dependency>
        <groupId>com.penguin.com.projecta</groupId>
        <artifactId>penguin-common--pom</artifactId>
        <version>${com.penguin.common.projecta}</version>
        <type>pom</type>
        <exclusions>
            <exclusion>
                <groupId>ant-contrib</groupId> 
                <artifactId>ant-contrib</artifactId>                        
            </exclusion>
        </exclusions>
    </dependency>
</dependencies>

我引用了这个链接:Is there anyway to exclude artifacts inherited from a parent POM? .但这对我也没有帮助。

最佳答案

虽然我怀疑你的项目结构是否正确(我想不出一个父 pom 应该复制依赖项的好例子......),但你可能正在寻找 inherited -标签

关于maven - 排除从父 POM 继承的 Artifact ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18297797/

相关文章:

maven-2 - Maven插件无法加载类

eclipse - Eclipse 中的 Wildfly 正在将 Maven SNAPSHOT 添加到 Web 上下文

maven 用 jar 和更多文件创建 zip

Maven 依赖插件在构建类路径和树之间的排序差异

java - Maven : what does "build life cycle mapping" mean

java - Spring boot (Maven) 运行时未找到外部 jar 类

maven 原型(prototype) :generate failure caused by org. apache.maven.plugin.MojoFailureException

java - 使用maven使jar成为jsf中的自定义组件

java - Maven 无法识别 pom.xml 中的 'configuration' 标记

java - maven project 和 sbt project and play framework 是否考虑共享一个存储库?