Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Flutter and app store releases

ext {} and ext properties fail in build.gradle.kts

Errorext in buildscript cannot be recognised by Gradle Kotlin DSL

Short answer

ext is the Groovy way to hold extra properties. In build.gradle.kts the same data lives behind the extra accessor, a map you read and write with extra["name"]. Subprojects reach the root's values through rootProject.extra. For shared versions, a version catalog replaces ext altogether.

  • Applies to Gradle 8.x and 9.x, Kotlin DSL, Android Gradle Plugin 8.x
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check whether the failing file is a .kts script. If it is, any ext { } block or bare ext variable is Groovy syntax and must be rewritten.

    grep -rn "ext" --include=*.gradle.kts .
  2. 2Match what you see, then jump to its fix

    1. 1ext { kotlin_version = '1.9.0' } or ext.kotlin_version is red in build.gradle.ktsGroovy ext syntax copied into a .kts fileFix
    2. 2The root script works, but app/build.gradle.kts cannot find the propertyA subproject reads the root project's value without rootProjectFix
    3. 3You use ext only to share library or plugin versions between filesShared versions are better kept in a version catalogFix

What does the error look like?

  • ext in buildscript cannot be recognised by Gradle Kotlin DSL
  • The ext { } block is marked as an error in build.gradle.kts

Cause 1 of 3

Groovy ext syntax copied into a .kts file

1Check

Extra properties in the Kotlin DSL come from the extra accessor, a map. The Groovy ext block has no counterpart.

grep -rn "ext\b" --include=*.gradle.kts .

2Fix

Set the value with extra and read it with a cast.

// root build.gradle.kts
extra["myVersion"] = "1.0.0"

val myVersion = extra["myVersion"] as String

3Verify

Sync or run any task and confirm the script compiles.

./gradlew help

Confirmed by docs.gradle.org

Did this fix it?

Cause 2 of 3

A subproject reads the root project's value without rootProject

1Check

extra belongs to the project whose script uses it. A subproject must ask the root project for it.

grep -rn "extra\[" --include=*.gradle.kts .

2Fix

Read the value through rootProject.extra in the subproject script.

// app/build.gradle.kts
val myVersion = rootProject.extra["myVersion"] as String

3Verify

Run a task on the subproject.

./gradlew :app:help

Confirmed by docs.gradle.org

Did this fix it?

Cause 3 of 3

Shared versions are better kept in a version catalog

1Check

A catalog file gradle/libs.versions.toml is imported automatically as libs, so no ext is needed.

ls gradle/libs.versions.toml

2Fix

Declare the version once in the catalog and read it in Kotlin DSL scripts.

# gradle/libs.versions.toml
[versions]
groovy = "3.0.5"

// build.gradle.kts
val groovyVersion = libs.versions.groovy.get()

3Verify

Build with the catalog entry in place.

./gradlew help

Confirmed by docs.gradle.org

Did this fix it?

How do I stop it coming back?

  • Prefer a version catalog over extra properties for dependency versions.
  • When converting a Groovy script, rewrite ext blocks and single quotes in the same pass.
  • Keep the values in one root file and read them elsewhere through rootProject.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.