Java 如何与使用Gradle插件的子项目一起构建Gradle插件项目?
我有一个带有几个模块的Gradle项目,其中有一个模块实现了Gradle插件(Java 如何与使用Gradle插件的子项目一起构建Gradle插件项目?,java,gradle,groovy,gradle-plugin,Java,Gradle,Groovy,Gradle Plugin,我有一个带有几个模块的Gradle项目,其中有一个模块实现了Gradle插件(插件子项目),还有一个模块展示了这个插件(示例子项目): 在示例子项目中,我依赖于插件: buildscript { repositories { mavenCentral() mavenLocal() } dependencies { classpath "myplugin:gradle-plugin:0.1.0" }
插件子项目
),还有一个模块展示了这个插件(示例子项目
):
在示例子项目
中,我依赖于插件:
buildscript {
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
classpath "myplugin:gradle-plugin:0.1.0"
}
}
apply plugin: "myplugin.plugin"
它必须从本地存储库获取插件
问题:为了构建示例子项目
,必须将插件安装到本地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
我可以删除示例子项目
,将插件安装到本地maven存储库中,然后我可以成功地添加和构建示例项目。但这是一种黑客行为,我想用一种标准的方式解决这个问题
问题:如何将Gradle插件项目与使用它的子项目一起构建?您可以在main
build.Gradle中添加行:
build.dependsOn ":plugin-subproject:build"
附言。
有一种方法可以在设置中定义模块。gradle
rootProject.name = 'project-name'
include "plugin-subproject"
include "sample-subproject"
include "other subprojects"
并使依赖项如下所示:
dependencies {
implementation project(':plugin-subproject')
}
但没有文件证明这是正确的组装模块顺序。谢谢。插件子项目是。它不需要位于依赖项中,它必须位于buildscript
部分,因为它涉及到构建示例子项目
。尽管如此,我还是试过了。不幸的是,我也犯了同样的错误。如果我理解正确,你尤金是正确的。如果您的项目中有一个Gradle插件供您的项目使用,那么它应该在buildSrc
中实现。您可以使用+
作为类路径版本:classpath“myplugin:Gradle plugin:0.1.+”
来依赖最新发布的版本。但是,您将无法使用当前版本。@Phil thast是我正在做的,但它不方便。
dependencies {
implementation project(':plugin-subproject')
}