Hi - Having a small problem with the new IDE. I’ve gotten the FRC supported standard libraries installed & visible using what comes from the vendor and the instructions from the WPI docs. But can anyone point to a help section (or on-line tutorial somewhere) about creating what I need for other ones we have used in the past (for example, slf4j and logback for our logging implementation). In the past, you just dropped them in the right folder and Eclipse picked them up. I assume I need to write some kind of Maven or JSON file - but looking at the two from CTRE and KauaiLabs … I am not sure where to start). Thanks in advance! --Stu
OK … I added the following to the dependencies block in build.gradle (which had none of the CTRE or KauaiLabs stuff):
https://mvnrepository.com/artifact/org.slf4j/slf4j-simple/1.7.25
https://mvnrepository.com/artifact/ch.qos.logback/logback-classic/1.2.3
https://mvnrepository.com/artifact/ch.qos.logback/logback-core/1.2.3
which are the three jars I need.
I am on Window-7 … so I’m not sure how I run the “./gradlew” command, as that seems to be a *nix approach. There is a gradlew.bat in my tree - but I’m not sure how to run that equivalently.
Thanks in advance!
For CTRE libraries, I asked the same question here: Importing CTRE through Gradle build system without VS Code.
On windows 7, if you want to run the “gradlew” command, you will open a command prompt (or powershell) and “cd” to the directory with all your project files in it. From there, type “gradlew.bat” followed by whatever arguments you need to pass to the command.
If you install VS Code and the WPI Plugin, your experience will be much smoother. If you don’t want to use VS Code (like me), then just run gradlew on Mac OS/Linux and gradlew.bat on windows.
I did install VS Code and the WPI Plugin.
If I right click on “gradlew.bat” and select “Open in Terminal” it opens what appears to be a Windows command shell in the folder (as a “dir” command gives a list of files which seems to match). I tried typing the following “gradlew.bat clean build --refresh-dependencies” which promptly blew up with a failure on line 56 of build.gradle which is exactly the line that ends the three now lines I added to the dependencies block per the initial help.
If I remove those three lines for my additions, the command runs fine.
Is there something other than the “https” format of the dependency?
Note that there are two ways of getting dependencies:
-
For standard open source libraries as describe above.
-
For non standard of custom stuff that you can’t/don’t want to put in an internet repository.
dependencies {
externalLibs files(‘libs/commons-lang.jar’, ‘libs/log4j.jar’)
}
More examples are in the Gradle docs
A dependency in Gradle is not a URL to a jar file hosted on a website or located in the filesystem somewhere. It’s the coordinates to such a URL that is independent of the server that hosts it.
Gradle (and the Maven dependency system in general) has a notion of repositories that store libraries, and libraries are specified in your build system as dependencies. Instead of saying , “hey, here’s a JAR file I want to use”, you tell the build system how to find the artifact you want, and in what scope it should be used:
repositories {
// Search for artifacts in the central Maven repository
mavenCentral()
}
dependencies {
// Tell the build system to use SLF4J 1.7.6 as a compile-time dependency
compile(group: 'org.slf4j', name: 'slf4j-simple', version: '1.7.6')
}
The group
in a dependency roughly corresponds to an organizations repository, in which all the libraries they publish are available, and in this example corresponds to this URL that Gradle will use to look for the artifact: https://repo1.maven.org/maven2/org/slf4j/
name
is the name of the library: slf4j-simple
, and so Gradle will look in the directory with that name in the URL I specified above.
version
is simply the version of the library to use.
This setup has several advantages over the old “download a JAR” system. Gradle will handle all transitive dependencies for you and automatically download them as well. Updating a dependency to a newer version (or downgrading to an older one) is done just by changing the version
specifier. You don’t need to include your dependencies in your project, since Gradle will just download them into its local cache if they’re not present.
This is actually the standard way of using Gradle, Maven, and other distributed dependency systems. The vendor JSON format is just for FRC so we can guarantee that a computer can be set up with a development environment and all the dependencies needed to write a robot program without any internet connection.
Jeanne & Sam -
Thank you for your help - the dependencies method worked perfectly (I haven’t had a chance to try the “offline” version of placing them in a lib and adding the externalLibs specification yet … we don’t really have external Internet at our build space). But I now have the logger running.
Thank you both again very much!
Stu