user1644873
user1644873

Reputation: 1231

Why is Gradle not including my dependencies when I specifically state them?

We are retrofitting an existing web app to include SOAP services using JBoss 6 EAP and CXF. My problem is that, even though I explicitly state I want certain dependencies included in my .war file (using "compile {dependency}"), they are not included. It appears to be related to other libraries.

Trying to be a good do-bee, I listed all the cxf dependencies as 'providedCompile' since JBoss EAP already includes them in the modules directory:

providedCompile "org.apache.cxf:cxf-rt-transports-http:2.6.8"
providedCompile "org.apache.cxf:cxf-api:2.6.8"
providedCompile "org.apache.cxf:cxf-rt-bindings-soap:2.6.8"
providedCompile "org.apache.cxf:cxf-rt-bindings-xml:2.6.8"
providedCompile "org.apache.cxf:cxf-rt-core:2.6.8"
providedCompile "org.apache.cxf:cxf-rt-databinding-jaxb:2.6.8"
providedCompile "org.apache.cxf:cxf-rt-frontend-jaxws:2.6.8"
providedCompile "org.apache.cxf:cxf-rt-frontend-simple:2.6.8"
providedCompile "org.apache.cxf:cxf-tools-common:2.6.8"
providedCompile "org.apache.cxf:cxf-tools-validator:2.6.8"
providedCompile "org.apache.cxf:cxf-tools-wsdlto-core:2.6.8"
providedCompile "org.apache.cxf:cxf-tools-wsdlto-databinding-jaxb:2.6.8"

For example, I need dom4j. I know I need it because I see the ClassNotFoundExceptions at startup.

So I add this to my dependencies:

compile "dom4j:dom4j:1.6.1"

No joy. That is, until I change all the above 'providedCompile' statements to 'compile'.

I am still working on producing a simplified example for posting here, but has anyone else see odd behavior like this? Why would one 'providedCompile' dependency block another 'compile' dependency from being included in a .war file? Why must I duplicate libraries in my .war that are already provided by the container?

Upvotes: 0

Views: 936

Answers (1)

Peter Niederwieser
Peter Niederwieser

Reputation: 123890

Gradle assumes that all dependencies of the providedCompile configuration (which includes direct and transitive dependencies) are available in the target environment, and hence doesn't include them in the War. dom4j is likely a transitive providedCompile dependency. If you want to express that only direct providedCompile dependencies are available in the target environment (i.e. the ones explicitly listed in the build script), you can set configurations.providedCompile.transitive = false, or selectively use the @jar notation (e.g. providedCompile "org.apache.cxf:cxf-rt-bindings-xml@jar:2.6.8").

To check which providedCompile dependency(s) drag in dom4j, run gradle dependencyInsight --configuration providedCompile --dependency dom4j.

Upvotes: 1

Related Questions