From the course: Gradle for Java-Based Applications and Libraries

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Declaring a dependency on an external library

Declaring a dependency on an external library

From the course: Gradle for Java-Based Applications and Libraries

Start my 1-month free trial

Declaring a dependency on an external library

- [Instructor] To declare a dependency for a Java-based project, you will need to understand three aspects. First of all, we need to know the coordinates of the dependency you want to consume. Maven calls this the group, artifact, and version of the dependency, in short GAV. Let's hop over to Maven Central and search for the dependency commons-cli. We'll use the dependency to write more sophisticated code for defining and parsing command line options for the program. To consume the dependency, we will first have to declare the repository using the repositories method. Assign the shortcut method, mavenCentral, so that Gradle knows where to resolve the dependency from. Next up, define the list of dependencies with the dependencies method call. Within the dependencies block, we will define the GAV of the commons-cli dependency with version 1.4. You can grab the notation from the Maven Central search result. The scope…

Contents