I am attempting to compile several WAR files, all that depend on a common JAR module. In my Gradle build however, I cannot seem to get a ‘Provided’ like dependency to work with the Java plugin.
My compile looks like this:
apply plugin: 'java'
configurations{
providedCompile
}
dependencies {
compile module("org.springframework.amqp:spring-amqp:${springAmqpVersion}")
compile module("org.slf4j:slf4j-api:${slf4jVersion}")
compile module("org.slf4j:slf4j-ext:${slf4jVersion}")
providedCompile "javax.servlet:servlet-api:${servletApiVersion}"
runtime module("org.slf4j:jcl-over-slf4j:${slf4jVersion}")
runtime module("org.slf4j:jul-to-slf4j:${slf4jVersion}")
runtime module("org.slf4j:log4j-over-slf4j:${slf4jVersion}")
sourceArchives module("org.springframework.amqp:spring-amqp:${springAmqpVersion}:sources")
sourceArchives module("javax.servlet:servlet-api:${servletApiVersion}:sources")
}
sourceSets {
main { compileClasspath += configurations.providedCompile }
}
However, that last bit is where it gets an exception. I have tried adding the servlet-api (Provided by Tomcat) to the configuration after the runtime dependencies would extend it, or simply putting it in as a compile module, then removing it from runtime dependencies later.
I’ve attempted several different ways of modifying the dependencies, with my closest results being:
newRuntime = configurations.runtime.minus(configurations.providedCompile)
configurations.runtime = newRuntime
This last bit however, will generate the variable newRuntime with the proper dependencies, however when I tried to reassign the variable back to the runtime configuration, it throws a “Cannot find property exception”
I found a lot of discussion of this exact problem on Gradle’s bug tracking:Gradle-784
However the main lead from that is from Spring who uses Maven with their gradle builds, which I am unfamiliar with.
The most promising link I found here on SO, but unfortunately I could not get the examples to work as well: SO Provided Question
Of note for the Stack Overflow question the line that showed most promise:
//Include provided for compilation
sourceSets.main.compileClasspath += configurations.provided
This line does not give an error like other attempts, however it appears that the providedCompile (My version of provided) dependency is not actually put on the compile classpath, as there is a classpath error when compilation is attempted.
I’m not 100% following your message but providedCompile is only allowed for ‘war’ plugin.
During ‘war’ step the servlet jar is not included.