我有一个非常基础的多项目/多模块Gradle构建用例。我最终需要的结构复杂度不会比官方Gradle文档中声明子项目之间依赖关系的部分提出的更高。
将他们的文档复制到这里,我们有以下项目结构:
.
├── buildSrc
│ ...
├── api
│ ├── src
│ │ └──...
│ └── build.gradle
├── services
│ └── person-service
│ ├── src
│ │ └──...
│ └── build.gradle
├── shared
│ ├── src
│ │ └──...
│ └── build.gradle
└── settings.gradle
还有这些构建文件:
// settings.gradle
rootProject.name = 'dependencies-java'
include 'api', 'shared', 'services:person-service'
// buildSrc/src/main/groovy/myproject.java-conventions.gradle
plugins {
id 'java'
}
group = 'com.example'
version = '1.0'
repositories {
mavenCentral()
}
dependencies {
testImplementation "junit:junit:4.13"
}
// api/build.gradle
plugins {
id 'myproject.java-conventions'
}
dependencies {
implementation project(':shared')
}
shared/build.gradle
plugins {
id 'myproject.java-conventions'
}
// services/person-service/build.gradle
plugins {
id 'myproject.java-conventions'
}
dependencies {
implementation project(':shared')
implementation project(':api')
}
然而,当我尝试执行项目根目录下的 gradle build
命令时,实际测试时出现以下错误:
Plugin [id: 'myproject.java-conventions'] was not found in any of the following sources:
- Gradle Core Plugins (plugin is not in 'org.gradle' namespace)
- Plugin Repositories (plugin dependency must include a version number for this source)
为了好玩,我尝试添加版本号,但可预见的是 Gradle 一如既往地抱怨,称无法解析该构件。我做错了什么?
我的 Gradle 版本信息:
------------------------------------------------------------
Gradle 6.5.1
------------------------------------------------------------
Build time: 2020-06-30 06:32:47 UTC
Revision: 66bc713f7169626a7f0134bf452abde51550ea0a
Kotlin: 1.3.72
Groovy: 2.5.11
Ant: Apache Ant(TM) version 1.10.7 compiled on September 1 2019
JVM: 11.0.8 (Oracle Corporation 11.0.8+10)
OS: Windows 10 10.0 amd64
buildSrc
,这在文档中并不明确。但我会记录一个问题,让Gradle将build.gradle
添加到该目录中。 - Austin Brownplugins { \
kotlin-dsl` }` - st.ebberr