Maven尝试两次部署相同的工件

时间:2015-05-22 08:18:14

标签: 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>

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

如何让Maven只部署额外的ear文件一次?

Erates

修改

<?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>

1 个答案:

答案 0 :(得分:4)

首先,您正在使用模块并尝试在父pom中执行奇怪的操作(dependency-plugin,build-helper等)。在父母身上,永远不应该像你在pom中那样执行。您应该在相应的模块中进行适当的配置/执行,因为这个定义将继承所有子项。

您要创建一个ear文件吗?您应该使用打包ear,而只使用mvn deploy部署您的ear文件。

此外,如果你打电话,你似乎误解了生命周期的原因:

mvn clean package deploy

这可以简化为:

mvn clean deploy

因为软件包生命周期是部署的一部分所以我建议您阅读life cycle信息。