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

时间:2011-06-10 14:59:12

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

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

12 个答案:

答案 0 :(得分:135)

我不知道这是不是答案,但它可能会引导你朝着正确的方向前进......

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

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

这归结为命令......

mvn clean install

与......不同。

mvn clean install:install

前者将在每个循环中运行所有目标,包括安装(如编译,包,测试等)。后者甚至不会编译或打包你的代码,它只会运行那一个目标。看看异常,这有点意义;它谈到:

  

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

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

答案 1 :(得分:66)

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 {{ 1}} phase)你最终会陷入恼人的deploy

一个典型的例子是CI工作(例如Jenkins或Bamboo工作),在这些工作中你想要执行/关注不同方面的不同步骤:

  • 第一步是The packaging for this project did not assign a file to the build artifact,执行测试和测试覆盖
  • 第二步是基于质量分布的Sonarqube分析,例如mvn clean install以及更多选项
  • 然后,只有在成功执行测试执行和质量门后,您才希望将最终的项目工件部署到Maven企业存储库,但是您不想重新运行mvn sonar:sonar,因为它会再次执行前面的阶段(以及编译,测试等),你希望你的构建有效,但快速

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

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

  

在包装阶段,所有人都聚集在一起并放置在上下文中。通过这种机制,Maven可以确保mvn deploy:deploymaven-install-plugin正在复制/上传同一组文件。因此,当您只执行maven-deploy-plugin时,上下文中没有文件,也没有任何内容可以部署。

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

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

然后拒绝不是问题。

deploy:deploy的{​​{3}}配置选项在某些情况下无效,因为我们有执行的中间作业步骤:

  

是否应在其自己的部署阶段或多模块构建结束时部署每个项目。如果设置为maven-deploy-plugin且构建失败,则不会部署任何reactor项目。 (实验)

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

true

mvn jar:jar deploy:deploy 不会在构建过程中重新创建任何jar,这要归功于默认情况下maven-jar-plugin选项设置为false

  

即使没有任何内容显示已更改,也需要jar插件来构建新的JAR。默认情况下,此插件会查看输出jar是否存在且输入是否未更改。如果这些条件成立,则插件会跳过jar的创建。

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

附加说明:如果您正在使用build-helper-maven-pluginbuildnumber-maven-plugin或任何其他类似的插件来生成maven-jar-plugin稍后使用的元数据(例如,清单文件的条目) ,你很可能有与validate阶段相关联的执行,你仍然希望在jar:jar构建步骤中拥有它们(并保持快速执行)。在这种情况下,几乎无害的开销是调用validate deployAtEnd,如下所示:

mvn validate jar:jar deploy:deploy

还有一个补充说明:如果您没有jar,而是war打包,请在安装/部署之前使用war:war

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

答案 2 :(得分:6)

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

我在使用 Java IDE处理 IntelliJ IDEA 项目时遇到此失败错误。< / p>

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

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

Choose Wrong Selection

如上图所示,在install下运行选定的Lifecycle后,问题就消失了,我的maven安装编译成功了。

答案 3 :(得分:5)

我有同样的问题。 我的错误信息不完整。但在我的情况下,我添加了带有源代码的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结束

答案 4 :(得分:3)

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

答案 5 :(得分:0)

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

解决方案包括:

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

进入插件管理部分。

答案 6 :(得分:0)

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

答案 7 :(得分:0)

虽然@ 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 :(得分:0)

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

require('module-alias/register')

答案 9 :(得分:0)

我已经看到当 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>

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

答案 10 :(得分:0)

您缺少属性标签:

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

答案 11 :(得分:0)

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

<packaging>jar</packaging>

<packaging>pom</packaging>

所以我把它改回

<packaging>jar</packaging>

它再次创建了jar