Maven – Module:referencing another module from the desciptor

maven-2

My assembly descriptor for module (APP1) is:

  <?xml version="1.0" encoding="UTF-8"?>
  <assembly>
  <id>report</id>
    <formats>
    <format>jar</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <moduleSets>
    <moduleSet>
      <includes>
    <include>*-APP2</include>[trying to refer to another module ie module-APP2]
      </includes>
      <sources>
    <fileSets>
      <fileSet>
        <directory>/</directory>
        <includes>
          <include>**/target</include>
        </includes>
      </fileSet>
    </fileSets>
    <excludeSubModuleDirectories>false</excludeSubModuleDirectories>
    <outputDirectoryMapping>/</outputDirectoryMapping>
      </sources>
    </moduleSet>
  </moduleSets>
 </assembly>

When I am running the mvn install cmd , I'm getting

[WARNING] The following patterns were never triggered in this artifact inclusion filter:
o  '*-APP2'

where have I gone wrong?

I modified as :

<?xml version="1.0" encoding="UTF-8"?><assembly>
  <id>report</id>
  <formats>
    <format>jar</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <moduleSets>
    <moduleSet>
      <includes>
    <include>sampleMaven:module-APP2</include>
      </includes>
      <sources>
    <fileSets>
      <fileSet>
        <directory>/</directory>
        <includes>
          <include>target/*</include>
        </includes>
      </fileSet>
    </fileSets>
    <excludeSubModuleDirectories>false</excludeSubModuleDirectories>
    <outputDirectoryMapping>/</outputDirectoryMapping>
      </sources>
    </moduleSet>
  </moduleSets>
</assembly>

still getting :

[WARNING] The following patterns were never triggered in this artifact inclusion filter:
o  'sampleMaven:module-APP2'

Updated on 18/sep:
Main proj pom.xml–>

http://maven.apache.org/maven-v4_0_0.xsd">
4.0.0
sampleMaven
anu
0.0.1-SNAPSHOT
pom

APP1

<module>APP2</module>

2)For APP1, the pom.xml is–>

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

anu
sampleMaven
0.0.1-SNAPSHOT

4.0.0
sampleMaven
APP1
APP1
0.0.1-SNAPSHOT
pom

../APP2

<build>
 <plugins>
    <plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.2-beta-3</version>
    <executions>
    <execution>
      <id>assemblyone</id>
      <phase>compile</phase>
      <goals>
            <goal>single</goal>
      </goals>
      <configuration>
        <finalName>App1</finalName>
        <appendAssemblyId>false</appendAssemblyId>
        <descriptors>
          <descriptor>${basedir}/src/main/resources/assemblies/report.xml</descriptor>
        </descriptors>
      </configuration>
    </execution>
     </executions>
    </plugin>
  </plugins>
</build> 
</project> ...

3)Assembly descriptor is –>

report

jar

false

 <sources>
  <fileSets>
    <fileSet>
      <directory>/</directory>
      <includes>
       <include>target/*</include>
      </includes>
    </fileSet>
  </fileSets>
  <excludeSubModuleDirectories>false</excludeSubModuleDirectories>
  <outputDirectoryMapping>/</outputDirectoryMapping>
 </sources>
 <binaries>
   <outputDirectory>
      ${module.artifactId}-${module.version}
   </outputDirectory>
   <dependencySets>
      <dependencySet/>
   </dependencySets>
 </binaries>
</moduleSet>

On running gettting–>Error stacktrace:

org.apache.maven.project.DuplicateProjectException: Project 'sampleMaven:APP2' is duplicated in the reactor

Best Answer

Update: The Maven book has a section on including moduleSets in assemblies. The approach you have in your example is deprecated. There is also a problem with build order when defining moduleSets from the parent. The parent must be built first so the child can inherit from it, but the child must be built so that the parent can includ it in its assembly. The following approach addresses that cycle.

Define a parent pom that references an assembly module.

<?xml version="1.0" encoding="UTF-8"?>
<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>name.seller.rich</groupId>
  <artifactId>test-parent</artifactId>
  <packaging>pom</packaging>
  <version>1.0.0</version>
  <modules>
    <module>test-assembly</module>
  </modules>
  <dependencies>
</project>

In the assembly module, define a module with a relative path to the actual application module(s), and define the assembly plugin configuration:

<?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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>name.seller.rich</groupId>
  <artifactId>test-assembly</artifactId>
  <packaging>pom</packaging>
  <version>1.0.0-SNAPSHOT</version>
  <modules>
    <module>../my-app2</module>
  </modules>
  <build>
    <plugins>
      <plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.2-beta-4</version>
    <executions>
      <execution>
        <id>assembly</id>
        <phase>package</phase>
        <goals>
          <goal>single</goal>
        </goals>
        <configuration>
          <finalName>App1</finalName>
          <appendAssemblyId>false</appendAssemblyId>
          <descriptors>
            <descriptor>src/main/assembly/my-assembly.xml</descriptor>
          </descriptors>
        </configuration>
      </execution>
    </executions>
      </plugin>
    </plugins>
  </build>
</project>

and my-assembly.xml is defined as follows:

<?xml version="1.0" encoding="UTF-8"?><assembly>
  <id>my-assembly</id>
  <formats>
    <format>jar</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <moduleSets>  
    <moduleSet>
      <binaries>
        <outputDirectory>
          ${module.artifactId}-${module.version}
        </outputDirectory>
        <dependencySets>
          <dependencySet/>
        </dependencySets>
      </binaries>
    </moduleSet>
  </moduleSets>
</assembly>

Building the parent module will then result in a build order of:

  1. test-parent
  2. my-app2
  3. test-assembly

So when the assembly comes to be packaged, my-app2 is built, and is available for inclusion. The binaries declaration will include the jars.