Adding third-party Java dependencies to gradle

I am working on a vision processing system with a Jetson TX2. To do this, I am using RESTEasy to query the Jetson over HTTP in a separate thread. However, I can’t seem to add the RESTEasy dependency correctly to the gradle build project.

I added the library’s locations to the dependencies list in build.gradle:

dependencies {
compile wpi.deps.wpilib()
compile ‘javax.json:javax.json-api:1.0’
compile ‘javax.json.bind:javax.json.bind-api:1.0’
compile ‘’
compile ‘org.glassfish.jersey.core:jersey-client:2.0-m04’
compile ‘org.jboss.resteasy:resteasy-client:3.0.14.Final’
compile ‘org.jboss.resteasy:resteasy-jackson-provider:2.3.4.Final’
compile ‘com.fasterxml.jackson.core:jackson-annotations:2.9.6’
nativeZip wpi.deps.vendor.jni(wpi.platforms.roborio)
nativeDesktopZip wpi.deps.vendor.jni(wpi.platforms.desktop)
testCompile ‘junit:junit:4.12’

I’ve tried building the robot code when I was still connected to the internet before deploying it in the hope that it would download the needed jar files, but I’ve had no luck.

In addition, to verify that this was in fact a dependency problem with the RoboRio, I wrote a gradle script for a test build and ran it in a local Linux VM while I was connected to the TX2:

task query_jetson(type:JavaExec) {
dependsOn ‘:build’
main=“frc.robot.lib.trajectory.jetsoninterface.Que ryJetsonTest”
classpath = sourceSets.main.runtimeClasspath

The code worked perfectly, indicating that there is some dependency issue specific to WPILib or problem with how gradle is pushing my code to the RoboRio.

Any suggestions for what my next step should be?

Is gradlerio giving you an error during the deploy, or is it deploying and then giving an error at runtime?

@Thad_House it is an error during runtime, when I try to use the RESTEasy library from code on the RoboRio.

Can you please post a log of your error?

@Jaci I repeatedly got the following error from RESTEasy: “Unable to find a MessageBodyReader of content-type application/json and type class java.lang.String”

The exact error I got was described in detail here and resolved by adding a dependency which I already have in my build.gradle.

As I mentioned, I do not get this error when I build the project locally, which means it has to be a problem with something specific to the RoboRio. I wouldn’t be asking on this forum if this were a problem with RESTEasy–I believe I have narrowed this down to a WPILib/GradleRio issue.

Before being deployed to the RIO, all libraries are embedded into a single jar. From what I can tell, RESTEasy relies on them being in multiple jars on the classpath, each with their own META-INF file. When merged into a single jar (a “fat” jar), only one META-INF can exist, which is why they aren’t being detected.

This appears to be a problem in RESTEasy, not GradleRIO, since RESTEasy can’t properly support merged / bundled / fat jars.

You may be able to work around it by manually adding some manifest entries.

See these two answers for how to solve your issue:

Ah, thank you so much! That explains it.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.