简体   繁体   中英

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM