title: Gradle 'Provided' dependency for Java plugin
body: <p>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.</p>
  
  <p>My compile looks like this:</p>
  
  <pre><code>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 }
  }
  </code></pre>
  
  <p>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.</p>
  
  <p>I've attempted several different ways of modifying the dependencies, with my closest results being:</p>
  
  <pre><code>newRuntime = configurations.runtime.minus(configurations.providedCompile)
  configurations.runtime = newRuntime
  </code></pre>
  
  <p>This last bit however, will generate the variable <em>newRuntime</em> with the proper dependencies, however when I tried to reassign the variable back to the runtime configuration, it throws a "Cannot find property exception"</p>
  
  <p>I found a lot of discussion of this exact problem on Gradle's bug tracking:<a href="http://issues.gradle.org/browse/GRADLE-784" rel="nofollow noreferrer">Gradle-784</a></p>
  
  <p>However the main lead from that is from Spring who uses Maven with their gradle builds, which I am unfamiliar with.</p>
  
  <p>The most promising link I found here on SO, but unfortunately I could not get the examples to work as well: <a href="https://stackoverflow.com/questions/10405970/how-do-i-define-a-compile-time-only-classpath-in-gradle">SO Provided Question</a>
  Of note for the Stack Overflow question the line that showed most promise:</p>
  
  <pre><code>//Include provided for compilation
  sourceSets.main.compileClasspath += configurations.provided
  </code></pre>
  
  <p>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.</p>