Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven Assembly Plugin - Include classes from another module

I have a multimodule project and am trying to generate an assembled file in SubProject2 that includes some of its classes plus some DTOs defined in SubProject1. However, Proc.jar file only has Proc.class and com\myproy\spr\dto*.class, whereas SubProject1's files (com\myproy\dto*.class) are not included and cannot come up with a way to make it work.

Projects' layout:

Parent
|-pom.xml
|
SubProject1
|-pom.xml
|-src\main\java\com\myproy\dto
|-src\main\java\com\myproy\util
|
SubProject2
|-pom.xml
|-src\assembly\def.xml
|-src\main\java\com\myproy\spr
|-src\main\java\com\myproy\spr\dto

def.xml:

<assembly
    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0
                        http://maven.apache.org/xsd/assembly-1.1.0.xsd">
    <id>Proc</id>
    <formats>
        <format>jar</format>
    </formats>
    <includeBaseDirectory>false</includeBaseDirectory>
    <fileSets>
        <fileSet>
            <directory>target/classes</directory>
            <includes>
                <include>com/myproy/spr/Proc.class</include>
                <include>com/myproy/spr/dto/*.class</include>
                <include>com/myproy/dto/*.class</include>
            </includes>
            <outputDirectory>/</outputDirectory>
        </fileSet>
    </fileSets>
</assembly>

SubProject2->pom.xml

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <version>2.4.1</version>
    <executions>
        <execution>
            <id>distro-assembly</id>
            <phase>package</phase>
            <goals>
                <goal>single</goal>
            </goals>
             <configuration>
                <descriptors>
                    <descriptor>src/assembly/def.xml</descriptor>
                </descriptors>
             </configuration>
        </execution>
    </executions>
</plugin>           
like image 726
codependent Avatar asked Nov 30 '25 20:11

codependent


1 Answers

Correct me if I understand you incorrectly. You want some specific functionality which is in the SubProject1. And you want only this functionality (not more) and you can not include the whole SubProject1 as dependency.

So maybe, if I understand it correctly, you can extract this functionality in another project (something like Commons), and add it as dependency in SubProject1 and SubProject2.

like image 174
Iker Aguayo Avatar answered Dec 03 '25 11:12

Iker Aguayo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!