Compile Dependency but do not want to package inside jar


(pranav.singh) #1

I am a xyz.jar defined as a compile time dependencies.

dependencies { … compile xyz.jar … }

This jar is must for my code to compile. But there is some other gradle target which includes this project, and in turn, this big fat xyz.jar gets packaged inside the top level jar.

How can I just use this jar for compilation, and not letting it get bundled inside top level jar?

I tried many options like replacing compile with providedCompile, compileReadOnly, compile … {transitive = false} etc… but none of them seems to work. If I make it testRuntime, it won’t package, but it will not help in compiling my code either.

Please advise.


(Carlo Luib-Finetti) #2

You should define a special configuration and put this into the dependencies. Something like this should do the job.

configurations {
   specialDep
}
dependencies {
  compile (...)
  specialDep your.jar
}
  jar {
  from configurations.compile - configurations.specialDep
}