Maven-publish: Excluding transitive dependencies from a subproject in a multi-project build

Using Gradle 2.8 I have the following subproject dependency defined:

compile(project(":grails-datastore-gorm-hibernate-core")) {
    exclude group:'org.hibernate', module:'hibernate-core'
    exclude group:'org.hibernate', module:'hibernate-validator'
    exclude group:'org.hibernate', module:'hibernate-ehcache'
    exclude group:'org.hibernate', module:'hibernate-commons-annotations'
}

When the POM is generated I get

<dependency>
  <groupId>org.grails</groupId>
  <artifactId>grails-datastore-gorm-hibernate-core</artifactId>
  <version>5.0.0.BUILD-SNAPSHOT</version>
  <scope>runtime</scope>
</dependency>

As you can see the exclusions are not taken into account. Is this by design? Is the only way to fix this manual POM/XML fudging?

Ping. I’m being hit by this again, how does this get escalated into an actual JIRA issue?

For clarification, this apparently only happens with project dependencies.

Perhaps you could add the hibernate libraries as exclusions on the configuration? Alternatively you could modify the POM that’s generated to add the exclusions, as described in the comments here.

One final thing: why the exclusions? The answer to that will help identify the most appropriate solution. That’s not the say this isn’t a bug that needs fixing.

Yes only with project dependencies. Of course there are many ugly ways I can hack around this, but this should “just work” IMO.

In terms of why the exclusions. We have 4 different Hibernate projects. The grails-datastore-gorm-hibernate-core project depends on Hibernate 3 and provides all classes that are binary compatible with Hibernate 3, 4 and 5.

We then have several projects (grails-datastore-gorm-hibernate4, grails-datastore-gorm-hibernate5 etc.) for each version of Hibernate that depends on grails-datastore-gorm-hibernate-core but must exclude the Hibernate 3 JARs from being pulled in since they use newer versions of the hibernate-core dependency.

Of course I could hack around this and make the dependencies in grails-datastore-gorm-hibernate-core provided or something, but that shouldn’t be necessary.

I think an exclusion on the configuration is the most appropriate solution then because you don’t want anything to pull in the Hibernate 3 libraries. That may or may not produce the POM you want, though, particularly as POMs have no concept of global excludes. Perhaps the bug affects such configuration excludes too.

BTW, this is an orthogonal discussion to the bug. It does look like that should be added to the issue tracker.

@Graeme_Rocher1, I’ve opened GRADLE-3366 to track this. I’m looking into getting this fixed in Gradle 2.10 however we are planning for this release as we speak so it may not make the cut.

This fix is in 2.10. We are aiming for an RC next week or you could try the latest 2.10 snapshot.

1 Like