Maven 尝试两次部署同一个工件

Era*_*tes 2 java maven

我正在使用 Maven 来构建我的项目,但是当我运行命令时mvn clean package deploy,它会尝试部署工件两次。我将 build-helper-maven-plugin 插件配置为附加我使用自定义插件创建的 ear 文件。

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.9.1</version>
            <executions>
                <execution>
                    <id>attach-artifacts</id>
                    <phase>package</phase>
                    <goals>
                        <goal>attach-artifact</goal>
                    </goals>
                    <configuration>
                        <artifacts>
                            <artifact>
                                <file>${project.build.directory}/${project.artifactId}-${project.version}.ear</file>
                                <type>ear</type>
                            </artifact>
                        </artifacts>
                    </configuration>
                </execution>
            </executions>
        </plugin>
Run Code Online (Sandbox Code Playgroud)

当我禁用 build-helper-maven-plugin 时,剩余的工件(仅 pom)仅上传一次。

我应该怎么做才能让 Maven 只部署一次额外的 ear 文件?

埃特斯

编辑

<?xml version="1.0" encoding="UTF-8"?>
<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>my.group.id</groupId>
    <artifactId>my.artifact.id</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>pom</packaging>

    <name>My Project</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <scm>
        <!-- Config -->
    </scm>

    <distributionManagement>
        <repository>
            <!-- Config -->
        </repository>
        <snapshotRepository>
            <!-- Config -->
        </snapshotRepository>
    </distributionManagement>

    <dependencies>
        <!-- My Dependencies here -->
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <version>2.9</version>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}</outputDirectory>
                            <overWriteReleases>false</overWriteReleases>
                            <overWriteSnapshots>false</overWriteSnapshots>
                            <overWriteIfNewer>true</overWriteIfNewer>
                            <includeGroupIds>my.group.ids.that.need.to.be.included</includeGroupIds>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>my.group.id</groupId>
                <artifactId>my.custom.plugin</artifactId>
                <version>1.0.1</version>
                <configuration>
                    <params>
                        <!-- My params -->
                    </params>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>my-custom-goal</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <!-- Release Plugin -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <goals>clean package deploy</goals>
                    <tagBase>https://my.tagbase</tagBase>
                </configuration>
            </plugin>

            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>build-helper-maven-plugin</artifactId>
                <version>1.9.1</version>
                <executions>
                    <execution>
                        <id>attach-artifacts</id>
                        <phase>package</phase>
                        <goals>
                            <goal>attach-artifact</goal>
                        </goals>
                        <configuration>
                            <artifacts>
                                <artifact>
                                    <file>${project.build.directory}/${project.artifactId}-${project.version}.ear</file>
                                    <type>ear</type>
                                </artifact>
                            </artifacts>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <modules>
        <!-- My Modules -->
    </modules>
</project>
Run Code Online (Sandbox Code Playgroud)

khm*_*ise 7

首先,您正在使用模块并尝试在您的父 pom(依赖插件、构建助手等)中做一些奇怪的事情。在父级中,永远不应该像在 pom.xml 中那样执行。您应该在适当的模块中进行适当的配置/执行,因为此定义将被所有子项继承。

您想创建一个耳朵文件吗?比你应该使用打包ear,你的耳朵文件将简单地通过使用mvn deploy.

此外,如果您致电,您似乎误解了生命周期原因:

mvn clean package deploy
Run Code Online (Sandbox Code Playgroud)

这可以简化为:

mvn clean deploy
Run Code Online (Sandbox Code Playgroud)

因为包生命周期是部署的一部分,所以我建议阅读生命周期信息。