如何跳过maven antrun copy/shade:动态阴影目标?

min*_*ime 4 java maven maven-shade-plugin maven-antrun-plugin maven-lifecycle

我正在使用maven来配置由多个小服务组成的应用程序.在java中开发的大多数服务共享相同的maven配置,就像在相同的构建生命周期中一样,共享资源(如spring AMQP).

所以我在SuperPom中组织了共享资源.

虽然阴影插件似乎并没有真正干扰安装过程,但是antrun插件当然不会找到它应该复制的任何文件,因为没有通过shade插件创建任何jar文件.

由于我想要在SuperPom中抽象出shade/antrun插件的配置,我需要跳过阴影/复制目标.

我已经试过mvn clean install -Dmaven.shade.skip=true,mvn clean install -Dmaven.copy.skip=true,mvn clean install -Dmaven.shade.shade.skip=true

这是一个小样本供您玩:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>Test</groupId>
    <artifactId>SuperTest</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    <properties>
        <log4j.version>1.2.17</log4j.version>
        <destination>pleasedeleteme</destination>
        <mainpackage>com.uk.cc.it.info.gov.test.xxx</mainpackage>
    </properties>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.2</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>${mainpackage}.Main</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.8</version>
                <executions>
                    <execution>
                        <id>copy</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy</goal>
                        </goals>
                        <configuration>
                            <artifactItems>
                                <artifactItem>
                                    <groupId>${groupId}</groupId>
                                    <artifactId>${artifactId}</artifactId>
                                    <version>${version}</version>
                                    <type>jar</type>
                                    <overWrite>true</overWrite>
                                    <outputDirectory>${destination}</outputDirectory>
                                </artifactItem>
                            </artifactItems>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>${log4j.version}</version>
        </dependency>
    </dependencies>

</project>
Run Code Online (Sandbox Code Playgroud)

Kri*_*nck 6

您是否尝试在超级pom中将maven-shade-plugin的阶段设置为none,然后在客户端poms中覆盖它?

所以在父母pom中:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.3</version>
    <executions>
        <execution>
            <id>shade</id>
            <phase>none</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <!-- ... -->
            </configuration>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

在需要它的儿童poms:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <!-- no need to specify version -->
    <executions>
        <execution>
            <id>shade</id>
            <phase>package</phase>
            <!-- no need to specify configuration -->
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)