# Compile Gradle Plugin Against Different API Version

**URL:** <https://discuss.gradle.org/t/compile-gradle-plugin-against-different-api-version/40281>\
**Category:** Help/Discuss\
**Created:** [June 21, 2021, 4:12pm UTC](https://discuss.gradle.org/t/compile-gradle-plugin-against-different-api-version/40281 "2021-06-21T16:12:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_R](https://avatars.discourse-cdn.com/v4/letter/m/8e8cbc/32.png) [@Mark\_R](https://discuss.gradle.org/u/Mark_R)\
**Post date:** [June 21, 2021, 4:12pm UTC](https://discuss.gradle.org/t/compile-gradle-plugin-against-different-api-version/40281/1 "2021-06-21T16:12:51Z")

</div>

Gradle plugins make use of the gradle API via a dependency declaration on a special “gradleApi” method. This restricts the version of the API to be the same as the version of gradle used to compile the plugin.

We have a use case where we need to continue to support older API versions (2.x for now but will be bumped up in the future) while using newer plugins that require newer versions of gradle (such as spring boot and xtext-gradle-plugin). Thus far we have been doing this by building with 2.13 and ensuring forwards compatibility through integration testing and keeping our plugins pinned to older versions. We want to upgrade our plugins and so need to bump up the version of Gradle we build with plugins with.

Is there a way to execute Gradle on one version but compile a plugin against a different API version? For example, could we create a BOM dependency that pulls in api dependencies in lieu of using gradleApi()? Does such a feature or module already exist?

```gradle
dependencies {
    implementation gradleApi()
}

```

Something like this would be handy:

```gradle
dependencies {
    implementation gradleApi("2.13")
}

```

---

<div class="post-metadata">

**Author:** ![Chris\_Dore](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/chris_dore/32/7592_2.png) [@Chris\_Dore](https://discuss.gradle.org/u/Chris_Dore)\
**Post date:** [June 22, 2021, 5:34am UTC](https://discuss.gradle.org/t/compile-gradle-plugin-against-different-api-version/40281/2 "2021-06-22T05:34:07Z")

</div>

Here’s a related issue you can watch

> <https://github.com/gradle/gradle/issues/1835>
>
> Dependencies on Gradle's API should not be limited to the current Gradle version… used by the build.
> 
> \### Expected Behavior
> 
> Provide options like:
> 
> \`\`\`groovy
> dependencies {
> compile 'org.gradle:gradle-api:3.0'
> }
> \`\`\`
> 
> Or if the JARs won't be published that way:
> 
> \`\`\`groovy
> dependencies {
> compile gradleApi('3.0')
> }
> \`\`\`
> 
> \### Current Behavior
> 
> \`\`\`groovy
> dependencies {
> compile gradleApi() // always uses the API of the Gradle version used to run the build
> }
> \`\`\`
> 
> \### Context
> 
> If I need to compile against Gradle 3.0 (since it's the minimum supported by a plugin) I shouldn't also be limited to building the plugin itself with Gradle 3.0. I can use TestKit to verify compatibility with older versions, but it would be nice to get compile errors if I was using an API that was too new.
> 
> Ultimately, I don't understand the case for \`gradleApi()\` being a special case dependency. Seems like it would be more straightforward to publish the Gradle API to a Maven repo like any other dependency in the Java community.

---

<div class="post-metadata">

**Author:** ![Daniel\_L](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/daniel_l/32/6420_2.png) [@Daniel\_L](https://discuss.gradle.org/u/Daniel_L)\
**Post date:** [June 28, 2021, 11:36am UTC](https://discuss.gradle.org/t/compile-gradle-plugin-against-different-api-version/40281/3 "2021-06-28T11:36:39Z")

</div>

This is the exact use case the plugins at [GitHub - gradle-plugins/toolbox: Painless and fast Gradle plugin development](https://github.com/gradle-plugins/toolbox) are solving. You don’t need to use the plugins to access the various Gradle APIs. You can resolve the dependencies at `dev.gradleplugins:gradle-api:<version>`. However, keep in mind that the core `java-gradle-plugin` plugin adds a self resolved dependencies which would need to be removed. The toolbox plugins take cares of that and much more.
