Maaz Zindani

Loading the index…

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

Gradle sync stops with MultipleCompilationErrorsException: startup failed in a .gradle file

Your error

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:4 more lines it can show

Fix it fast

Most common cause, 1 of 3

Code sits above the plugins {} block

Move plugins {} to the top of the file, right after any buildscript {} block, and keep the other statements below it.

Fix
// fails
def appVersion = '1.4.0'
plugins {
    id 'com.android.application'
}

// compiles
plugins {
    id 'com.android.application'
}
def appVersion = '1.4.0'
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed means Gradle could not compile a Groovy build or settings script. The line after it names the broken rule: code placed above plugins {}, a variable or expression inside plugins {}, or pluginManagement {} that is not the first block of settings.gradle. On Gradle 8 and 9, move the block or use literal versions.

  • Applies to Gradle 8.14, Gradle 9.9, Android Gradle Plugin 9.5
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Run any task from a terminal in the project root. Gradle prints the script path, the line number and the rule that failed right after startup failed, which is easier to read there than in the sync dialog.

Run this first
./gradlew help

Then find the line you see in this list and open its fix:

  1. 1Code sits above the plugins {} blockonly buildscript {}, pluginManagement {} and other plugins {} script blocks are allowed before plugins {} blocks, no other statements are allowed
  2. 2plugins {} holds a variable or an expressionargument list must be exactly 1 literal String or String with property replacement, or only id(String), alias(Provider), or alias(ProviderConvertible) method calls allowed in plugins {} script block
  3. 3pluginManagement {} is not first in settings.gradle, or is in a build fileThe pluginManagement {} block must appear before any other statements in the script, or Only Settings scripts can contain a pluginManagement {} block

What does the error look like?

  • org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
  • only buildscript {}, pluginManagement {} and other plugins {} script blocks are allowed before plugins {} blocks, no other statements are allowed
  • argument list must be exactly 1 literal String or String with property replacement
  • The pluginManagement {} block must appear before any other statements in the script.
  • Only Settings scripts can contain a pluginManagement {} block.

Cause 1 of 3

Code sits above the plugins {} block

You seeonly buildscript {}, pluginManagement {} and other plugins {} script blocks are allowed before plugins {} blocks, no other statements are allowed

Check

startup failed with this line means the build script runs something before plugins {}: an apply plugin line, a def, an ext {} block or a println. Gradle requires plugins {} to come before any other block, with only buildscript {} and other plugins {} blocks allowed above it.

Check
head -n 15 app/build.gradle

Fix

Move plugins {} to the top of the file, right after any buildscript {} block, and keep the other statements below it.

Fix
// fails
def appVersion = '1.4.0'
plugins {
    id 'com.android.application'
}

// compiles
plugins {
    id 'com.android.application'
}
def appVersion = '1.4.0'

Verify

The same task now gets past configuration and prints BUILD SUCCESSFUL.

Verify
./gradlew help

Confirmed by docs.gradle.org

Did this fix it?

Cause 2 of 3

plugins {} holds a variable or an expression

You seeargument list must be exactly 1 literal String or String with property replacement, or only id(String), alias(Provider), or alias(ProviderConvertible) method calls allowed in plugins {} script block

Check

startup failed with one of these lines means plugins {} contains something other than constant ids and versions. Gradle reads that block before the rest of the script runs, so a version taken from ext, a method call, string concatenation or an if statement is rejected while the script compiles.

Check
grep -n -A8 "^plugins" build.gradle app/build.gradle

Fix

Write ids and versions as plain strings, or keep versions in gradle/libs.versions.toml and apply each plugin with alias(). Dashes in a catalog alias turn into dots in the accessor.

Fix
# gradle/libs.versions.toml
[versions]
agp = "9.5.2"

[plugins]
android-application = { id = "com.android.application", version.ref = "agp" }

// build.gradle in the root project
plugins {
    alias(libs.plugins.android.application) apply false
}

Verify

Sync again in Android Studio; the plugin resolves and the startup failed dialog is gone.

Verify
./gradlew help

Confirmed by github.com

Did this fix it?

Cause 3 of 3

pluginManagement {} is not first in settings.gradle, or is in a build file

You seeThe pluginManagement {} block must appear before any other statements in the script, or Only Settings scripts can contain a pluginManagement {} block

Check

startup failed with these lines points at pluginManagement {}. Gradle accepts that block only in settings.gradle(.kts) and only as its first block, so a rootProject.name line above it, or a copy pasted into build.gradle, stops compilation.

Check
head -n 5 settings.gradle
grep -n "pluginManagement" build.gradle app/build.gradle

Fix

Keep a single pluginManagement {} at the very top of settings.gradle and delete any copy from the build files.

Fix
// settings.gradle
pluginManagement {
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}
rootProject.name = 'my-app'
include ':app'

Verify

Gradle compiles the settings script and lists the projects.

Verify
./gradlew projects

Confirmed by github.com

Did this fix it?

How do I stop it coming back?

  • Keep plugin ids and versions only in gradle/libs.versions.toml and apply them with alias(), so no build file needs a version variable.
  • Run ./gradlew help in CI for every change to a .gradle file, so a script that no longer compiles fails the pull request.
  • When you copy a snippet from a library README, check which block and which file it belongs in before you paste it.

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 on the same stack: QistLock, Nuclear Home Video.

Next step

Want this handled for good?

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