0

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.

1 Answers1

1

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>
Meno Hochschild
  • 42,708
  • 7
  • 104
  • 126
  • Wow I'm such an idiot for not noticing. It gives the same result with v2.9.2 though :( The issue originally happend wih v2.9.2. I fiddled around a bit with the version after that, guess I accidentally wrote 2.9.3 instead of 2.9.2 when restoring it to the original version. – 4D617274696A6E Feb 29 '16 at 17:52
  • @Martijn Is it a relocation problem? I notice that you have specified relocations for other classes like this uuid-package but not for Joda-Time. – Meno Hochschild Feb 29 '16 at 18:02
  • It does the same thing if I relocate Joda time as well, except the joda package is in the specified relocated location, ofcourse. – 4D617274696A6E Feb 29 '16 at 18:07
  • Also does the same if I don't relocate anything at all. And it also does the same if I comment out all exclusions. – 4D617274696A6E Feb 29 '16 at 18:17
  • @Martijn Hm, sorry. Have you also tried to **include** the joda-classes explicitlly in the filter section? – Meno Hochschild Feb 29 '16 at 18:23
  • @Martijn If you minimize your jar then make sure that your project really uses Joda-Time otherwise it can be "optimized" away, see also the description of minimizing on website of maven-plugin: "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" – Meno Hochschild Feb 29 '16 at 18:27
  • No I haven't, I just found something out. After fiddling around with a bunch of pom settings. If I remove the `true` it works good. And when I re add it, it breaks again. Any clue why that is? – 4D617274696A6E Feb 29 '16 at 18:29