Search code examples
maventitankryo

Maven shade plugin with Kryo 3.0: ClassNotFoundException


I'm fairly new to Maven and I want to update a project from Kryo 2.22 to 3.0.1. In the project I've got the following dependency.

<dependency>
    <groupId>com.esotericsoftware.kryo</groupId>
    <artifactId>kryo</artifactId>
    <version>2.22</version>
</dependency>

The project uses the Maven shade plugin to create a jar file:

<plugin>
    <artifactId>maven-shade-plugin</artifactId>
    <version>2.3</version>
    <executions>
        <execution>
            <id>shade-gremlin-groovy</id>
            <phase>package</phase>
            <goals>
                <goal>shade</goal>
            </goals>
            <configuration>
                <createDependencyReducedPom>false</createDependencyReducedPom>
                <artifactSet>
                    <includes>
                        <!-- As of Kryo 2.22, this artifact includes both minlog and reflectasm -->
                        <!-- If we upgrade to later a Kryo version, we may have to add includes
                             for minlog and reflectasm (this is true of 2.24.0, not sure about 3) -->
                        <include>com.esotericsoftware.kryo:*</include>
                    </includes>
                </artifactSet>
                <filters>
                    <filter>
                        <artifact>*:*</artifact>
                        <excludes>
                            <exclude>reflectasm-1.07-shaded.jar</exclude>
                            <exclude>minlog-1.2.jar</exclude>
                            <exclude>objenesis-1.2.jar</exclude>
                            <exclude>META-INF/MANIFEST.MF</exclude>
                        </excludes>
                    </filter>
                </filters>
                <relocations>
                    <relocation>
                        <pattern>com.esotericsoftware.kryo</pattern>
                        <shadedPattern>com.thinkaurelius.shaded.kryo_2_22</shadedPattern>
                    </relocation>
                    <relocation>
                        <pattern>com.esotericsoftware.minlog</pattern>
                        <shadedPattern>com.thinkaurelius.shaded.minlog_1_2</shadedPattern>
                    </relocation>
                    <relocation>
                        <pattern>com.esotericsoftware.reflectasm</pattern>
                        <shadedPattern>com.thinkaurelius.shaded.reflectasm_1_07</shadedPattern>
                    </relocation>
                    <relocation>
                        <pattern>com.esotericsoftware.shaded.org.objenesis</pattern>
                        <shadedPattern>com.thinkaurelius.shaded.objenesis_1_2</shadedPattern>
                    </relocation>
                </relocations>
                <!-- false below means the shade plugin overwrites the main project artifact (the one with no classifier).
                     false does *not* actually detach the main artifact, despite what the option name suggests. -->
                <shadedArtifactAttached>false</shadedArtifactAttached>
                <minimizeJar>false</minimizeJar>
            </configuration>
        </execution>
    </executions>
</plugin>

However I cannot figure out what I should change except the groupId to: <groupId>com.esotericsoftware.kryo</groupId> If I change the version number to 3.0.1 it cannot find the shaded classes (throws ClassNotfound exception:

java.lang.NoClassDefFoundError: com/thinkaurelius/shaded/kryo_3_0_1/kryo/Serializer
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at com.thinkaurelius.titan.graphdb.database.serialize.kryo.KryoSerializer.<init>(KryoSerializer.java:71)
at com.thinkaurelius.titan.graphdb.database.serialize.StandardSerializer.<init>(StandardSerializer.java:29)
at com.thinkaurelius.titan.graphdb.database.serialize.StandardSerializer.<init>(StandardSerializer.java:41)
at com.thinkaurelius.titan.diskstorage.configuration.backend.KCVSConfiguration.<init>(KCVSConfiguration.java:69)
at com.thinkaurelius.titan.diskstorage.configuration.backend.KCVSConfiguration.<init>(KCVSConfiguration.java:57)
at com.thinkaurelius.titan.diskstorage.configuration.KCVSConfigTest.getConfig(KCVSConfigTest.java:31)

I think the problem is that Kryo 2.22 has a different groupId (com.esotericsoftware.kryo) than Kryo 3.0.1 and that Maven cannot connect the dependency. How do I resolve this?


Solution

  • It appeared that the following line in the maven shade plugin:

    <include>com.esotericsoftware.kryo:*</include>
    

    had to be changed to:

    <include>com.esotericsoftware:*</include>
    

    Since the groupId is different. So the problem was a mismatch of a dependency.