Maven Build Plugin - Including Classes from Another Module

I have a multi-module project and I am trying to create a compiled file in SubProject2 that includes some of its classes plus some DTOs defined in SubProject1. However, the Proc.jar file only has Proc.class and com \ myproy \ spr \ dto * .class, whereas the SubProject1 files (com \ myproy \ dto * .class) are not included and cannot find a way to make it work.

Layout of projects:

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>           

      

+3


source to share


2 answers


Correct me if I misunderstand you. You need some functionality, which is in SubProject1. And you only want this functionality (no more) and you cannot include the entire SubProject1 as a dependency.



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

+1


source


Why not add the project as a jar dependency ?.



0


source







All Articles