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

只愿长相守 提交于 2019-11-30 02:27:36
Justin Garrick

The solution that worked for me (I'm not sure if it is ideal, it seems rather hackish) was to switch to the deploy:deploy-file goal:

<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 invoke it explicitly:

mvn -U -X -pl projectname clean install deploy:deploy-file

The solution worked for me is to add the <attachartifact> tag after zip creation, filled with the same path and zip filename . 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 has to exists, otherwise attachartifact returns "file does not exists" error (consider to use whenempty="create" in tag in order to avoid errors).

While looking for a way to add comment to a zip file I found this question. The deploy worked fine but had troubles with the maven release to post into nexus. The solution below solved my problem, I made an empty zip assembly and then simply replaced it with the zip file from the ant task which allowed me to add the comment to the zip file. This way the artifact is generated and 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>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!