How to publish and use gradle plugin with dependencies on local project?

不问归期 提交于 2019-12-12 19:58:43

问题


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'
        }
    }
}

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: ...

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).

Can someone help me how can I publish gradle plugin with its local dependencies and use it in another project ?

Thank you very much for any help.


回答1:


We ended up using the Gradle shadow plugin to include our module in the published artifact.

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:'))
   }
}


来源:https://stackoverflow.com/questions/54831685/how-to-publish-and-use-gradle-plugin-with-dependencies-on-local-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!