在 Gradle 构建中,将仓库声明在 buildscript
部分和根级别的构建中有什么区别?
buildscript {
repositories {
mavenCentral();
}
}
对抗
repositories {
mavenCentral();
}
在 Gradle 构建中,将仓库声明在 buildscript
部分和根级别的构建中有什么区别?
buildscript {
repositories {
mavenCentral();
}
}
对抗
repositories {
mavenCentral();
}
buildscript
区块中的仓库用于获取您的buildscript
依赖项的依赖关系。这些依赖关系被放置在构建类路径上,您可以在构建文件中引用它们。例如:互联网上存在的额外插件。
根级别上的仓库用于获取您的项目所依赖的依赖项。因此,所有编译您的项目所需的依赖项都在其中。
我希望能够给您一个清晰的概念。为此,我附上了build.grade的代码快照,以便更好地理解。
buildscript依赖项:
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 文件将从根级别仓库中下载。[项目依赖]
maven { url("https://plugins.gradle.org/m2/") }
部分可以在两个块中使用。因为它们用于不同的依赖关系。
资源链接:dependencies within buildscript closure and core 的区别