Getting all Maven artifacts from Hudson
I have a Maven project that is a child project. It has many sibling projects and the job of this project is to get resources from the siblings and package them in a zip file using the antrun plugin.
<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>
开发者_Go百科 <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>
This worked fine for building the zip. However, the problem is that the zip is not the artifact of the build. And, thus there is no link in Hudson to download it.
I would either like to figure out how to get Hudson to recognize this as an artifact of Maven, or get Maven to realize that the ZIP is the artifact. (I used to have packaging element missing and then I would get an unwanted JAR as artifact).
You can use 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>
The Build Helper Maven Plugin (attach-artifact goal) will tell maven that a particular file should be added to maven's list of artifacts for that project. Setting the packaging to "pom" is the correct thing to do in this situation.
Note that if you are running the "install" goal, then your zip file will also be copied to the local maven repository, but it will be renamed according to maven conventions. Just something to be aware of, if you have downstream builds depending on this artifact.
精彩评论