XML : How to Assemble a Multi-Module Project with different jars in different folders in the main project root with the Maven Assembly plugin

I have a multi-module Apache Maven 3.3.3 project with n*** (multiple) modules:

  /mvnModular             /mainMod             /modules             /modules /module1             /modules /module2             /modules /module***             /modules /module***    

The idea is to have an application written in a way that a user will download the project mvnModular that only contains mainMod.jar in the mvnModular folder innitially. The mainMod folder has a jar file called mainMod.jar in /mvnModular/mainMod/target/ after mvn package, which is the main project. Then the project could be extended by adding modules to a folder called modules in the mvnModular root. Each of the modules has a module***.jar file in /mvnModular/module***/target after build, for example module1.jar.

How can I go about adding the .jar files in modules module1, module2, module3, module*** into a folder modules in the root, and mainMod.jar into the root folder, mvnModular?

.....

mainMod has only one file 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>mainmod</groupId>    <artifactId>mainmod</artifactId>    <version>1.0-SNAPSHOT</version>    <packaging>pom</packaging>      <name>mainmod</name>    <url>http://maven.apache.org</url>      <build>      <pluginManagement>        <plugins>          <plugin>            <artifactId>maven-assembly-plugin</artifactId>            <version>2.2-beta-5</version>            <configuration>              <descriptors>                <descriptor>src/main/assembly/assembly.xml</descriptor>              </descriptors>            </configuration>            <executions>              <execution>                <id>make-assembly</id> <!-- this is used for inheritance merges -->                <phase>package</phase> <!-- append to the packaging phase. -->                <goals>                  <goal>single</goal> <!-- goals == mojos -->                </goals>              </execution>            </executions>          </plugin>        </plugins>      </pluginManagement>    </build>      <properties>      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>    </properties>      <dependencies>      <dependency>        <groupId>junit</groupId>        <artifactId>junit</artifactId>        <version>3.8.1</version>        <scope>test</scope>      </dependency>    </dependencies>      <modules>      <module>..\modules\pom.xml</module>    </modules>  </project>    

assembly.xml:

  <assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.3 http://maven.apache.org/xsd/assembly-1.1.3.xsd">    <id>bin</id>    <baseDirectory>/</baseDirectory>      <formats>      <format>zip</format>    </formats>      <includeBaseDirectory>false</includeBaseDirectory>      <files>      <file>        <source>${project.basedir}/src/main/config/config.properties</source>        <filtered>true</filtered>      </file>   </files>     <fileSets>    <fileSet>      <directory>${project.basedir}/src/main/scripts</directory>      <outputDirectory>scripts</outputDirectory>    </fileSet>      <fileSet>      <directory>${project.basedir}/src/modules</directory>      <outputDirectory>modules</outputDirectory>    </fileSet>  </fileSets>    <dependencySets>    <dependencySet>      <outputDirectory>lib</outputDirectory>    </dependencySet>      <dependencySet>      <useProjectArtifact>false</useProjectArtifact>      <useTransitiveDependencies>false</useTransitiveDependencies>      <unpack>false</unpack>      <includes>        <include>*:*:jar</include>      </includes>    </dependencySet>  </dependencySets>  </assembly>    

Modules has only one file, 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>      <parent>      <groupId>mainmod</groupId>      <artifactId>mainmod</artifactId>      <version>1.0-SNAPSHOT</version>      <relativePath>../mainmod/pom.xml</relativePath>    </parent>      <groupId>mainmod.modules</groupId>    <artifactId>modules</artifactId>    <version>1.0-SNAPSHOT</version>    <packaging>pom</packaging>      <name>modules</name>    <url>http://maven.apache.org</url>      <properties>      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>    </properties>      <dependencies>      <dependency>        <groupId>junit</groupId>        <artifactId>junit</artifactId>        <version>3.8.1</version>        <scope>test</scope>      </dependency>    </dependencies>      <modules>      <module>..\module1\pom.xml</module>      <module>..\module2\pom.xml</module>    </modules>  </project>    

No comments:

Post a Comment