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

前端 未结 3 1474
梦谈多话
梦谈多话 2020-12-28 10:31

I\'m using the maven-antrun-plugin to do a bunch of work with Ant, which ultimately results in a zip file. I\'d like to deploy the zip file to our maven server (Artifactory

相关标签:
3条回答
  • 2020-12-28 11:15

    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
    
    0 讨论(0)
  • 2020-12-28 11:16

    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).

    0 讨论(0)
  • 2020-12-28 11:19

    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>
    
    0 讨论(0)
提交回复
热议问题