Vatuu / discord-rpc

Java Wrapper of the Discord-RPC Library for Discord Rich Presence.
MIT License
194 stars 42 forks source link

Shading of jar does not work #34

Open 1-alex98 opened 5 years ago

1-alex98 commented 5 years ago

I am not an expert on this, but here is my problem.

My app uses jna version 5.0.0. Discord-rpc uses version 4.5.1

When running my app it loads the jna lib from the discord library making it crash with NoSuchMethodError.

The solution to the issue is the library using the shade plusgin as described here https://labs.spotify.com/2015/09/01/java-linking/ .

If I look into your maven pom.xml then I see you use that plug-in

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
</plugin>

So there should not be any problems but the classes are never the less normally included in the discord-rpc jar and i would expect them to be under net.arikia.dev path or something so my app does not load them as jna. I do admit I got not much of an idea of this shading plugin...

Maybe I will have a look into it, but would be cool if somebody of u could do it I have a really hard time reading into that shade-plugin docu.

1-alex98 commented 5 years ago

After reading it again. I think you need to relocate the libraries by hand like so:

<relocations>
                <relocation>
                       <pattern>net.java.dev.jna</pattern>
                        <shadedPattern>net.arikia.dev.jna</shadedPattern>
                 </relocation>
</relocations>

Read this https://maven.apache.org/plugins/maven-shade-plugin/examples/class-relocation.html

1-alex98 commented 5 years ago

Like this :

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <relocations>
                                <relocation>
                                    <pattern>com.sun.jna</pattern>
                                    <shadedPattern>net.arikia.dev.jna</shadedPattern>
                                </relocation>
                            </relocations>
                        </configuration>
                    </execution>

                </executions>
            </plugin>
DeJayDev commented 5 years ago

I'm also not an expert on this, so at least we're on the same page.

If you're including JNA and not using it it is best to let discord-rpc handle the bindings. However, if you ARE using JNA for a custom solution of your own, I can look into shading so that our dependencies don't get in the way of yours.

1-alex98 commented 5 years ago

I am using JNA my self that is the issue and a newer version 5.0.0