Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple assemblies from one maven project [duplicate]

we have different java source code "projects". 3 projects are completly identical(fatclient, same dependencies etc.) - there is only another main class that have to be invoked.

Today we have one base-project with a main class:

<project>     <groupId>net.company.BaseTool</groupId>     <artifactId>BaseTool</artifactId>     <version>1.1.0-SNAPSHOT</version>     <packaging>jar</packaging>      <name>BaseTool</name>     <build>         <plugins>             <plugin>                 <artifactId>maven-assembly-plugin</artifactId>                 <configuration>                     <archive>                         <manifest>                             <mainClass>net.company.BaseTool</mainClass>                         </manifest>                     </archive>                 </configuration>             </plugin>         </plugins>     </build> </project> 

and other projects that depending on the base-project

<project>     <groupId>net.company.AnotherTool</groupId>     <artifactId>AnotherTool</artifactId>     <version>1.1.0-SNAPSHOT</version>     <packaging>jar</packaging>      <name>AnotherTool</name>     <build>         <plugins>             <plugin>                 <artifactId>maven-assembly-plugin</artifactId>                 <configuration>                     <archive>                         <manifest>                             <mainClass>net.company.AnotherTool</mainClass>                         </manifest>                     </archive>                 </configuration>             </plugin>         </plugins>     </build>     <dependencies>         <dependency>             <groupId>net.company.BaseTool</groupId>             <artifactId>BaseTool</artifactId>             <version>1.1.0-SNAPSHOT</version>         </dependency>     </dependencies> </project> 

We are doing this, because we need simple double-click startable applications.

But I dont want to create an extra java project for each application.

My question is: Is it possible to create multiple assemblies from one project? And if yes, how it should be done.

Here comes the solution

<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>my.company.toolbox</groupId>     <artifactId>toolbox</artifactId>     <version>1.1.0-SNAPSHOT</version>     <packaging>jar</packaging>      <name>toolbox</name>     <url>http://wiki.company.my/toolbox</url>      <build>         <plugins>             <plugin>                 <groupId>org.apache.maven.plugins</groupId>                 <artifactId>maven-assembly-plugin</artifactId>                 <version>2.6</version>                 <configuration>                     <finalName>toolbox</finalName>                     <appendAssemblyId>false</appendAssemblyId>                     <descriptorRefs>                         <descriptorRef>jar-with-dependencies</descriptorRef>                     </descriptorRefs>                 </configuration>                 <executions>                     <execution>                         <id>ToolOne</id>                         <phase>package</phase>                         <goals>                             <goal>single</goal>                         </goals>                         <configuration>                             <finalName>ToolOne</finalName>                             <archive>                                 <manifest>                                     <mainClass>my.company.ToolOne</mainClass>                                 </manifest>                             </archive>                         </configuration>                     </execution>                     <execution>                         <id>ToolTwo</id>                         <phase>package</phase>                         <goals>                             <goal>single</goal>                         </goals>                         <configuration>                             <finalName>ToolTwo</finalName>                             <archive>                                 <manifest>                                     <mainClass>my.company.ToolTwo</mainClass>                                 </manifest>                             </archive>                         </configuration>                     </execution>                     <execution>                         <id>ToolThree</id>                         <phase>package</phase>                         <goals>                             <goal>single</goal>                         </goals>                         <configuration>                             <finalName>ToolThree</finalName>                             <archive>                                 <manifest>                                     <mainClass>my.company.ToolThree</mainClass>                                 </manifest>                             </archive>                         </configuration>                     </execution>                     <execution>                         <id>ToolFour</id>                         <phase>package</phase>                         <goals>                             <goal>single</goal>                         </goals>                         <configuration>                             <finalName>ToolFour</finalName>                             <archive>                                 <manifest>                                     <mainClass>my.company.ToolFour</mainClass>                                 </manifest>                             </archive>                         </configuration>                     </execution>                 </executions>             </plugin> 
like image 480
Mirko Avatar asked Oct 04 '12 12:10

Mirko


People also ask

Can a Maven project have multiple pom files?

Yes you can use Maven Profiles to manage this. Obviously you can tweak this approach to suit your needs however works best.

What is multi module Maven project?

A multi-module project is built from an aggregator POM that manages a group of submodules. In most cases, the aggregator is located in the project's root directory and must have packaging of type pom. The submodules are regular Maven projects, and they can be built separately or through the aggregator POM.

What is Reactor build order in Maven?

The Reactor This part of the Maven core does the following: Collects all the available modules to build. Sorts the projects into the correct build order. Builds the selected projects in order.


1 Answers

You can use different executions of the assembly plugin and then attach the resulting assembly to the build. Of course you have to configure different final names for the artifacts in the assembly plugin configuration.

like image 138
SpaceTrucker Avatar answered Sep 28 '22 06:09

SpaceTrucker