Skip to content
This repository has been archived by the owner on Apr 9, 2023. It is now read-only.

Shading of jar does not work #34

Open
1-alex98 opened this issue May 4, 2019 · 4 comments · May be fixed by #35
Open

Shading of jar does not work #34

1-alex98 opened this issue May 4, 2019 · 4 comments · May be fixed by #35

Comments

@1-alex98
Copy link

1-alex98 commented May 4, 2019

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
Copy link
Author

1-alex98 commented May 4, 2019

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
Copy link
Author

1-alex98 commented May 4, 2019

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>

@1-alex98 1-alex98 linked a pull request May 4, 2019 that will close this issue
@DeJayDev
Copy link
Collaborator

DeJayDev commented May 4, 2019

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
Copy link
Author

1-alex98 commented May 4, 2019

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants