java - 如何与使用它的子项目一起构建 Gradle 插件项目?
问题描述
我有一个带有几个模块的 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 插件项目与使用它的子项目一起构建?
解决方案
您可以在 main 中添加行build.gradle
:
build.dependsOn ":plugin-subproject:build"
PS有办法在settings.gradle
rootProject.name = 'project-name'
include "plugin-subproject"
include "sample-subproject"
include "other subprojects"
并使依赖项像这样:
dependencies {
implementation project(':plugin-subproject')
}
但没有书面证据表明这是按正确顺序组装模块的正确方法。
推荐阅读
- visual-studio-code - VScode 自动完成功能不适用于 CSS 文件
- c# - 在 C# 和 MySQL 中使用 Dapper 进行查询
- javascript - Chartjs:旋转轴标题
- amazon-web-services - aws 的 lambda 日志中没有显示任何消息
- laravel - laravel-jsvalidation 包不支持所见即所得编辑器
- json - 如何在颤动中限制 JSON 数组输出?
- node.js - 将变量传递给 Dockerfile CMD、Nodejs
- matlab - 如何在 Matlab 中将 k 折交叉验证与“模式网络”神经网络一起使用?
- python - 在 Python 中读取 gz/gzip XML Sitemap
- javascript - 如何使用 JavaScript 防止移动设备上的睡眠模式