Search code examples
javamavengradlemaven-publishgradle-shadow-plugin

Exclude dependency from pom using Maven Publish Plugin?


I use the following plugins:

id 'maven-publish'
id "com.github.johnrengelman.shadow" version "7.0.0"

my dependencies:

dependencies {
    shadow gradleApi()
    shadow localGroovy()
    implementation 'com.example:lib:0.1.0'

my publishing block:

publishing {
    publications {
        pluginJar(MavenPublication) {  publication ->
            from project.shadow.component(publication)
            artifact sourceJar
        }
    }
}

When I run publishToMavenLocal task I can see that in result pom.xml contains a dependency that I do not want there.

Let's say it's:

<dependency>
  <groupId>com.example</groupId>
  <artifactId>lib</artifactId>
  <version>0.1.0</version>
  <scope>runtime</scope>
</dependency>

How I can configure publications block in order to get rid of this dependency from the pom.xml (and module) file?


Solution

  • I discovered that since my library had one runtime dependency I could use the following:

    components.java.withVariantsFromConfiguration(configurations.runtimeElements) {
        skip()
    }