2

Is there a way to create a fat jar with Maven that only contains some but not all dependency artifacts?

More concretely, I want to have two executions of shade: one that includes com.acme:* and one that includes all else. The point is to have two jars -- one with all my code and one with all the 3rd party deps. The latter is easy:

<artifactSet>
  <excludes>
    <exclude>com.acme:*</exclude>
  </excludes>
</artifactSet>

But the former isn't. Because exclusions are processed after inclusions and everything is included by default, the following would not work:

<artifactSet>
  <excludes>
    <exclude>*:*</exclude>
  </excludes>
  <includes>
    <include>com.acme:*</include>
  </includes>
</artifactSet>

Any Maven mavens out there? (sorry but I had to)

ktdrv
  • 3,602
  • 3
  • 30
  • 45

1 Answers1

0

Probably is not needed by the original author but, after few try I managed to accomplish the result as follows:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-shade-plugin</artifactId>
    <version>3.4.1</version>
    <executions>
        <execution>
            <id>exec-id</id>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <minimizeJar>true</minimizeJar>
                <artifactSet>
                    <includes>
                        <include>group.id:artifactId</include>
                    </includes>
                </artifactSet>
                <filters>
                    <filter>
                        <artifact>group.id:artifactId</artifact>
                        <includes>
                            <include>path/to/include/**</include>
                            <include>path/to/include/**</include>
                            <include>path/to/include/**</include>
                            <include>path/to/include/**</include>
                        </includes>
                    </filter>
                </filters>
                <finalName>yourFinalName</finalName> 
                <createDependencyReducedPom>false</createDependencyReducedPom>
                <outputDirectory>../your-dir</outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>

with the attribute <artifactSet> and <includes> you define only the dependencies that should be added to the outoput jar, and if you have to filter the artifacts, you can use <filters> to filter through the packages of each artifact.

Hope this helps.