How can I deploy a zip file created using maven-antrun-plugin?

I use maven-antrun-plugin to do a ton of Ant work, which ultimately leads to the creation of a zip file. I would like to deploy a zip file to our maven server (Artifactory). Maven-antrun-part works as intended and successfully creates the zip file; however, the deployment fails with the following error message:

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.6:deploy (default-deploy) on project projectname: The packaging for this project did not assign a file to the build artifact

My POM file is as follows:

 <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.company.division</groupId> <artifactId>projectname</artifactId> <version>1.0.0-SNAPSHOT</version> <packaging>pom</packaging> <parent> <groupId>com.company.product</groupId> <artifactId>parentproject</artifactId> <version>1.0.0</version> </parent> <distributionManagement> <snapshotRepository> <id>artifactory</id> <name>artifactory-snapshots</name> <url>http://localartifactoryserver/artifactory/libs-snapshot-local</url> <uniqueVersion>false</uniqueVersion> </snapshotRepository> </distributionManagement> <dependencies> <!-- Some dependencies... --> </dependencies> <build> <plugins> <!-- Compiler plugin --> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.6</source> <target>1.6</target> <encoding>UTF8</encoding> <optimize>true</optimize> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.6</version> <executions> <execution> <id>compile</id> <phase>compile</phase> <configuration> <target> <!-- Do lots of other stuff with Ant. --> <!-- Create a zip file. --> <zip basedir="mydir" destfile="${WORKSPACE}/MyZip.zip" /> </target> </configuration> <goals> <goal>run</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> <version>2.6</version> <configuration> <groupId>${project.groupId}</groupId> <artifactId>${project.artifactId}</artifactId> <version>${project.version}</version> <packaging>zip</packaging> <file>MyZip.zip</file> <url>${project.distributionManagement.snapshotRepository.url}</url> </configuration> </plugin> </plugins> </build> </project> 

When I call this (from the parent POM) with mvn -U -pl projectname clean deploy , I get the above error during the deployment phase. Does anyone know what I'm doing wrong, or how can I fix this?

+7
source share
3 answers

The solution that worked for me (I'm not sure if this is perfect, seems pretty hacky) was to go to the deploy:deploy-file target:

 <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> <version>2.6</version> <goals> <goal>deploy-file</goal> </goals> <configuration> <repositoryId>artifactory</repositoryId> <packaging>zip</packaging> <generatePom>true</generatePom> <url>${project.distributionManagement.snapshotRepository.url}</url> <artifactId>${project.artifactId}</artifactId> <groupId>${project.groupId}</groupId> <version>${project.version}</version> <file>${WORKSPACE}/MyZip.zip</file> </configuration> </plugin> 

and call it explicitly:

 mvn -U -X -pl projectname clean install deploy:deploy-file 
+10
source

Looking for a way to add a comment to the zip file, I found this question. The deployment worked fine, but it had problems releasing maven to send to the nexus. The solution below solved my problem, I created an empty zip assembly, and then just replaced it with a zip file from the ant task, which allowed me to add a comment to the zip file. Thus, the artifact is generated, not transitive.

 <?xml version="1.0" encoding="UTF-8"?> <assembly> <id>${project.build.finalName}</id> <formats> <format>zip</format> </formats> <includeBaseDirectory>false</includeBaseDirectory> <fileSets> <fileSet> <directory>${project.build.directory}/MyStuff/emptydir</directory> <outputDirectory></outputDirectory> <useDefaultExcludes>true</useDefaultExcludes> </fileSet> </fileSets> 

  <plugin> <!-- make an assembly (zip the LxBase) for the distribuition --> <artifactId>maven-assembly-plugin</artifactId> <executions> <execution> <id>docs-assembly</id> <phase>package</phase> <configuration> <appendAssemblyId>false</appendAssemblyId> <descriptors> <descriptor>src/main/assembly/assemble.xml</descriptor> </descriptors> </configuration> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.8</version> <executions> <execution> <id>zip-artifacts</id> <phase>package</phase> <goals> <goal>run</goal> </goals> <configuration> <target> <zip destfile="${project.build.directory}/MyStuff-${project.version}.zip" update="true" comment="This is my comment..."> <fileset dir="${project.build.directory}/MyStuff" /> </zip> </target> </configuration> </execution> </executions> </plugin> 
+1
source

The solution that worked for me is to add <attachartifact> after creating the zip, populated with the same path and zip file name. So something like:

  <executions> <execution> <id>zip-artifacts</id> <phase>package</phase> <goals> <goal>run</goal> </goals> <configuration> <target> <zip destfile="${project.build.directory}/MyStuff-${project.version}.zip" update="true" comment="This is my comment..."> <fileset dir="${project.build.directory}/MyStuff" /> </zip> <attachartifact file="${project.build.directory}/MyStuff-${project.version}.zip" type="zip" /> </target> </configuration> </execution> </executions> 

Remember that the zip file must exist, otherwise attachartifact returns attachartifact "the file does not exist" (consider using whenempty="create" to avoid errors).

0
source

All Articles