tags:

views:

267

answers:

1

Hi 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"&gt;
  <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  A: 

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.

Rich Seller
Hi When running the assembly, i m getting the warning as you have given.So, u mean to say that i shud use goal=compile for the assemblies(which gives jars) and enable the maven compile goal ?
No I mean make the project's packaging "pom" and configure the plugins so that the goals normally executed in the jar's lifecycle are executed in the pom's lifecycle, with the configuration above the resources and compile plugins will be executed during the default lifecycle, so you still run `mvn install`. This gets round the bug in the assembly plugin
Rich Seller
Hi..I changed the packaging as "pom".Added the two plugins you have provided and didn't make any configuration changes to the assemblies.On running mvn install, for the 2nd assembly , it is giving-Caused by: org.apache.maven.project.DuplicateArtifactAttachmentException: Duplicate artifact attachment detected.
the assemblies all need unique ids and finalNames. The ones you posted above worked fine when I ran them with basic assemblies. Have the assembly.xml files got a copy-paste error?
Rich Seller
No there is no copy paste errors-the illegal attachment is the one with Project name-version.jar .
there is no such configuration in your question, could you update the question to include it?
Rich Seller
Caused by: org.apache.maven.project.DuplicateArtifactAttachmentException: Duplicate artifact attachment detected. (project: com.xxx:maven_XX:pom:0.0.1-SNAPSHOT; illegal attachment: com.XXX:maven_XX:jar:0.0.1-SNAPSHOT)
Hii customised the goas as -preclean compile package and encountered the above error.But when i ran mvn preclean compile package form cmd line, the assemblies are getting created except one assembly which contains the test-classes.Please tell me why this behaviour
does it work if you comment out that assembly?
Rich Seller
Not at all-it is not coming till there.Just generates one assembly and when comes to second,it throws this error