War plugin not including certain compile dependencies in war

When using the war plugin certain “compile” dependencies are not included in the war’s WEB-INF/lib unless they’re a transient dependency of another library. This only seems to be an issue with certain specific libraries. This simple build.gradle should reproduce the issue by including it in an empty web app and running the war task:

apply plugin: 'java'
apply plugin: 'war'
   repositories {
  dependencies {
 compile 'javax.validation:validation-api:1.0.0.GA'
           providedCompile ('org.hibernate:hibernate-validator:4.3.0.Final') {
        transitive = true
   // validation-api.jar is NOT included in war
    transitive = false
  // validation-api.jar IS included in war

Everything on ‘providedCompile’ (including any transitive dependencies) is not included in the War, even if it’s also on ‘compile’. This explains what you are seeing.

Got it. Thanks.

Still having an issue with this…

If I set the compile dependency to not include transitives:

compile 'javax.validation:validation-api:1.0.0.GA'
  providedCompile 'org.hibernate:hibernate-validator:4.3.0.Final@jar'

everything works as expected. (i.e. validation-api.jar is included in war.)

However. If I have project dependencies in a multi-project build:

compile 'javax.validation:validation-api:1.0.0.GA'
  providedCompile project(':components:sharedLibrary') {
       transitive = false

I don’t get the expected behaviour. (i.e. validation-api.jar is NOT included in war.)

What I need is for validation-api.jar to be included in the war regardless of whether or not it’s a transitive dependency of some other library/project.

So apparently even if I set a providedCompile project dependency to “transitive = false”, if that sub project has a compile dependency for validation-api.jar it still causes it to be omitted from the war. So it seems like the transitive behavior is different if the dependency is a sub project vs. a jar.

I don’t think ‘transitive’ and similar properties are supported for project dependencies. Instead, you’d reconfigure what the other project exposes (e.g. via its ‘default’ configuration).

So then my next question is…if I have a set of jars that I want to make sure end up in the war no matter what, how would I accomplish that?

Tightly control what you add to ‘providedCompile’. (Note that I edited my previous comment and added some more information.)