[英]maven-shade-plugin : how add all dependencies and custom local jar to executable jar?
Maven 3 Java 1.8 Maven 3 Java 1.8
In my pom.xml 在我的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 . 我需要创建一个可执行jar 。 So I use plugin
maven-shade-plugin
here pom's snippet: 所以我在pom的代码段中使用插件
maven-shade-plugin
:
<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
: 结果,它生成
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. 但是我有50个依赖项。 How add ALL dependencies to executable jar?
如何将所有依赖项添加到可执行jar?
PS PS
external-pojo-1.0-SNAPSHOT.jar
is a external custom jar that locate on project's folder /libs
是位于项目文件夹
/libs
上的外部自定义jar
By default all runtime
scoped dependencies will be included in the shaded uber JAR. 默认情况下,所有
runtime
范围内的依赖项都将包含在带阴影的uber JAR中。 Remove <artifactSet>
from the <configuration>
to get default behavior. 从
<configuration>
删除<artifactSet>
以获取默认行为。
<artifactSet>
configuration option is used to override the defaults. <artifactSet>
配置选项用于覆盖默认值。 When specified <includes>
option is a white list of artifacts to include. 指定后,
<includes>
选项是要包含的工件的白名单。
Since plugin version 1.3 you can use wildcards *
and ?
从插件版本1.3开始,您可以使用通配符
*
和?
, but this shouldn't be necessary in your example: ,但在您的示例中这不是必需的:
<includes>
<include>**</include>
</includes>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.