【发布时间】:2021-01-02 18:16:38
【问题描述】:
我有一个带有多个模块的 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存储库,然后我可以成功添加和构建示例项目。但这是一个 hack,我想以标准方式解决问题。
问题:如何将 Gradle 插件项目与使用它的子项目一起构建?
【问题讨论】:
-
如果我理解正确,你need this
-
尤金是正确的。如果你的项目中有你的项目使用的 Gradle 插件,它应该在
buildSrc中实现。 -
您可以使用
+作为类路径版本:classpath "myplugin:gradle-plugin:0.1.+",来依赖 最新发布的 版本。但是,您将无法使用当前版本。 -
@Phil thast 是我正在做的,但是很不方便。
标签: java gradle groovy gradle-plugin