问题描述
我正在创建gradle插件,该插件依赖于其他本地模块。它的某些gradle构建看起来像这样:
I am creating gradle plugin which has dependency on my other local module. Some of its gradle build look like this:
dependencies {
compile gradleApi()
compile project(":myDependencyProject")
}
publishing {
publications {
maven(MavenPublication) {
groupId = 'org.my.gradle.plugin'
artifactId = 'some-name'
version = '1.0-SNAPSHOT'
from components.java
}
}
}
gradlePlugin {
plugins {
jsonPlugin {
id = 'org.my.gradle.plugin'
implementationClass = 'my.implementation.class'
}
}
}
当我发布时我的插件使用 gradle publishToMavenLocal 之后,我尝试在另一个项目中使用该插件,但失败并出现以下错误:
When I publish my plugin using gradle publishToMavenLocal and after that I try to use that plugin in another project it fails with this error:
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring project ':my-project'.
> Could not resolve all artifacts for configuration ':my-project:classpath'.
> Could not find org.my.gradle.plugin:myDependencyProject:1.0-SNAPSHOT.
Searched in the following locations: ...
简单来说,它找不到依赖项用于myDependencyProject项目。这就是为什么下一步我尝试创建一个胖罐子并将其发布,但是我遇到了相同的错误(gradle插件的代码是相同的,除了我已将组件Java中的更改为
到 artifact shadowJar
)。
In simple words it could not find dependency for myDependencyProject project. That is why as a next step I tried to create a fat jar and publish it but I have got the same error (the code for gradle plugin was same except I have changed from components java
to artifact shadowJar
).
有人可以帮助我如何发布具有本地依赖项的gradle插件和
Can someone help me how can I publish gradle plugin with its local dependencies and use it in another project ?
非常感谢您的帮助。
推荐答案
我们最终使用了将我们的模块包含在。
We ended up using the Gradle shadow plugin to include our module in the published artifact.
对我们很重要的一件事但是,仅在其中包含本地图书馆是为了防止我们的最终用户拥有某些图书馆(如Kotlin)的2份副本。因此,我们
One thing that was important to us though, was to only include the local library in it to prevent our end consumer from having 2 copies of some library (such as Kotlin). So we filtered the dependencies
shadowJar {
dependencies {
include(dependency(':your-module-name:'))
}
}
这篇关于如何发布和使用依赖于本地项目的gradle插件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!