我正在尝试使用maven shade插件将Joda时间2.9.2隐藏到我的最终jar文件中。但是Joda time的类没有被添加到最终的jar中,一些包和其他文件被添加,但不是.class文件。
这是我的pom.xml;
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>me.ninjoh</groupId>
<artifactId>nincore</artifactId>
<version>2.0.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<local.maven.repository>file:///Users/LegitAdmin/.m2/repository</local.maven.repository>
</properties>
<repositories>
<repository>
<id>mcapi</id>
<url>http://build.mc-api.net/plugin/repository/everything/</url>
</repository>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>net.mcapi.uuid</groupId>
<artifactId>uuid-java</artifactId>
<version>1.1.2</version>
</dependency>
<!--Spigot API-->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!--Bukkit API-->
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.8.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<!-- Joda Time-->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.2</version>
</dependency>
<!-- Jbcrypt -->
<dependency>
<groupId>org.mindrot</groupId>
<artifactId>jbcrypt</artifactId>
<version>0.3m</version>
</dependency>
<!-- Jansi (for color in console) -->
<dependency>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
<version>1.11</version>
</dependency>
<!-- Jetbrains annotations -->
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations-java5</artifactId>
<version>15.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<minimizeJar>true</minimizeJar>
<artifactSet>
<includes>
<include>org.jetbrains:annotations-java5</include>
<include>org.fusesource.jansi:jansi</include>
<include>org.mindrot:jbcrypt</include>
<include>net.mcapi.uuid:uuid-java</include>
<include>joda-time:joda-time</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>org.jetbrains</pattern>
<shadedPattern>me.ninjoh.common.org.jetbrains</shadedPattern>
</relocation>
<relocation>
<pattern>org.fusesource.jansi</pattern>
<shadedPattern>me.ninjoh.common.org.fusesource.jansi</shadedPattern>
</relocation>
<relocation>
<pattern>org.mindrot.jbcrypt</pattern>
<shadedPattern>me.ninjoh.common.org.mindrot.jbcrypt</shadedPattern>
</relocation>
<relocation>
<pattern>net.mcapi.uuid</pattern>
<shadedPattern>me.ninjoh.common.net.mcapi.uuid</shadedPattern>
</relocation>
</relocations>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/license/**</exclude>
<exclude>META-INF/*</exclude>
<exclude>META-INF/maven/**</exclude>
<exclude>LICENSE</exclude>
<exclude>NOTICE</exclude>
<exclude>/*.md</exclude>
<exclude>/.gitignore</exclude>
<exclude>/*.txt</exclude>
<exclude>build.properties</exclude>
</excludes>
</filter>
</filters>
</configuration>
</plugin>
</plugins>
</build>
<distributionManagement>
<repository>
<id>local-repository</id>
<url>${local.maven.repository}</url>
</repository>
</distributionManagement>
以下是最终jar文件的内容; http://pastebin.com/TXzB9vTv
为什么Joda时间的课程不包含在最后一个jar中?我该如何解决这个问题?
对于未来的读者:
使用<minimizeJar>true</minimizeJar>
时,您应在过滤器部分明确包含依赖关系(在本例中为joda time)。否则它可以“优化”。
答案 0 :(得分:1)
发布版本v2.9.3尚未发布。最新的一个是v2.9.2。
<强>更新强>
在澄清版本问题之后,以下对m aven-shade-plugin的描述非常重要。
除了用户指定的过滤器,插件也可以配置为 自动删除未使用的所有依赖项类 该项目,从而最大限度地减少了由此产生的优步JAR
因此,要么确保您的项目确实使用Joda-Time,要么删除标记条目
<minimizeJar>true</minimizeJar>