装配创建问题

时间:2009-10-05 09:11:11

标签: maven-2

在我的项目中,我创建了许多程序集(4-5)并将它们输出到目标。这些程序集的1/2中没有采用它们的最终名称(或程序集ID),但是按照artifactID-version的格式.jar ..这非常令人困惑 为什么会这样?

从我的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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.apple</groupId>
  <artifactId>maven</artifactId>
  <name>maven_XX</name>
  <version>0.0.1-SNAPSHOT</version>  


  <build>
    <plugins>
    <!-- Added to avoid the compilation issue wrt Annotations -->
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.5</source>
          <target>1.5</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.4.2</version>
        <configuration>
          <skip>true</skip>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <version>2.2-beta-4</version>
        <executions>              
          <execution>
            <id>clientjar</id>
            <phase>compile</phase>
            <goals>
              <goal>single</goal>
            </goals>
            <configuration>
              <finalName>XX_client</finalName>
              <appendAssemblyId>false</appendAssemblyId>
              <descriptors>
                <descriptor>
                  ${basedir}/src/main/resources/assemblies/clientjar.xml
                </descriptor>
              </descriptors>
            </configuration>
          </execution>
          <execution>
            <id>11***</id>
            <phase>compile</phase>
            <goals>
              <goal>single</goal>
            </goals>
            <configuration>
              <finalName>11server</finalName>
              <appendAssemblyId>false</appendAssemblyId>
              <descriptors>
                <descriptor>
                  ${basedir}/src/main/resources/assemblies/11server.xml
                </descriptor>
              </descriptors>
              <outputDirectory>assemblies-target</outputDirectory>
            </configuration>
          </execution>
          <execution>
            <id>cache</id>
            <phase>compile</phase>
            <goals>
              <goal>single</goal>
            </goals>
            <configuration>
              <finalName>cache</finalName>
              <appendAssemblyId>false</appendAssemblyId>
              <descriptors>
                <descriptor>
                 ${basedir}/src/main/resources/assemblies/cache.xml
              </descriptor>
              </descriptors>
              <outputDirectory>assemblies-target</outputDirectory>
            </configuration>
          </execution>

2 个答案:

答案 0 :(得分:14)

Lyle的评论拉出到问题级别以提供可见性。

虽然之前的答案有效Lyle指出:

  

如果我理解这一点,那么对于组装插件中的错误而言,这似乎是一种有点侵入性的解决方法。相反,请尝试在配置中设置false。请参阅:MASSEMBLY-352

对于未附加到存储库分发的工件,这是一个很好的解决方案,对我来说效果很好。

...
<appendAssemblyId>false</appendAssemblyId>
<attach>false</attach>
...

答案 1 :(得分:8)

当您运行程序集时,Maven会看到这样的输出到控制台吗?:

[INFO] [assembly:single {execution: 11***}]
[INFO] Reading assembly descriptor: C:\test\test-parent2/src/main/resources/assemblies/11server.xml
[INFO] Building jar: C:\test\test-parent2\assemblies-target\11server.jar
[WARNING] Configuration options: 'appendAssemblyId' is set to false, and 'classifier' is missing.
Instead of attaching the assembly file: C:\test\test-parent2\assemblies-target\11server.jar, it will become the file for
 main project artifact.
NOTE: If multiple descriptors or descriptor-formats are provided for this project, the value of this file will be non-de
terministic!

这是因为所有程序集都指定了<appendAssemblyId>false</appendAssemblyId>并且未指定分类器。分类器在2.2-beta-4版本中已弃用,因此无论如何都会被忽略,这是插件中的错误/功能。
因此,Maven将始终将其中一个程序集作为jar包装的“主要”工件,并且您不会在target-assemblies目录中看到它。

要解决此问题,您可以指定项目具有pom打包,然后将jar生命周期的目标绑定到pom。

要启用process-resourcescompile目标,您需要将打包更改为pom,将以下配置添加到您的pom,并运行标准生命周期目标。例如mvn packagemvn install

<plugin>
  <artifactId>maven-resources-plugin</artifactId>
  <executions>              
    <execution>
      <id>process-resources</id>
      <phase>process-resources</phase>
      <goals>
        <goal>resources</goal>
      </goals>
    </execution>
  </executions>
</plugin>
<plugin>
  <artifactId>maven-compiler-plugin</artifactId>
  <executions>              
    <execution>
      <id>compile</id>
      <phase>compile</phase>
      <goals>
        <goal>compile</goal>
      </goals>
    </execution>
  </executions>
</plugin>

可以在Introduction to the Build Lifecycle内置生命周期绑定部分找到绑定到jar生命周期的完整目标列表。它们都遵循与process-resourcescompile目标类似的模式。在您的情况下,您可能想要省略jar目标。