Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are some gradle dependencies working with no version supplied

Tags:

gradle

As far as I know gradle requires a version number when setting dependencies, but partial wildcards are allowed. For example if I want Guava, I cannot do this as it fails:

compile('com.google.guava:guava')

It has to be (as an example):

compile('com.google.guava:guava:21.0')

However, I'm learning Spring, which has the following:

compile("org.springframework.boot:spring-boot-starter")
compile("org.springframework:spring-web")
compile("com.fasterxml.jackson.core:jackson-databind")

How are these dependencies working with no version supplied?

Is it because of the following, but I thought these lines were required only for my plugin 'org.springframework.boot':

buildscript {
 repositories {
    mavenCentral()
 }
 dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-plugin:1.4.3.RELEASE")
 }
}
like image 761
Neil Walker Avatar asked Jan 16 '17 12:01

Neil Walker


People also ask

How does Gradle resolve transitive dependencies?

Releases of a module hosted on a repository can provide metadata to declare those transitive dependencies. By default, Gradle resolves transitive dependencies automatically. The version selection for transitive dependencies can be influenced by declaring dependency constraints.

Where does Gradle get its dependencies?

Gradle can consume dependencies available in the local Maven repository. Declaring this repository is beneficial for teams that publish to the local Maven repository with one project and consume the artifacts by Gradle in another project. Gradle stores resolved dependencies in its own cache.

How do I know if Gradle dependency has new version?

Go to Android Studio -> Preferences -> Plugins (for Mac) and File -> Settings -> Plugins (for windows) and search “Check for Dependency updates plugin”. Install it and restart android studio. You will be able to see Dependencies tab on the right which will show if any dependency has a new update available.


2 Answers

It is worth mentioning that the trick is called BOM (bill of materials) and the actual versions can be checked in the related POM file (in this example, it is for the version 2.7.0) inside spring-boot-dependencies package. This is mentioned in the Spring Boot official documentation here: Build Systems.

Another way that Spring provides this (for non Boot projects) is through Spring Platform BOM where it actually provides version for the following dependencies.

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'io.spring.gradle:dependency-management-plugin:0.6.0.RELEASE'
    }
}

apply plugin: 'io.spring.dependency-management'

dependencyManagement {
    imports {
        mavenBom 'io.spring.platform:platform-bom:Athens-SR2'
    }
}
like image 96
hakamairi Avatar answered Nov 09 '22 06:11

hakamairi


TL;DR - spring boot uses custom dependencies resolver.

A spring boot plugin that is applied with the following piece of code:

apply plugin: 'spring-boot'

handles the dependencies that are listed without version. This logic is implemented in this class which delegates it to here. DependencyManagementPluginFeatures are applied here.

like image 30
Opal Avatar answered Nov 09 '22 05:11

Opal