Search code examples
javagradlegrailsehcachetransitive-dependency

excluding module/transitive dependencies from Gradle Build


I am currently attempting to build a gradle grails 3 project, where it is using Spring-context-support as a transitive dependency under some Spring dependency at compile time as declared in my build file. My application does depend on the group and artifact/module as a whole(That is, Spring-context-support), however, I need to explicitly get rid of/exclude EhCache from within spring-context-support. I know syntactically how rid myself of the entire spring-context-support dependency, however I cannot seem to figure out how to remove JUST the caching...

A screen shot is attached to help illustrate what i mean: this line when uncommented will remove the entire spring-context-support dependency: enter image description here

Here you see the "cache" package, containing the Ehcache modules that I am trying to get rid of. How would I adjust the exclude declaration to remove this? enter image description here


Solution

  • Gradle (or Maven) will only allow you to exclude a dependency at the artifact level, that is not have the jar on the classpath. There is no first class support for filtering out a set of packages from a dependency.

    For that, the easiest would be to repackage your application in a fat jar, filtering out the packages you deem unnecessary.

    However the way your question is phrased makes me wonder if there is not a confusion. What you will find inside org.springframework.cache is not Ehcache code but instead the Spring caching abstraction. Ehcache library is either a module under group net.sf.ehcache or org.ehcache, and you could very well exclude these.