gradle - 在 Gradle 中为所有项目配置存储库
问题描述
我正在尝试为所有子项目配置存储库。
我有主要的build.gradle
:
buildscript {
repositories {
mavenLocal()
mavenCentral()
google()
jcenter()
...
}
dependencies {
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
plugins {
id 'base'
}
allprojects {
apply plugin: 'base'
repositories {
mavenLocal()
mavenCentral()
google()
jcentre()
...
}
wrapper{
gradleVersion = '6.5.1'
distributionType = Wrapper.DistributionType.ALL
}
dependencies {
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
在子项目中build.gradle
,我只有:
...
dependencies {
implementation ....
}
我正进入(状态:
Execution failed for task ':compileJava'.
> Could not resolve all files for configuration ':compileClasspath'.
> Cannot resolve external dependency .... because no repositories are defined.
Required by:
project :
我想repositories
在主文件中定义一次,因为这些在子项目中不会改变。
在settings.gradle
我的主要项目中:
rootProject.name = 'main-project-name'
include 'sub-project-name'
在settings.gradle
子项目中,我有:
rootProject.name = 'sub-project-name'
解决方案
Gradle 中的多项目构建可能有多个build.gradle
文件,但只有一个settings.gradle
文件(通常在项目根目录中)。您的第二个settings.gradle
文件定义了仅包含单个项目的第二个设置。您可以通过运行来检查这一点gradle projects
。只需删除第二个settings.gradle
文件即可解决您的问题。
通常你可以简单地通过命名相应的目录然后调用来定义你的子项目的名称include
。目录的名称rootProject
可能会在内部定义settings.gradle
,因为目录的名称通常不会存储在 Git 等版本控制系统中。开发人员可能会将存储库检出到不同的目录,从而导致 Gradle 为根项目使用不同的名称。如果您希望子项目具有与其包含目录不同的名称,请使用include
所需的名称,然后通过project(':foo').projectDir = file('path/to/foo')
.
推荐阅读
- regex - 通过正则表达式从导入中获取 npm 包名称(不是相对路径)
- swift - 下载百分比 (SWIFT)
- bash - 什么是 ._.bash_profile 文件
- ios - 在 xcode 上使用 Sqlite 的指南?
- java - 使用'>>'将int向右移动后如何将最高有效位更改为1?
- visual-studio-code - 对于特定类型的扩展,结束文件没有空行
- jaxb - 如何解决 JAXB IllegalAnnotationException 错误
- selenium-webdriver - 在 Selenium 中运行并行 Testng 测试
- azure - 检查 azure blob 容器中是否存在文件
- r - 将帧与 R 中的重叠数据相结合