Maven’s “provided” dependencies are available for compilation and for test execution, but won’t be put on the runtime classpath and won’t be packaged. But unlike Maven, Gradle doesn’t support a “provided” dependency scope out-of-the-box.
Defining a “provided” scope in Gradle is pretty straight-forward, but it is not exactly a one-liner: You have to define a new configuration and add it to the various classpathes.
configurations {
provided
}
sourceSets {
main {
compileClasspath += configurations.provided
}
test {
compileClasspath += configurations.provided
runtimeClasspath += configurations.provided
}
}
dependencies {
provided "javax:j2ee:1.3.1" // example
}
If you are using Gradle’s Eclipse or IDEA support, you must also add the configuration to the classpath of these modules:
eclipse {
classpath {
plusConfigurations += [configurations.provided]
noExportConfigurations += [configurations.provided]
}
}
idea {
module {
scopes.PROVIDED.plus += [configurations.provided]
}
}