没有提供任何版本的情况下,一些gradle依赖关系如何工作 [英] How are some gradle dependencies working with no version supplied

查看:130
本文介绍了没有提供任何版本的情况下,一些gradle依赖关系如何工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,在设置依赖关系时,gradle需要一个版本号,但允许部分通配符。例如,如果我想要番石榴,我不能这样做,因为它失败了:

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

它必须是(作为例子):

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

然而,我正在学习Spring,它包含以下内容:

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

这些依赖关系是如何在没有提供任何版本的情况下工作的?



这是因为以下原因,但我认为这些行仅仅是我的插件'org.springframework.boot'所必需的:

  buildscript {
repositories {
mavenCentral()
}
依赖项{
classpath(org.springframework.boot:spring-boot-gradle-plugin:1.4.3 .RELEASE)
}
}
spring-boot-dependencies项目中检查一>。这在以下文档中提到: http://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-build-systems.html



< Spring提供的另一种方式(对于非引导项目)通过 Spring Platform BOM 执行实际上提供了以下依赖项的版本。

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

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

dependencyManagement {
impor ts {
mavenBom'io.spring.platform:platform-b​​om:Athens-SR2'
}
}


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")
 }
}

解决方案

It worth mentioning that the trick is called BOM (bill of materials) and the actual versions can be checked in spring-boot-dependencies project. This is mentioned in the documentation under: http://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-build-systems.html

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'
    }
}

这篇关于没有提供任何版本的情况下,一些gradle依赖关系如何工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆