How to use Maven assembly plugin with multi module maven project

kashili kashili

I am new to maven and spent ~3 days in generating the zip file with assembly plugin refering to http://www.petrikainulainen.net/programming/tips-and-tricks/creating-a-runnable-binary-distribution-with-maven-assembly-plugin/ My project is multi module, so I also referred to Managing multi-module dependencies with Maven assembly plugin

Still I have several inefficiencies. Below is assembly.xml (which I inherited from 1st link)

 <assembly>
<id>bin</id>
<!-- Generates a zip package containing the needed files -->
<formats>
    <format>zip</format>
</formats>

<!-- Adds dependencies to zip package under lib directory -->
<dependencySets>
    <dependencySet>
        <!-- Project artifact is not copied under library directory since it is 
            added to the root directory of the zip package. -->
        <useProjectArtifact>false</useProjectArtifact>
        <outputDirectory>lib</outputDirectory>
        <unpack>false</unpack>

    </dependencySet>
</dependencySets>
<moduleSets>
    <moduleSet>

        <!-- Enable access to all projects in the current multimodule build! <useAllReactorProjects>true</useAllReactorProjects> -->

        <!-- Now, select which projects to include in this module-set. -->
        <includes>
            <include>com.XX:YY-main</include>
        </includes>

        <!--<binaries> <outputDirectory>YY-main/target</outputDirectory> <unpack>false</unpack> 
            </binaries> -->
    </moduleSet>
</moduleSets>
<fileSets>
    <!-- Adds startup scripts to the root directory of zip package. The startup 
        scripts are located to src/main/scripts directory as stated by Maven conventions. -->
    <fileSet>
        <directory>${project.build.scriptSourceDirectory}</directory>
        <outputDirectory>conf</outputDirectory>
        <includes>
            <include>*</include>
        </includes>
    </fileSet>
    <fileSet>
        <directory>${project.build.directory}</directory>
        <outputDirectory></outputDirectory>
        <includes>
            <include>log4j.properties</include>
        </includes>
    </fileSet>
    <!-- adds jar package to the root directory of zip package -->
    <fileSet>
        <directory>${project.build.directory}</directory>
        <outputDirectory></outputDirectory>
        <includes>
            <include>*with-dependencies.jar</include>
        </includes>
    </fileSet>
</fileSets>

Below is the pom.xml (primary or main)

 <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4</version>
             <configuration>                    <descriptors>
              <descriptor>YY-main/src/main/assembly/assembly.xml</descriptor>   
         <!-- <descriptor>DummyAssembly.xml</descriptor> -->

                </descriptors>
            </configuration>
        </plugin>   

Questions:

1)Since assembly.xml is referred in primary pom, all submodules also get zipped. How can I specify only certain submodules to be zipped, while all others get ignored. I tried to move YY-main/src/main/assembly/assembly.xml from main pom to child/submodule pom and have dummyassembly.xml in main which does nothing. But that is not working (possibly because dummyassembly.xml is missing some required lines). tried few things, but nothing seem to work

2)Also in assembly.xml (dependencyset), it is copying all the libraries to "lib" folder. How can I avoid this. again I tried few things (exclusion..) based on http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html#class_dependencySet but nothing worked.

Can some one provide me with specific statements that I should change in my pom or assembly files to address 1 and 2-thanks

khmarbaise

The basic thing you should change is to create a separate module where you do the packaging which will look like this.

   +-- root (pom.xml)
        +--- mod-1 (pom.xml)
        +--- mod-2 (pom.xml)
        +--- mod-assembly (pom.xml)

The pom in the mod-assembly will look like this:

<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>org.test.parent</groupId>
    <artifactId>root</artifactId>
    <version>1.0.0-SNAPSHOT</version>
  </parent>

  <artifactId>dist</artifactId>
  <packaging>pom</packaging>

  <name>Packaging Test : Distribution</name>

  <dependencies>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>module-one</artifactId>
      <version>${project.version}</version>
    </dependency>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>module-two</artifactId>
      <version>${project.version}</version>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <executions>
          <execution>
            <id>make-bundles</id>
            <goals>
              <goal>single</goal>
            </goals>
            <phase>package</phase>
            <configuration>
              <descriptors>
                <descriptor>proj1-assembly.xml</descriptor>
              </descriptors>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

</project>

That will solve the problem with running maven-assembly-plugin in every child and the problem with the dummy descriptor. Here you can find a real example of such structure.

Furthermore having the modules in one folder and the dependencies in an other folder you can use a assembly descriptor like this:

  <id>bin</id>
  <formats>
    <format>zip</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <dependencySets>
    <dependencySet>
          <useProjectArtifact>false</useProjectArtifact>
          <useTransitiveDependencies>true</useTransitiveDependencies>
          <outputDirectory>lib</outputDirectory>
          <unpack>false</unpack>
          <excludes>
            <exclude>${project.groupId}:*:*</exclude>
          </excludes>
      </dependencySet>
  </dependencySets>
  <moduleSets>
    <moduleSet>
      <useAllReactorProjects>true</useAllReactorProjects>
      <binaries>
        <outputDirectory>modules</outputDirectory>
        <unpack>false</unpack>
      </binaries>
    </moduleSet>
  </moduleSets>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to use Maven assembly plugin with multi module maven project

From Dev

How to configure Maven shade plugin in a multi-module project?

From Dev

Jboss as maven plugin to deploy Multi Module Maven Project

From Dev

maven-assembly-plugin: How to use appendAssemblyId

From Dev

maven-assembly-plugin: How to use appendAssemblyId

From Dev

How to create Maven Multi Module Project in Intellij?

From Dev

How to create Maven Multi Module Project in Intellij?

From Dev

Is there a Maven plugin listing all JUnit tests in a multi module project

From Dev

Multi module Maven project with wildfly-swarm-plugin

From Dev

Maven jetty plugin - automatic reload using a multi-module project

From Dev

An error while using the License Maven Plugin in a multi module project

From Dev

When should I use multi module maven project?

From Dev

use maven shade plugin like assembly plugin

From Dev

Convert maven project to submodule of multi module project?

From Dev

How to use maven assembly plugin to exclude a package from dependency jar?

From Dev

Maven project with multiple module and multiple assembly

From Dev

How to build an executable jar from multi module maven project?

From Dev

How to achive deploy on save of multi-module Maven project in NetBeans?

From Dev

How to create a multi-module maven project with spring boot

From Dev

How to automatically reuse dependency versions in a multi-module Maven project?

From Dev

How to achive deploy on save of multi-module Maven project in NetBeans?

From Dev

How to create assemble with multi-module project in maven

From Dev

maven-release-plugin in multi-module project having a seperate git repository for each module

From Dev

sonar-maven-plugin with multi-module maven

From Dev

Jacoco Maven multi module project coverage

From Dev

Putting a multi-module Maven project into Jenkins

From Dev

Maven Multi Module Project Structuring Issues

From Dev

Spring MVC in a multi maven module project

From Dev

Nar dependency in multi-module maven project

Related Related

  1. 1

    How to use Maven assembly plugin with multi module maven project

  2. 2

    How to configure Maven shade plugin in a multi-module project?

  3. 3

    Jboss as maven plugin to deploy Multi Module Maven Project

  4. 4

    maven-assembly-plugin: How to use appendAssemblyId

  5. 5

    maven-assembly-plugin: How to use appendAssemblyId

  6. 6

    How to create Maven Multi Module Project in Intellij?

  7. 7

    How to create Maven Multi Module Project in Intellij?

  8. 8

    Is there a Maven plugin listing all JUnit tests in a multi module project

  9. 9

    Multi module Maven project with wildfly-swarm-plugin

  10. 10

    Maven jetty plugin - automatic reload using a multi-module project

  11. 11

    An error while using the License Maven Plugin in a multi module project

  12. 12

    When should I use multi module maven project?

  13. 13

    use maven shade plugin like assembly plugin

  14. 14

    Convert maven project to submodule of multi module project?

  15. 15

    How to use maven assembly plugin to exclude a package from dependency jar?

  16. 16

    Maven project with multiple module and multiple assembly

  17. 17

    How to build an executable jar from multi module maven project?

  18. 18

    How to achive deploy on save of multi-module Maven project in NetBeans?

  19. 19

    How to create a multi-module maven project with spring boot

  20. 20

    How to automatically reuse dependency versions in a multi-module Maven project?

  21. 21

    How to achive deploy on save of multi-module Maven project in NetBeans?

  22. 22

    How to create assemble with multi-module project in maven

  23. 23

    maven-release-plugin in multi-module project having a seperate git repository for each module

  24. 24

    sonar-maven-plugin with multi-module maven

  25. 25

    Jacoco Maven multi module project coverage

  26. 26

    Putting a multi-module Maven project into Jenkins

  27. 27

    Maven Multi Module Project Structuring Issues

  28. 28

    Spring MVC in a multi maven module project

  29. 29

    Nar dependency in multi-module maven project

HotTag

Archive