# Provided VS CompileOnly

**URL:** https://discuss.gradle.org/t/provided-vs-compileonly/28568
**Category:** Help/Discuss
**Tags:** buildship
**Created:** [September 11, 2018, 8:46am UTC](https://discuss.gradle.org/t/provided-vs-compileonly/28568 "2018-09-11T08:46:16Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![hsowan](https://avatars.discourse-cdn.com/v4/letter/h/71e660/32.png) [@hsowan](https://discuss.gradle.org/u/hsowan)
#### Post date: [September 11, 2018, 8:46am UTC](https://discuss.gradle.org/t/provided-vs-compileonly/28568/1 "2018-09-11T08:46:16Z")

</div>

When I use provided like this:  
provided group: ‘javax.servlet’, name: ‘javax.servlet-api’, version: ‘3.1.0’  
the result was:  
BUILD FAILED in 0s  
Could not find method provided() for arguments [{group=javax.servlet, name=javax.servlet-api, version=3.1.0}] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.  
But use compileOnly is ok, why?

---

<div class="post-metadata">

### Author: ![Pierre1](https://avatars.discourse-cdn.com/v4/letter/p/a8b319/32.png) [@Pierre1](https://discuss.gradle.org/u/Pierre1)
#### Post date: [September 17, 2018, 10:11am UTC](https://discuss.gradle.org/t/provided-vs-compileonly/28568/2 "2018-09-17T10:11:00Z")

</div>

Hi,

`provided` is not a valid configuration name when using `java` or `war` plugin. See the plugin documentation page to have an overview of the configurations that are available to your project and their effect: [configurations from java plugin](https://docs.gradle.org/current/userguide/java_plugin.html#sec:java_plugin_and_dependency_management) and [configurations from war plugin](https://docs.gradle.org/current/userguide/war_plugin.html#sec:war_dependency_management)

To obtain the equivalent of the _Maven provided scope_, you can then either:

1. define your dependency in configurations `compileOnly` and `testImplementation` (requires Gradle 3.5+ and java plugin)
2. define your dependency in `providedCompile` (requires war plugin)
3. apply the [nebula.provided-base plugin](https://github.com/nebula-plugins/gradle-extra-configurations-plugin) **only if using Gradle 3.4 or lower** , and use the `provided` configuration.
