4D617274696A6E
4D617274696A6E

Reputation: 23

Shaded joda time does not contain classes

I'm trying to shade Joda time 2.9.2 into my final jar file, using the maven shade plugin. But Joda time's classes are not getting added to the final jar, some packages and other files are getting added, but not the .class files.

Here's my 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>

And here are the contents of the final jar file; http://pastebin.com/TXzB9vTv

Why aren't Joda time's classes being included in the final jar? How would I fix this?

For future readers: When using <minimizeJar>true</minimizeJar> you should explicitly include the dependency (in this case, joda time) in the filters section. Otherwise it can be 'optimized' away.

Upvotes: 0

Views: 361

Answers (1)

Meno Hochschild
Meno Hochschild

Reputation: 44071

The release v2.9.3 is not yet out. The latest one is v2.9.2.

Update:

After clarification of version problem, following description of maven-shade-plugin is important.

Besides user-specified filters, the plugin can also be configured to automatically remove all classes of dependencies that are not used by the project, thereby minimizing the resulting uber JAR

So either make sure that your project really uses Joda-Time, or remove the tag entry

<minimizeJar>true</minimizeJar>

Upvotes: 1

Related Questions