2

Maven 3 Java 1.8

In my pom.xml

    <dependencies>
        <dependency>
            <groupId>com.myproject/groupId>
            <artifactId>mixed-pojo</artifactId>
            <version>1.0-SNAPSHOT</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/libs/external-pojo-1.0-SNAPSHOT.jar</systemPath>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-stdlib-jdk8</artifactId>
            <version>${kotlin.version}</version>
        </dependency>
        <dependency>
            <groupId>org.jetbrains.kotlin</groupId>
            <artifactId>kotlin-test</artifactId>
            <version>${kotlin.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.zaxxer</groupId>
            <artifactId>HikariCP</artifactId>
            <version>3.3.1</version>
    </dependency>
...

I need to create ONE executable jar. So I use plugin maven-shade-plugin here pom's snippet:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.2.1</version>
        <executions>
            <execution>
                <phase>package</phase>
                <goals>
                    <goal>shade</goal>
                </goals>
                <configuration>
                    <transformers>
                        <transformer
                                implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                            <mainClass>com.myproject.AppStarterKt</mainClass>
                        </transformer>
                    </transformers>
                    <artifactSet>
                        <includes>
                            <include>${project.basedir}/libs/external-pojo-1.0-SNAPSHOT.jar</include>
                            <include>com.zaxxer:HikariCP</include>
                        </includes>
                    </artifactSet>
                </configuration>
            </execution>
        </executions>
    </plugin>

As result it generate executable jar:

myproject-1.0-SNAPSHOT-shaded.jar

Nice. But the problem is that I need manually add ALL dependencies in plugin like this:

<artifactSet>
                                <includes>
                                    <include>${project.basedir}/libs/external-pojo-1.0-SNAPSHOT.jar</include>
                                    <include>com.zaxxer:HikariCP</include>
                                </includes>
                            </artifactSet>

But I has 50 dependencies. How add ALL dependencies to executable jar?

P.S.

external-pojo-1.0-SNAPSHOT.jar

is a external custom jar that locate on project's folder /libs

Alexei
  • 14,350
  • 37
  • 121
  • 240

1 Answers1

2

By default all runtime scoped dependencies will be included in the shaded uber JAR. Remove <artifactSet> from the <configuration> to get default behavior.

<artifactSet> configuration option is used to override the defaults. When specified <includes> option is a white list of artifacts to include.

Since plugin version 1.3 you can use wildcards * and ?, but this shouldn't be necessary in your example:

<includes>
  <include>**</include>
</includes>
Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111
  • It's success included all dependencies. But not include my custom jar. How I can do this? – Alexei Mar 15 '19 at 13:25
  • 2
    Remove `system` and install this dependency into local repo using [`mvn install`](https://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html). This will also reduce the duplication, you won't have to specify the path twice. [System scope is not suitable for shade](https://stackoverflow.com/a/3643308/1602555). – Karol Dowbecki Mar 15 '19 at 13:28