为Gradle中的所有项目配置存储库
我正在尝试为所有子项目配置存储库 我有主要的为Gradle中的所有项目配置存储库,gradle,Gradle,我正在尝试为所有子项目配置存储库 我有主要的build.gradle: buildscript { repositories { mavenLocal() mavenCentral() google() jcenter() ... } dependencies { // NOTE: Do not place your application dependencies here;
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 :
我想在主文件中定义一次存储库
,因为这些存储库在子项目中不会更改
在主项目的
设置.gradle
中,我有:
rootProject.name = 'main-project-name'
include 'sub-project-name'
rootProject.name = 'sub-project-name'
在子项目的设置.gradle
中,我有:
rootProject.name = 'main-project-name'
include 'sub-project-name'
rootProject.name = 'sub-project-name'
Gradle中的多项目生成可能有多个
build.Gradle
文件,但只有一个settings.Gradle
文件(通常在根项目目录中)。第二个设置.gradle
文件定义了仅包含单个项目的第二个设置。您可以通过运行gradleprojects
来检查这一点。只需删除第二个设置.gradle
文件即可解决问题
通常,您可以通过命名相应的目录,然后调用include
来定义子项目的名称。rootProject
的名称可以在settings.gradle
中定义,因为目录的名称通常不存储在Git之类的版本控制系统中。开发人员可能会将存储库签出到不同的目录,从而导致Gradle对根项目使用不同的名称。如果希望子项目的名称与其包含目录不同,请使用所需名称的include
,然后通过project(':foo').projectDir=file('path/to/foo')
更改项目目录