buildscript
在 gradle 构建部分或构建的根级别声明存储库有什么区别。
buildscript {
repositories {
mavenCentral();
}
}
相对
repositories {
mavenCentral();
}
buildscript
在 gradle 构建部分或构建的根级别声明存储库有什么区别。
buildscript {
repositories {
mavenCentral();
}
}
相对
repositories {
mavenCentral();
}
块中的存储库buildscript
用于获取依赖项的buildscript
依赖项。这些是放在构建的类路径中的依赖项,您可以从构建文件中引用它们。例如互联网上存在的额外插件。
根级别的存储库用于获取项目所依赖的依赖项。因此,编译项目所需的所有依赖项。
我想给你一个清晰的概念。出于这个原因,我附上了 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) buildscript 依赖项 jar 文件将从 buildscript 存储库下载。【项目外部依赖】
ii) 根级依赖项 jar 文件将从根级存储库下载。[对于项目依赖]
这里,
“buildscript” 块只控制 buildscript 进程本身的依赖关系,而不是应用程序代码。作为各种 gradle 插件gradle-cobertura-plugin
,gradle-lint-plugin
可以从 buildscript repos 中找到。这些插件不会被引用为应用程序代码的依赖项。
但是对于项目编译和测试运行的 jar 文件,groovy all jar, junit and testng jar
可以从根级存储库中找到。
另一件事,maven { url("https://plugins.gradle.org/m2/") }
部分可以在两个块中使用。因为它们用于不同的依赖项。