1

我的应用程序依赖于第三方耳朵(它解构它,添加/修改其中的一些项目,并将其重构为新耳朵)。第三方耳朵必须使用第三方构建脚本来构建。

我正在尝试学习设置它的“maven-y”方式。我希望我需要将第三方 ear 安装到我的存储库中。

我想为第三方耳朵创建一个 pom.xml,它将构建第三方耳朵并安装/部署它。我创建了一个 pom.xml,它成功调用了第三方构建脚本(通过 maven-antrun-plugin),并在默认的 maven ear 项目所在的位置创建了 ear。

我的问题是 maven 的安装插件失败,因为它找不到存档(它希望打包的任何插件都在工件对象上设置了一个属性,而 maven-antrun-plugin 没有这样做)。

mvn package工作正常并生成耳朵。

运行时的确切错误消息mvn install如下所示:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.3.1:install (default-install) on project third_party_ear: The
packaging for this project did not assign a file to the build artifact -> [Help 1]

有没有更好的方法来解决这个问题?

<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>com.thirdparty</groupId>
    <artifactId>third_party_ear</artifactId>
    <version>9.0</version>
    <packaging>ear</packaging>

    <name>third_party_ear</name>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-ear-plugin</artifactId>
                <version>2.6</version>
                <executions>
                    <execution>
                        <id>default-ear</id>
                        <phase>none</phase>
                    </execution>
                    <execution>
                        <id>default-generate-application-xml</id>
                        <phase>none</phase>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.7</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <configuration>
                            <target>
                                <subant target="build-ear" antfile="build.xml" buildpath="${project.basedir}"/>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>
4

1 回答 1

2

When you specify <packaging>ear</packaging> you are telling Maven to invoke the full lifecycle specified for that packaging.

In your case what you want to do is write a wrapper pom.xml that just shells out to your 3rd party build script without invoking the EAR lifecycle and attach the produced artifact to Maven's reactor...

Something like this should work

<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>com.thirdparty</groupId>
    <artifactId>third_party_ear</artifactId>
    <version>9.0</version>
    <packaging>pom</packaging>

    <name>third_party_ear</name>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.7</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <configuration>
                            <target>
                                <subant target="build-ear" antfile="build.xml" buildpath="${project.basedir}"/>
                                <attachartifact file="${project.build.directory}/${project.build.finalName}.ear" type="ear"/>
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

There may be some slight glitches because the pom's packaging differs... but as this is not a classpath relevant artifact they shouldn't affect you.

Note the attachartifact ANT task can attach an artifact from anywhere, so you need not have battled ANT to get the file in the "right" place... though it is nicer to follow that convention. You may want to not use the project.build.finalName and hardcode the filename.

于 2012-10-30T19:13:37.643 回答