在gradle构建的buildScript
部分中声明存储库与在构建的根级别中声明存储库有什么区别。
选项1:
build.gradle
buildScript {
repositories {
mavenCentral();
}
}
或
build.gradle
repositories {
mavenCentral();
}
发布于 2012-12-18 20:15:43
buildScript块中的存储库用于获取buildScript依赖项的依赖项。这些是放在构建的类路径上的依赖项,您可以从构建文件中引用它们。例如存在于因特网上的额外插件。
根级别上的存储库用于获取项目所依赖的依赖项。因此,编译项目所需的所有依赖项。
发布于 2018-01-26 23:05:27
我想给你一个清晰的概念。出于这个原因,为了更好地理解,我附上了build.grade快照代码。
构建脚本依赖项:
buildscript {
repositories {
maven { url("https://plugins.gradle.org/m2/") }
}
dependencies {
classpath 'net.saliman:gradle-cobertura-plugin:2.3.2'
classpath 'com.netflix.nebula:gradle-lint-plugin:latest.release'
}
}
根级别/核心依赖项:
repositories{
mavenLocal()
maven { url("https://plugins.gradle.org/m2/") }
maven { url "https://repo.spring.io/snapshot" }
}
dependencies {
//Groovy
compile group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.3.10'
//Spock Test
compile group: 'org.spockframework', name: 'spock-core', version: '1.0-groovy-2.3'
//Test
testCompile group: 'junit', name: 'junit', version: '4.10'
testCompile group: 'org.testng', name: 'testng', version: '6.8.5'
}
所以,首先我想用一个词来说明
i)构建脚本依赖项jar文件将从构建脚本存储库中下载。项目外部依赖项
ii)将从根级存储库下载根级依赖项jar文件。用于项目依赖项的
这里,
“buildscript”块只控制buildscript进程本身的依赖关系,而不是应用程序代码的依赖关系。像gradle-cobertura-plugin
、gradle-lint-plugin
这样的gradle插件都可以从buildscript repos中找到。这些插件不会被引用为应用程序代码的依赖项。
但是对于项目编译和测试运行,可以从根级别的存储库中找到像groovy all jar, junit and testng jar
这样的jar文件。
和另一件事,maven { url("https://plugins.gradle.org/m2/") }
部分可以在这两个块中使用。因为它们用于不同的依赖项。
资源链接: Difference between dependencies within buildscript closure and core
https://stackoverflow.com/questions/13923766
复制相似问题