How do I define a compile-time *only* classpath in Gradle?

There has been a lot of discussion regarding this topic, mainly here, but not clear conclusion.

You are on the right track: currently the best solution is to declare your own provided configuration, that will included compile-only dependencies and add to to your compile classpath:

configurations{
  provided
}

dependencies{
  //Add libraries like lombok, findbugs etc
  provided '...'
}

//Include provided for compilation
sourceSets.main.compileClasspath += [configurations.provided]

// optional: if using 'idea' plugin
idea {
  module{
    scopes.PROVIDED.plus += [configurations.provided]
  }
}

// optional: if using 'eclipse' plugin
eclipse {
  classpath {
    plusConfigurations += [configurations.provided]
  }
}

Typically this works well.

Leave a Comment