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

Druudik :

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.

laochiv :

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=151902&siteId=1