1.15.2 Two same libraries

Discussion in 'Spigot Plugin Development' started by mnekos, Jan 21, 2020.

  1. My plugin has library "org.slf4j" and SkinsRestorer has the same library.

    When I enable both plugins it throws an exception:

    15:55:21 [WARNING] Exception encountered when loading plugin: MotdManager
    java.lang.LinkageError: loader constraint violation: when resolving method "org.slf4j.impl.StaticLoggerBinder.getLoggerFactory()Lorg/slf4j/ILoggerFactory;" the class loader (instance of net/md_5/bungee/api/plugin/PluginClassloader) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of net/md_5/bungee/api/plugin/PluginClassloader) for the method's defining class, org/slf4j/impl/StaticLoggerBinder, have different Class objects for the type org/slf4j/ILoggerFactory used in the signature
    at org.slf4j.LoggerFactory.getILoggerFactory(LoggerFactory.java:299)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:269)
    at redis.clients.jedis.HostAndPort.<clinit>(HostAndPort.java:12)
    at redis.clients.jedis.JedisFactory.<init>(JedisFactory.java:43)
    at redis.clients.jedis.JedisFactory.<init>(JedisFactory.java:35)
    at redis.clients.jedis.JedisPool.<init>(JedisPool.java:181)
    at redis.clients.jedis.JedisPool.<init>(JedisPool.java:145)
    at redis.clients.jedis.JedisPool.<init>(JedisPool.java:127)
    at redis.clients.jedis.JedisPool.<init>(JedisPool.java:76)
    at redis.clients.jedis.JedisPool.<init>(JedisPool.java:110)
    at redis.clients.jedis.JedisPool.<init>(JedisPool.java:93)
    at redis.clients.jedis.JedisPool.<init>(JedisPool.java:26)
    at pl.mnekos.motd.data.YAMLMotdDataLoader.getJedisPool(YAMLMotdDataLoader.java:63)
    at pl.mnekos.motd.MotdManagerPlugin.onEnable(MotdManagerPlugin.java:47)
    at net.md_5.bungee.api.plugin.PluginManager.enablePlugins(PluginManager.java:250)
    at net.md_5.bungee.BungeeCord.start(BungeeCord.java:280)
    at net.md_5.bungee.BungeeCordLauncher.main(BungeeCordLauncher.java:62)
    at net.md_5.bungee.Bootstrap.main(Bootstrap.java:15)

    How can I fix it?
     
  2. You can try and rebase the import using the maven shade plugin
     
  3. TeamBergerhealer

    Supporter

    Here is an example pom.xml section for shading in the ASM library:
    Code (Text):
            <!-- Plugins -->
            <plugins>
                <!-- Needed for shading in ASM, performing relocations -->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-shade-plugin</artifactId>
                    <version>2.0</version>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <goals>
                                <goal>shade</goal>
                            </goals>
                            <configuration>
                                <shadedArtifactAttached>true</shadedArtifactAttached>
                                <createDependencyReducedPom>false</createDependencyReducedPom>
                                <relocations>
                                    <relocation>
                                        <pattern>org.objectweb.asm</pattern>
                                        <shadedPattern>com.bergerkiller.mountiplex.dep.org.objectweb.asm</shadedPattern>
                                    </relocation>
                                </relocations>
                                <artifactSet>
                                    <includes>
                                        <include>org.ow2.asm</include>
                                    </includes>
                                </artifactSet>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
    This relocates the path of the library, 'org.objectweb.asm', to be located at 'com.bergerkiller.mountiplex.dep.org.objectweb.asm' instead.

    You can add this to the <configuration> section to also exclude portions of the library your plugin isnt using, to reduce the size of the final jar:
    Code (Text):
                                <minimizeJar>true</minimizeJar>