8

我正在使用 maven-antrun-plugin 对 Ant 进行大量工作,最终生成一个 zip 文件。我想将 zip 文件部署到我们的 Maven 服务器(Artifactory)。maven-antrun-portion 按预期工作并成功创建了 zip 文件;但是部署失败并显示以下错误消息:

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

我的POM文件如下:

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

当我(从父 POM)调用它时,mvn -U -pl projectname clean deploy我在部署阶段收到上述错误。有谁知道我做错了什么或如何解决这个问题?

4

3 回答 3

12

对我有用的解决方案(我不确定它是否理想,这似乎相当骇人听闻)是切换到deploy:deploy-file目标:

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

并显式调用它:

mvn -U -X -pl projectname clean install deploy:deploy-file
于 2011-06-22T13:46:02.523 回答
3

对我有用的解决方案是<attachartifact>在创建 zip 后添加标签,填充相同的路径和 zip 文件名。所以像:

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

请记住 zip 文件必须存在,否则attachartifact返回“文件不存在”错误(考虑使用whenempty="create"in 标签以避免错误)。

于 2019-01-18T16:13:32.763 回答
1

在寻找向 zip 文件添加评论的方法时,我发现了这个问题。部署工作正常,但在发布到 nexus 的 maven 版本时遇到了麻烦。下面的解决方案解决了我的问题,我制作了一个空的 zip 程序集,然后简单地将其替换为 ant 任务中的 zip 文件,这使我可以将注释添加到 zip 文件中。通过这种方式,工件是生成的,而不是传递的。

<?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>
于 2018-07-16T21:37:14.517 回答