我有一个包含几个模块的Gradle项目,其中有一个模块实现了Gradle插件(plugin-subproject),一个模块展示了这个插件(sample-subproject):
plugin-subproject
│ build.gradle
sample-subproject
│ build.gradle
other subprojects...
│ build.gradle
build.gradle在sample-subproject中,我依赖于插件:
buildscript {
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
classpath "myplugin:gradle-plugin:0.1.0"
}
}
apply plugin: "myplugin.plugin"它必须从本地存储库获取插件。
问题:为了构建sample-subproject,必须将插件安装到本地Maven存储库中。但是我无法安装它,因为如果我运行./gradlew :plugin-subproject:install,它就会失败。
* What went wrong:
A problem occurred configuring project ':sample-subproject'.
> Could not resolve all artifacts for configuration ':sample-subproject:classpath'.
> Could not find myplugin:gradle-plugin:0.1.0.
Searched in the following locations:
- https://repo.maven.apache.org/maven2/myplugin/gradle-plugin/0.1.0/gradle-plugin-0.1.0.pom
- file:/Users/myuser/.m2/repository/myplugin/gradle-plugin/0.1.0/gradle-plugin-0.1.0.pom
- https://plugins.gradle.org/m2/myplugin/gradle-plugin/0.1.0/gradle-plugin-0.1.0.pom
Required by:
project :sample-subproject我可以删除sample-subproject,将插件安装到本地maven存储库,然后我可以成功地添加和构建示例项目。但这是一个黑客,我想用标准的方式解决这个问题。
问题:如何与使用它的子项目一起构建一个Gradle插件项目?
发布于 2021-01-02 20:09:40
您可以在主build.gradle中添加行
build.dependsOn ":plugin-subproject:build"在settings.gradle中有定义模块的方法
rootProject.name = 'project-name'
include "plugin-subproject"
include "sample-subproject"
include "other subprojects"并建立如下的依赖关系:
dependencies {
implementation project(':plugin-subproject')
}但没有书面证据表明这是正确的方式来做正确的顺序组装模块。
https://stackoverflow.com/questions/65542529
复制相似问题