Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven-assembly-plugin: custom jar filenames

I use the assembly plugin to create several jars with some classes in it. I need custom names for the resulting jars: app_business.jar app_gui.jar core.jar etc.

Currently I have to following configuration:

    <plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
        <appendAssemblyId>false</appendAssemblyId>
    <finalName>app_business</finalName>
        <descriptors>
            <descriptor>assembly.xml</descriptor>
        </descriptors>
        <attach>true</attach>
    </configuration>
    <executions>
        <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>

an the assembly.xml file:

    <assembly>
      <id>app_business</id>
      <formats>
        <format>jar</format>
      </formats>
      <baseDirectory>target</baseDirectory>
      <includeBaseDirectory>false</includeBaseDirectory>

      <fileSets>
        <fileSet>
          <directory>${project.build.outputDirectory}</directory>
          <outputDirectory></outputDirectory> 
          <includes>
            <include>org/xyz/**</include>
          </includes>
        </fileSet>    
      </fileSets>
    </assembly>

this creates a file app_business.jar which is perfect. But i have no idea how to create my other files. The option appendAssemblyId doesn't help me, as it creates filenames in the format AppName-app_business.jar. I really need the exact filesname app_business.jar.

Any Idea? Thank you very much!

like image 594
Synox Avatar asked Aug 25 '09 07:08

Synox


1 Answers

You can move the configuration element below the execution element of the plugin declaration. This means the configuration will only be applied to that execution. You can then add additional executions of the assembly plugin for your other assemblies.

Here is an example of the modified configuration with two executions, each referencing a different assembly:

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <executions>
    <execution>
      <id>make-business-assembly</id>
      <phase>package</phase>
      <goals>
        <goal>single</goal>
      </goals>
      <configuration>
        <appendAssemblyId>false</appendAssemblyId>
        <finalName>app_business</finalName>
        <descriptors>
          <descriptor>src/main/assembly/business-assembly.xml</descriptor>
        </descriptors>
        <attach>true</attach>
      </configuration>
    </execution>
    <execution>
      <id>make-gui-assembly</id>
      <phase>package</phase>
      <goals>
        <goal>single</goal>
      </goals>
      <configuration>
        <appendAssemblyId>false</appendAssemblyId>
        <finalName>app_gui</finalName>
        <descriptors>
          <descriptor>src/main/assembly/gui-assembly.xml</descriptor>
        </descriptors>
        <attach>true</attach>
      </configuration>
    </execution>
  </executions>
</plugin>

With this configuration, two additional jars (app _business.jar and app _gui.jar) will be created in the target directory, though be aware if you install the project, only the last artifact assembled will be installed (this could of course be a problem).

To avoid this you would need to change the appendAssemblyId properties to true. The closest you can get in this case is to change the finalNames to "app" and the IDs to "gui" and "business", resulting in app-gui.jar and app-business.jar being packaged and all artifacts being installed.

like image 106
Rich Seller Avatar answered Sep 20 '22 19:09

Rich Seller