We are trying to use Gson (a third party library) and cannot find any documentation about how to specifically add a library when using VS-Code. Last year we used Eclipse and it seemed pretty straightforward, but we weren’t using Gson then, so we don’t know for sure.
WPILIB has created some Gradle code for building and deploying, but this is our first exposure to Gradle. At first we just tried installing Gson according to standard methodologies and we were able to get it to build in VS-Code when we were just doing a non-WPILIB build – i.e. building a stand-alone program (non-robot program) that we ran on the same PC as the build.
But when we started putting Gson into a robot program and building with the WPILIB build stuff, it would not find Gson. We dug into Gradle documentation and tried a bunch of stuff until we were finally able to get the build to see Gson. What we did was modify the build.gradle file by adding
build
repositories {
mavenCentral()
}
before dependencies, and within dependencies we added
implementation ‘com.google.code.gson:gson:2.8.5’
right before compile wpilib(). This allowed the project to build, but after we deploy to the robot we are getting message that our code stopped because it couldn’t find Gson at run-time. Not being very familiar with Gradle and Groovy, really, we are at a loss as to what to do next. I think we need to modify the jar {} statement, but I have no idea what change is necessary.
I had the exact same problem. I posted here as well and I fixed my issue. You want to use “compile”. Here is our build.gradle for reference when I added Json libraries.