【问题标题】:Maven: The packaging for this project did not assign a file to the build artifactMaven:此项目的打包未将文件分配给构建工件
【发布时间】:2011-09-12 14:00:34
【问题描述】:

我在 Mac 10.6.6 上使用 Maven 3.0.3。我有一个 JAR 项目,当我运行命令“mvn clean install:install”时,出现错误,

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.3.1:install (default-cli) on project StarTeamCollisionUtil: The packaging for this project did not assign a file to the build artifact -> [Help 1]

这是什么意思,我该如何解决?下面是我的 pom.xml。让我知道还有哪些其他信息会有所帮助,我会编辑这篇文章。谢谢, - 戴夫

<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.myco.starteam.util</groupId>
<artifactId>StarTeamCollisionUtil</artifactId>
<packaging>jar</packaging>
<name>StarTeam Collision Util</name>
<description>
    The StarTeam Collision Utility provides developers and release engineers alike the ability to
    compare files attached to a set of CRs to see if conflicts exist in the change set.
</description>
<version>1.0-SNAPSHOT</version>
<url>http://cm-build.myco.com:8080/hudson/view/Tools/job/StarTeamCollisionUtil - TRUNK/</url>
<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repositories>
    <repository>
        <id>myco-sonatype-nexus-snapshots</id>
        <name>MyCo Sonatype-Nexus Snapshots</name>
        <url>http://sonatype.myco.com/nexus/content/repositories/snapshots/</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>starteam</groupId>
        <artifactId>starteam</artifactId>
        <version>1.1.0</version>
        <type>jar</type>
        <scope>system</scope>
        <systemPath>${basedir}/lib/starteam110.jar</systemPath>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.2</version>
    </dependency>
    <dependency>
        <groupId>org.apache.ant</groupId>
        <artifactId>ant</artifactId>
        <version>1.8.1</version>
    </dependency>
    <dependency>
        <groupId>javax.mail</groupId>
        <artifactId>mail</artifactId>
        <version>1.4.1</version>
        <type>jar</type>
        <scope>compile</scope>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.8.1</version>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-site-plugin</artifactId>
            <version>3.0-beta-3</version>
            <configuration>
                <reportPlugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-report-plugin</artifactId>
                        <version>2.5</version>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-javadoc-plugin</artifactId>
                        <version>2.7</version>
                        <configuration>
                            <linksource>true</linksource>
                        </configuration>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-jxr-plugin</artifactId>
                        <version>2.2</version>
                    </plugin>
                    <plugin>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>versions-maven-plugin</artifactId>
                        <version>1.2</version>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-project-info-reports-plugin</artifactId>
                        <version>2.3.1</version>
                        <reportSets>
                            <reportSet>
                                <reports>
                                    <report>index</report>
                                    <report>dependencies</report>
                                    <report>dependency-management</report>
                                    <report>cim</report>
                                    <report>issue-tracking</report>
                                    <report>license</report>
                                    <report>scm</report>
                                </reports>
                            </reportSet>
                        </reportSets>
                    </plugin>
                </reportPlugins>
            </configuration>
        </plugin>
    </plugins>
</build>
<distributionManagement>
    <repository>
        <id>sonatype-nexus</id>
        <url>http://sonatype.myco.com/nexus/content/repositories/snapshots/</url>
    </repository>
</distributionManagement>
<scm>
    <url>https://starteam.cmass.myco.com/BorlandStarTeam/BorlandStarTeam.jsp</url>
</scm>
<issueManagement>
    <system>StarTeam</system>
    <url>https://starteam.cmass.myco.com/BorlandStarTeam/BorlandStarTeam.jsp</url>
</issueManagement>
<ciManagement>
    <system>Hudson</system>
    <url>http://cm-build.myco.com:8080/hudson/</url>
</ciManagement>
</project>

【问题讨论】:

    标签: maven maven-3 pom.xml maven-jar-plugin maven-install-plugin


    【解决方案1】:

    我不知道这是否是答案,但它可能会引导你走向正确的方向......

    install:install 命令实际上是maven-install-plugin 上的一个目标。这与install maven 生命周期阶段不同。

    Maven lifecycle phases 是某些插件可以绑定到的构建中的步骤。当您调用单个生命周期阶段时,可能会执行来自不同插件的许多不同目标。

    这归结为命令...

    mvn clean install
    

    不同于...

    mvn clean install:install
    

    前者将在安装之前并包括安装(如编译、打包、测试等)的每个周期中运行所有目标。后者甚至不会编译或打包您的代码,它只会运行那个目标。看看异常,这有点道理;它谈到:

    StarTeamCollisionUtil:此项目的打包未将文件分配给构建工件

    尝试前者,您的错误可能会消失!

    【讨论】:

    • 我正在通过 Bamboo 运行,但我没有看到任何内容 mvn install:install any where in config
    【解决方案2】:

    TL;DR 要解决此问题,请在之前调用打包插件,例如对于 jar 包装使用 maven-jar-plugin ,如下:

    mvn jar:jar install:install
    

    或者

    mvn jar:jar deploy:deploy 
    

    如果您确实需要部署。

    Gotcha 如果您的多模块项目具有不同的包装(ear/war/jar/zip),这种方法将不起作用 - 更糟糕的是,将安装/部署错误的工件!在这种情况下,使用 reactor 选项仅构建可部署模块(例如 war)。


    说明

    在某些情况下,您实际上想直接运行 install:installdeploy:deploy 目标(即,来自 maven-deploy-plugindeploy 目标,而不是 Maven deploy phase)以烦人的The packaging for this project did not assign a file to the build artifact告终。

    一个典型的例子是 CI 作业(例如 Jenkins 或 Bamboo 作业),您希望在不同的步骤中执行/关注不同的方面:

    • 第一步是mvn clean install,执行测试和测试覆盖率
    • 第二步是基于质量概况的 Sonarqube 分析,例如mvn sonar:sonar 以及更多选项
    • 然后,只有在成功执行测试并通过质量门之后,您才希望将最终项目工件部署到您的 Maven 企业存储库,但您不想重新运行 mvn deploy,因为它会再次执行之前的阶段(以及编译、测试等),并且您希望构建有效但又快速

    是的,您可以加快最后一步,至少跳过测试(编译和执行,通过-Dmaven.test.skip=true)或使用特定配置文件(跳过尽可能多的插件),但它更容易和清晰只需运行mvn deploy:deploy 然后。

    但它会因上述错误而失败,因为还指定了by the plugin FAQ:

    在打包阶段,所有内容都被收集并放置在上下文中。通过这种机制,Maven 可以确保maven-install-pluginmaven-deploy-plugin 正在复制/上传同一组文件。所以当你只执行deploy:deploy 时,上下文中没有任何文件,也没有什么可部署的。

    确实,deploy:deploy 需要一些运行时信息,这些信息由之前的阶段(或之前的插件/目标执行)放置在构建上下文中。

    它还报告了一个潜在的错误:MDEPLOY-158: deploy:deploy 不适用于仅将工件部署到 Maven 远程仓库

    但后来因为没有问题而被拒绝。

    maven-deploy-plugindeployAtEnd 配置选项在某些情况下也无济于事,因为我们需要执行中间作业步骤:

    每个项目是否应在其自己的部署阶段或多模块构建结束时进行部署。如果设置为 true 并且构建失败,则不会部署任何反应器项目。 (实验性)

    那么,如何解决呢?
    只需在类似的第三步/最后一步中运行以下命令:

    mvn jar:jar deploy:deploy
    

    maven-jar-plugin 不会在构建过程中重新创建任何 jar,这要归功于其 forceCreation 选项默认设置为 false

    要求 jar 插件构建一个新的 JAR,即使内容似乎都没有改变。默认情况下,此插件会查看输出 jar 是否存在并且输入是否未更改。如果这些条件为真,插件将跳过 jar 的创建。

    但它会很好地为我们填充构建上下文并让deploy:deploy 开心。无需跳过测试,无需添加配置文件。正是您所需要的:速度。


    附加说明:如果您使用build-helper-maven-pluginbuildnumber-maven-plugin 或任何其他类似插件来生成稍后由maven-jar-plugin 使用的元数据(例如清单文件的条目),您很可能会被处决链接到validate 阶段,您仍然希望在jar:jar 构建步骤期间拥有它们(但要保持快速执行)。在这种情况下,几乎无害的开销是调用validatephase,如下所示:

    mvn validate jar:jar deploy:deploy
    

    另外一个注意事项:如果您没有jar,而是war 打包,请在安装/部署之前使用war:war

    Gotcha 如上所述,检查多模块项目中的行为。

    【讨论】:

    • 遇到了这个确切的场景。写得很棒 - 应该在部署插件常见问题解答中,而不是相当简洁的“你不能那样做”的解释。
    • 谁会想到 jar jar 会有用 ;)
    • 查看我的多模块项目解决方案:stackoverflow.com/a/57824874/318174
    • 很好的解释。用我的 Jenkins 服务器准确描述了我的场景。
    • 花了几个小时研究这个,没有运气,这个答案完美地描述了每一个细节。感谢您的精彩总结。
    【解决方案3】:

    此回复是针对一个非常古老的问题,以帮助其他面临此问题的人。

    我在使用 IntelliJ IDEA IDE 处理我的 Java 项目时遇到了这个失败的错误。

    Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.4:install (default-cli) on project getpassword: The packaging for this project did not assign a file to the build artifact
    

    当我在Plugins - install 下选择install:install 时发生此失败,如下图红色箭头所示。

    一旦我如上图所示在Lifecycle 下运行选定的install,问题就消失了,我的maven install compile build 成功。

    【讨论】:

      【解决方案4】:

      我有同样的问题。 我的错误信息不完整。但就我而言,我添加了带有源的生成 jar。通过将此代码放在 pom.xml 中:

      <build> 
          <pluginManagement>
              <plugins>
                  <plugin>
                      <artifactId>maven-source-plugin</artifactId>
                      <version>2.1.2</version>
                      <executions>
                          <execution>
                              <phase>deploy</phase>
                              <goals>
                                  <goal>jar</goal>
                              </goals>
                          </execution>
                      </executions>
                  </plugin>
              </plugins>
          </pluginManagement>
      </build>
      

      所以在部署阶段我执行 source:jar 目标,该目标生成带有源的 jar。并以 BUILD SUCCESS 结束部署

      【讨论】:

        【解决方案5】:

        使用 maven-install-plugin 版本 3.0.0-M1(或类似版本)时出现此错误

        正如上面已经提到的,这里也可以使用以下插件版本:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
                <version>2.5.2</version>
            </plugin>
        

        【讨论】:

          【解决方案6】:

          你必须清除目标文件如jar和其他 在 C: 驱动你的文件夹在 .m2 中查看它的安装位置并删除 .jar 文件、快照文件并删除目标文件然后清理你发现它将运行的应用程序

          【讨论】:

          • 部分解决方案。
          【解决方案7】:

          虽然@A_Di-Matteo 的答案确实适用于非多模块,但我有一个适用于多模块的解决方案。

          解决方案是覆盖每个插件配置,使其绑定到none 的阶段,除了 jar/war/ear 插件,当然还有 deploy 插件。即使您确实有一个模块,我的基本测试也表明这在性能方面会更快(出于我不知道的原因)。

          因此,诀窍是制作一个执行上述操作的配置文件,当您只想部署时激活该配置文件。

          下面是我的一个项目中的一个示例,它使用了 shade 插件,因此我不得不重新覆盖 jar 插件而不是覆盖:

              <profile>
                <id>deploy</id>
                <activation>
                  <property>
                    <name>buildStep</name>
                    <value>deploy</value>
                  </property>
                </activation>
                <build>
                  <plugins>
                    <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-compiler-plugin</artifactId>
                      <executions>
                        <execution>
                          <id>default-compile</id>
                          <phase>none</phase>
                        </execution>
                        <execution>
                          <id>default-testCompile</id>
                          <phase>none</phase>
                        </execution>
                        <execution>
                          <id>test-compile</id>
                          <phase>none</phase>
                        </execution>
                      </executions>
                    </plugin>
                    <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-surefire-plugin</artifactId>
                      <executions>
                        <execution>
                          <id>default-test</id>
                          <phase>none</phase>
                        </execution>
                      </executions>
                    </plugin>
                    <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-install-plugin</artifactId>
                      <executions>
                        <execution>
                          <id>default-install</id>
                          <phase>none</phase>
                        </execution>
                      </executions>
                    </plugin>
                    <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-resources-plugin</artifactId>
                      <executions>
                        <execution>
                          <id>default-resources</id>
                          <phase>none</phase>
                        </execution>
                        <execution>
                          <id>default-testResources</id>
                          <phase>none</phase>
                        </execution>
                      </executions>
                    </plugin>
                    <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-shade-plugin</artifactId>
                      <executions>
                        <execution>
                          <id>default</id>
                          <phase>none</phase>
                        </execution>
                      </executions>
                    </plugin>
                    <plugin>
                      <groupId>org.apache.maven.plugins</groupId>
                      <artifactId>maven-jar-plugin</artifactId>
                      <executions>
                        <execution>
                          <id>default-jar</id>
                          <configuration>
                            <forceCreation>false</forceCreation>
                          </configuration>
                        </execution>
                      </executions>
                    </plugin>
                  </plugins>
                </build>
              </profile>
          

          现在如果我运行mvn deploy -Pdeploy,它只会运行 jar 并部署插件。

          如何确定需要覆盖的插件是运行 deploy 并查看日志以查看哪些插件正在运行。确保跟踪插件配置的id,它是插件名称后面的括号。

          【讨论】:

            【解决方案8】:

            我遇到了同样的问题,但我最初执行了 mvn install(不是前面提到的 install:install)。

            解决方案是包括:

             <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-install-plugin</artifactId>
                    <version>2.5.2</version>
             </plugin>
            

            进入插件管理部分。

            【讨论】:

              【解决方案9】:

              当我收到相同的错误消息时,这对我有用...

              mvn install deploy
              

              【讨论】:

                【解决方案10】:

                我已经看到当需要的插件没有在 pom.xml 中特别提及时会发生此错误。所以

                mvn clean install
                

                如果不添加会给出异常:

                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-install-plugin</artifactId>
                        <version>2.5.2</version>
                 </plugin>
                

                同样,

                mvn clean install deploy
                

                如果不添加类似的内容,将在相同的异常上失败:

                <plugin>
                   <artifactId>maven-deploy-plugin</artifactId>
                   <version>2.8.1</version>
                   <executions>
                      <execution>
                         <id>default-deploy</id>
                         <phase>deploy</phase>
                         <goals>
                            <goal>deploy</goal>
                         </goals>
                      </execution>
                   </executions>
                </plugin>
                

                这是有道理的,但欢迎提供更清晰的错误消息

                【讨论】:

                  【解决方案11】:

                  您缺少 属性 标签:

                  <properties>
                          <maven.compiler.source>1.8</maven.compiler.source>
                          <maven.compiler.target>1.8</maven.compiler.target>
                  </properties>
                  

                  pom.xml 文件的工作版本应如下所示:
                  <?xml version="1.0" encoding="UTF-8"?>
                  <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>org.example</groupId>
                      <artifactId>se-lab1</artifactId>
                      <version>1.0-SNAPSHOT</version>
                  
                      <properties>
                          <maven.compiler.source>1.8</maven.compiler.source>
                          <maven.compiler.target>1.8</maven.compiler.target>
                      </properties>
                  
                      <build>
                          <plugins>
                              <plugin>
                                  <groupId>org.apache.maven.plugins</groupId>
                                  <artifactId>maven-assembly-plugin</artifactId>
                                  <executions>
                                      <execution>
                                          <phase>package</phase>
                                          <goals>
                                              <goal>single</goal>
                                          </goals>
                                          <configuration>
                                              <archive>
                                                  <manifest>
                                                      <mainClass>
                                                          org.hkr.Main
                                                      </mainClass>
                                                  </manifest>
                                              </archive>
                                              <descriptorRefs>
                                                  <descriptorRef>jar-with-dependencies</descriptorRef>
                                              </descriptorRefs>
                                          </configuration>
                                      </execution>
                                  </executions>
                              </plugin>
                              <plugin>
                                  <groupId>org.apache.maven.plugins</groupId>
                                  <artifactId>maven-surefire-plugin</artifactId>
                                  <version>2.19.1</version>
                                  <dependencies>
                                      <dependency>
                                          <groupId>org.junit.platform</groupId>
                                          <artifactId>junit-platform-surefire-provider</artifactId>
                                          <version>1.1.0</version>
                                      </dependency>
                                      <dependency>
                                          <groupId>org.junit.jupiter</groupId>
                                          <artifactId>junit-jupiter-engine</artifactId>
                                          <version>5.1.0</version>
                                      </dependency>
                                  </dependencies>
                              </plugin>
                          </plugins>
                      </build>
                  
                      <dependencies>
                          <dependency>
                              <groupId>org.apache.maven.plugins</groupId>
                              <artifactId>maven-compiler-plugin</artifactId>
                              <version>3.8.1</version>
                          </dependency>
                      </dependencies>
                  </project>
                  

                  【讨论】:

                    【解决方案12】:

                    我希望这对某人有所帮助,但我不小心在我的项目中添加了一个模块,它改变了我的 pom 文件

                    <packaging>jar</packaging>
                    

                    <packaging>pom</packaging>
                    

                    所以我把它改回了

                    <packaging>jar</packaging>
                    

                    它再次创建了 jar

                    【讨论】:

                      猜你喜欢
                      • 2016-02-28
                      • 1970-01-01
                      • 1970-01-01
                      • 1970-01-01
                      • 1970-01-01
                      • 1970-01-01
                      • 2013-01-13
                      • 2016-06-27
                      • 1970-01-01
                      相关资源
                      最近更新 更多