Exclude a transitive dependency

This borders on a “frequently asked question” and I think I’ve read all of the recent posts about it. I am still floundering, so I’m going to see if someone will point me to the answer…

I created a simple little demo project with this build.gradle.kts:

plugins {
  id("java")
}

repositories {
    mavenLocal()
    mavenCentral()
}

val demopath by configurations.creating {
    extendsFrom(configurations["implementation"])
}

configurations.configureEach {
  exclude("net.sf.saxon:Saxon-HE")
  exclude("com.saxonica:Saxon-EE")
}

dependencies {
  implementation("org.nineml:coffeegrinder:3.2.6")
  implementation("org.nineml:coffeefilter:3.2.6")
}

tasks.register("helloWorld") {
  doLast {
    demopath.forEach { file -> 
      println(file)
    }
  }
}

If you run the helloWorld task, it will tell you that Saxon-HE:9.6.0.4 is in the demopath. This is a transitive dependency of CoffeeFilter.

I don’t want that on the classpath. Based on some posts I’ve read, I expected this to exclude it:

  implementation("org.nineml:coffeegrinder:3.2.6") {
    exclude("net.sf.saxon:Saxon-HE")
    exclude("com.saxonica:Saxon-EE")
  } 
  implementation("org.nineml:coffeefilter:3.2.6") {
    exclude("net.sf.saxon:Saxon-HE")
    exclude("com.saxonica:Saxon-EE")
  }

But it didn’t. Based on other posts, I expected this to exclude it:

configurations.configureEach {
  exclude("net.sf.saxon:Saxon-HE")
  exclude("com.saxonica:Saxon-EE")
}

It also did not.

I am, in fact, working on the build script for Saxon-HE. I don’t want Saxon-HE included by any transitive dependency from any dependency, transitive or otherwise!

I assume I’m overlooking something obvious, but, uh, I’m overlooking it :slight_smile:

Help?

I assume I’m overlooking something obvious, but, uh, I’m overlooking it :slight_smile:

Indeed :smiley:
image

Okay. That’s embarrassing. Thank you. I’m going to mutter under my breath a little bit about how it’d be nice if dependencies and exclusions has a more consistent syntax, but maybe that’s just me. Thanks again.

The main problem is, that for an exclude you can also exclude all in a given group.
So you cannot disambiguate between exclude("group") and exclude("group", "version") without different method names.
Actually, you can use consistent syntax by not using "group:version" for declaring dependencies. :slight_smile:
For example use a version catalog.