首页 文章

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

提问于
浏览
1

我正在使用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

EDIT

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

  • 4

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

    你想创建一个ear文件吗?你应该使用包装 ear ,你的耳朵文件只需使用 mvn deploy 进行部署 .

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

    mvn clean package deploy
    

    这可以简化为:

    mvn clean deploy
    

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

相关问题