Which plugin can copy classes from specific dependency into final jar

52 Views Asked by At

I created a maven parent project, where I have:

Parent pom:

<modules>
    <module>my-project-solution-a</module>
    <module>my-project-solution-b</module>
    <module>my-project-shared-solution</module>
</modules>

my-project-shared-solution contains the common shared logic for both my-project-solution-a and my-project-solution-b

my-project-solution-a:

<dependencies>
    <dependency>
        <groupId>com.my.solution</groupId>
        <artifactId>my-project-shared-solution</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
    </dependency>
</dependencies>

my-project-solution-b:

<dependencies>
    <dependency>
        <groupId>com.my.solution</groupId>
        <artifactId>my-project-shared-solution</artifactId>
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.core</groupId>
        <artifactId>jersey-server</artifactId>
    </dependency>
</dependencies>

During the build, I want to copy all classes from my-project-shared-solution into my-project-solution-a jar and my-project-solution-b jar.

BUT I don't want to copy the classes from other dependencies like spring-webmvc or jersey-server.

So if my other projects want to include a or b solution, it would still require adding spring-webmvc or jersey-server dependencies, but it would not be needed to add the shared dependency also, because the classes from the shared one will be packed into a and b jars.

I tried something with maven-dependency-plugin but I don't know how to set this up.

Can you provide some examples of how I could do this during the maven build?

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
        <execution>
            <id>copy-dependencies</id>
            <phase>package</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <artifactItems>
                    <artifactItem>
                        <groupId>com.my.solution</groupId>
                        <artifactId>my-project-shared-solution</artifactId>
                        <version>1.0.0</version>
                        <type>jar</type>
                        <classifier>jar-with-dependencies</classifier>
                        <overWrite>true</overWrite>
                        <outputDirectory>libs</outputDirectory>
                        <destFileName>somename.jar</destFileName>
                    </artifactItem>
                </artifactItems>
                <overWriteReleases>false</overWriteReleases>
                <overWriteSnapshots>false</overWriteSnapshots>
                <overWriteIfNewer>true</overWriteIfNewer>
                <excludeTransitive>true</excludeTransitive>
            </configuration>
        </execution>
    </executions>
</plugin>
0

There are 0 best solutions below