AndroidEngineX
AndroidEngineX

Reputation: 1481

In Gradle version catalog file libs.version.toml plugins name is not recognised

I am using the version catalog to effectively share the dependency across different Gradle modules in the Android project.

I am using below libs.versions.toml file

[versions]
room = "2.4.0"
gradlePlugins-agp = "7.0.4"

# Gradle plugins
gradlePlugins-hilt = "2.40.5"

[libraries]
androidx-room-common = { module = "androidx.room:room-common", version.ref = "room" }
androidx-room-compiler = { module = "androidx.room:room-compiler", version.ref = "room" }
androidx-room-ktx = { module = "androidx.room:room-ktx", version.ref = "room" }

hilt-android = { module = "com.google.dagger:hilt-android", version.ref = "gradlePlugins-hilt" }
hilt-kapt = { module = "com.google.dagger:hilt-compiler", version.ref = "gradlePlugins-hilt" }
hilt-plugin = { module = "com.google.dagger:hilt-android-gradle-plugin", version.ref = "gradlePlugins-hilt" }

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

For the above libs.versions.toml file while building the app Gradle build fails with the following error

org.gradle.api.InvalidUserDataException: Invalid TOML catalog definition:
  - Problem: In version catalog libs, unknown top level elements [plugins].

* Exception is:
java.lang.RuntimeException: org.gradle.api.InvalidUserDataException: Invalid TOML catalog definition:
  - Problem: In version catalog libs, unknown top level elements [plugins].
    
    Reason: TOML file contains an unexpected top-level element.
    
    Possible solution: Make sure the top-level elements of your TOML file is one of 'bundles', 'libraries', 'metadata' or 'versions'.
    
    Please refer to https://docs.gradle.org/7.0.2/userguide/version_catalog_problems.html#toml_syntax_error for more details about this problem.

While the documentation clearly states the plugins are supported top-level name in the toml file

Upvotes: 10

Views: 27937

Answers (1)

AndroidEngineX
AndroidEngineX

Reputation: 1481

After a bit of digging and exploring some open source projects, I found the solution for the above issue. Initially, I was using the distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip as my Gradle version in gradle-wrapper.properties but to fix the issue I updated the Gradle version to 7.3.2

So changing the distribution URL to distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.2-all.zip fixed the issue for me

Upvotes: 7

Related Questions