在gradle构建的 buildScript 部分或构建的根级别中声明存储库之间有什么区别 .
buildScript
选项1:
build.gradle :
buildScript { repositories { mavenCentral(); } }
要么
repositories { mavenCentral(); }
buildScript块中的存储库用于获取buildScript依赖项的依赖项 . 这些是放在构建的类路径上的依赖项,您可以从构建文件中引用它们 . 例如互联网上存在的额外插件 .
根级别的存储库用于获取项目所依赖的依赖项 . 所以编译项目所需的所有依赖项 .
构建脚本(即build.gradle)可能对构建脚本本身的执行具有一些依赖性 . 您可以将这些依赖项包含在buildScript块中 . Chapter 4 of Gradle Beyond the Basics详细描述了它 .
我想给你清楚的概念 . 出于这个原因,我附上了 build.grade 快照代码以便更好地理解 .
buildscript dependencies:
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' } }
root level/core dependencies:
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文件将从buildscript库中下载 . [项目外部依赖项] ii)根级依赖项jar文件将从根级别存储库下载 . [对于项目依赖性]
这里,
“buildscript”块仅控制buildscript进程本身的依赖关系,而不是应用程序代码 . 作为各种gradle插件,如 gradle-cobertura-plugin , gradle-lint-plugin 可以从buildscript repos中找到 . 这些插件不会被引用为应用程序代码的依赖项 .
gradle-cobertura-plugin
gradle-lint-plugin
但是对于项目编译和测试,可以从根级别存储库中找到像 groovy all jar, junit and testng jar 这样的jar文件 .
groovy all jar, junit and testng jar
And another thing , maven { url("https://plugins.gradle.org/m2/") } 部分可以在两个块中使用 . 因为它们用于不同的依赖项 .
maven { url("https://plugins.gradle.org/m2/") }
Resource Link: Difference between dependencies within buildscript closure and core
3 回答
buildScript块中的存储库用于获取buildScript依赖项的依赖项 . 这些是放在构建的类路径上的依赖项,您可以从构建文件中引用它们 . 例如互联网上存在的额外插件 .
根级别的存储库用于获取项目所依赖的依赖项 . 所以编译项目所需的所有依赖项 .
构建脚本(即build.gradle)可能对构建脚本本身的执行具有一些依赖性 . 您可以将这些依赖项包含在buildScript块中 . Chapter 4 of Gradle Beyond the Basics详细描述了它 .
我想给你清楚的概念 . 出于这个原因,我附上了 build.grade 快照代码以便更好地理解 .
buildscript dependencies:
root level/core dependencies:
所以,首先我想用一个字来澄清
这里,
“buildscript”块仅控制buildscript进程本身的依赖关系,而不是应用程序代码 . 作为各种gradle插件,如
gradle-cobertura-plugin
,gradle-lint-plugin
可以从buildscript repos中找到 . 这些插件不会被引用为应用程序代码的依赖项 .但是对于项目编译和测试,可以从根级别存储库中找到像
groovy all jar, junit and testng jar
这样的jar文件 .And another thing ,
maven { url("https://plugins.gradle.org/m2/") }
部分可以在两个块中使用 . 因为它们用于不同的依赖项 .Resource Link: Difference between dependencies within buildscript closure and core