【问题标题】:Getting all Maven artifacts from Hudson从 Hudson 获取所有 Maven 工件
【发布时间】:2009-11-17 23:46:46
【问题描述】:

我有一个 Maven 项目,它是一个子项目。它有许多同级项目,这个项目的工作是从同级项目中获取资源并使用 antrun 插件将它们打包成一个 zip 文件。

<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/maven-v4_0_0.xsd">
    <parent>
        <artifactId>SystemOfRegistries</artifactId>
        <groupId>someGroup</groupId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
    <groupId>someGroup</groupId>
    <artifactId>deploy-data</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>pom</packaging>
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <configuration>
                            <tasks>
                                <!--
                                    Place any Ant task here. You can add anything you can add
                                    between <target> and </target> in a build.xml.
                                -->
                                <zip destfile="${project.build.directory}/${build.finalName}.zip"
                                    whenempty="fail">
                                    <zipfileset dir="${project.parent.basedir}/build/AG" prefix="ag"/>
                                </zip>
                            </tasks>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

这对于构建 zip 非常有效。但是,问题在于 zip 不是构建的工件。而且,因此在 Hudson 中没有下载链接。

我想弄清楚如何让 Hudson 将其识别为 Maven 的工件,或者让 Maven 意识到 ZIP 工件。 (我曾经缺少包装元素,然后我会得到一个不需要的 JAR 作为工件)。

【问题讨论】:

    标签: maven-2 ant hudson maven-plugin


    【解决方案1】:

    你可以使用builder-helper-maven-plugin

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>1.3</version>
        <executions>
            <execution>
                <id>attach-artifacts</id>
                <phase>package</phase>
                <goals>
                    <goal>attach-artifact</goal>
                </goals>
                <configuration>
                    <artifacts>
                        <artifact>
                            <file>${project.build.directory}/${build.finalName}.zip</file>
                            <type>zip</type>
                        </artifact>
                    </artifacts>
                </configuration>
            </execution>
        </executions>
    </plugin>
    

    【讨论】:

      【解决方案2】:

      Build Helper Maven 插件 (attach-artifact goal) 将告诉 maven 应将特定文件添加到该项目的 maven 工件列表中。在这种情况下,将包装设置为“pom”是正确的做法。

      请注意,如果您正在运行“安装”目标,那么您的 zip 文件也将被复制到本地 maven 存储库,但将根据 maven 约定重命名。如果您有依赖此工件的下游构建,请注意一些事情。

      【讨论】:

      • 感谢您的回答。由于我使用${project.build.directory}/${build.finalName}.zip 作为工件名称,并且由于我没有覆盖默认的finalName,因此生成的工件名称与maven insall 的名称相同。我猜 maven 看到标准的 maven 命名约定已经在工件上,并且不会尝试第二次使用它们。
      猜你喜欢
      • 2017-05-02
      • 2011-09-15
      • 2011-06-24
      • 2023-03-10
      • 2011-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-29
      相关资源
      最近更新 更多