Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Issue with assembly creation

Tags:

maven-2

In my project, I m creating many assemblies(4-5) and they are output to target.1/2 of these assemblies are not taking their final names(or assembly id) , but as per the format artifactID-version.jar..This is very confusing Why is this so?

Extracts from my 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>
like image 682
user170114 Avatar asked Oct 05 '09 09:10

user170114


2 Answers

Pulling Lyle's comment out to the question level to provide visibility.

While the previous answer works Lyle points out that:

If I understand this correctly, it seems like a somewhat invasive workaround for what amounts to a bug in the assembly plugin. Instead, try setting false in the configuration. See: MASSEMBLY-352

For artifacts that are not attached to the repository distribution this is a fine solution and worked well for me.

...
<appendAssemblyId>false</appendAssemblyId>
<attach>false</attach>
...
like image 96
Peter Kahn Avatar answered Oct 09 '22 19:10

Peter Kahn


When you run the assembly, do you see something like this output to the console by 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!

This happens because all your assemblies specify <appendAssemblyId>false</appendAssemblyId> and no classifier is specified. The classifier is deprecated in the 2.2-beta-4 version so is ignored anyway, this is a bug/feature in the plugin.
As a result, Maven will always make one of the assemblies the "main" artifact for jar packaging, and you don't see it in your target-assemblies directory.

To work around this you can specify that your project has pom packaging, then bind the goals for the jar lifecycle to the pom.

To enable the process-resources and compile goals you would change the packaging to pom, add the following configuration to your pom, and run the standard lifecycle goals. For example mvn package or mvn 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>

The full list of goals bound to the jar lifecycle can be found in the Built in Lifecycle Bindings section of the Introduction to the Build Lifecycle. They all follow a similar pattern to the process-resources and compile goals. In your case you probably want to omit the jar goal.

like image 21
Rich Seller Avatar answered Oct 09 '22 20:10

Rich Seller