Unable to add Json Dependency in build.gradle

Hi.
I added this line:
compile group: ‘org.json’, name: ‘json’, version: ‘20180813’

in the dependency section of build.gradle

but I get an error and I have looked everywhere online. I even talked to Jason on 2073 who was also confused.

Error:

> Could not resolve all files for configuration ‘:compile’.
> Could not find org.json:json:20180813.
Searched in the following locations:
- http://first.wpi.edu/FRC/roborio/maven/release/org/json/json/20180813/json-20180813.pom
- http://first.wpi.edu/FRC/roborio/maven/release/org/json/json/20180813/json-20180813.jar
- http://dev.imjac.in/maven/org/json/json/20180813/json-20180813.pom
- http://dev.imjac.in/maven/org/json/json/20180813/json-20180813.jar
- https://raw.githubusercontent.com/Open-RIO/Maven-Mirror/master/m2/org/json/json/20180813/json-20180813.pom
- https://raw.githubusercontent.com/Open-RIO/Maven-Mirror/master/m2/org/json/json/20180813/json-20180813.jar

Please let me know if you have a solution for this. Thank you.

You need to add mavenCentral as a repository to look at. It is not added by default to the wpilib examples.

repositories {
mavenCentral()
}

I added that in settings.gradle and it still gives me the same error. :frowning:

Sent from my Pixel XL using Tapatalk

Can you post your full build.gradle? The mavenCentral() declaration Thad mentioned goes in build.gradle not settings.gradle.

Here’s ours where we pull in google’s json-simple:

You’re right! I added that to build.gradle and it worked flawlessly. I guess when you create a template in vscode it doesn’t add that repository section in the build.gradle. thank you everyone for you help!

Sent from my Pixel XL using Tapatalk

Dont add it to build.gradle
Download the jar and put it in USER/wpilib/user/java/lib/json.jar
it will compile.

I would not recommend following this advice - adding to build.gradle allows you to more easily update dependencies when needed and automatically download them when first setting up a project on a new computer. Adding to build.gradle is a more standard-compliant way to track dependencies, and will help prevent accidents where one forgets to download one of them. The manual download way is (as far as I can remember) deprecated for next year.

As was stated elsewhere in the thread, the repositories block isn’t a part of the template’s build.gradle, so will need to be added manually.

Yup. Downloading and placing into a folder is a brute force way of making sure you have exactly the same jar every build (say, if you don’t trust Gradle to do that for some reason, or it’s not available in a repository, or something like that maybe… eh).

The key is that you don’t want it outside of version control. Putting into the local disk User folder will mean that any time you want to change that Jar version (or deply from a new PC), you have to manually update the file. Not the end of the world, but definitely doesn’t scale well (what if you had to maintain this project for 5 years, onboarding someone new every month? what if you had to change the version of that jar file every month?).

The folder in user/wpilib will no longer work in 2019, and doesn’t work in the alpha either. So for the gradlerio stuff, in the build.gradle is absolutely the right way to do it.

Technically the stuff in the build.gradle file isn’t in the version control either, because the actual dependencies get put in your local gradle repo.
(generally in USER_HOME/.gradle/)

I agree with your point, however.

Very true! In the case of gradle, you create files in version control that specify to the tool what .jar’s you need (rather than just keeping the .jar’s themselves there). Insert explanation about why caching is good in this case here.

I have the new vscode working with the plugins.(java) We are using the zip portable version of vscode. I have added the data folder to make it portable. I was able to build the code at home where I have normal internet. At school the district blocks the download of the dependency jar files. I thought the downloads would be saved in the vscode data folder and then we could build at school. Any work arounds for restrictive school internet environments when trying to build the code? What about at competition? I could see either not having internet or having a restricted internet and then not being able to build. Any suggestions?

Thank you.

Sam Alexander
Team 1290

If you’ve already built on that computer, you should be able to use

.\gradlew build --offline

I recommend making a new topic in the future, instead of piggybacking off of other threads