androidkotlingradleandroid-gradle-plugingradle-plugin

Could not resolve com.android.tools.build:gradle:7.4.2 convention module


I'm trying to write gradle plugin in my android project. I have a build-logic module which contains convenion module. I wrote a small plugin JvmLibraryPlugin and registered it in the convention module build.gradle.kts file. I'm trying to specify a com.android.tools.build:gradle plugin dependency in the convention module in the build.gradle.kts file, but I'm having trouble keeping the project in sync. I get an error:

Execution failed for task ':build-logic:convention:compileKotlin'.
> Error while evaluating property 'filteredArgumentsMap' of task ':build-logic:convention:compileKotlin'
   > Could not resolve all files for configuration ':build-logic:convention:compileClasspath'.
      > Could not resolve com.android.tools.build:gradle:7.4.2.
        Required by:
            project :build-logic:convention
         > No matching variant of com.android.tools.build:gradle:7.4.2 was found. The consumer was configured to find an API of a library compatible with Java 8, preferably in the form of class files, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' but:
             - Variant 'apiElements' capability com.android.tools.build:gradle:7.4.2 declares an API of a library, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm':
                 - Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8
             - Variant 'javadocElements' capability com.android.tools.build:gradle:7.4.2 declares a runtime of a component, and its dependencies declared externally:
                 - Incompatible because this component declares documentation and the consumer needed a library
                 - Other compatible attributes:
                     - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
                     - Doesn't say anything about its target Java version (required compatibility with Java 8)
                     - Doesn't say anything about its elements (required them preferably in the form of class files)
                     - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'jvm')
             - Variant 'runtimeElements' capability com.android.tools.build:gradle:7.4.2 declares a runtime of a library, packaged as a jar, preferably optimized for standard JVMs, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm':
                 - Incompatible because this component declares a component compatible with Java 11 and the consumer needed a component compatible with Java 8
             - Variant 'sourcesElements' capability com.android.tools.build:gradle:7.4.2 declares a runtime of a component, and its dependencies declared externally:
                 - Incompatible because this component declares documentation and the consumer needed a library
                 - Other compatible attributes:
                     - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
                     - Doesn't say anything about its target Java version (required compatibility with Java 8)
                     - Doesn't say anything about its elements (required them preferably in the form of class files)
                     - Doesn't say anything about org.jetbrains.kotlin.platform.type (required 'jvm')

I tried changing the version from 7.4.2 to 8.x.x, but it didn't help. I'm getting a similar error. I tried changing the gradle JDK in the settings to versions 11, 15, 17, 19, but it didn't help.

Hierarchy of build-logic modules:

Hierarchy

build.gradle.kts(build-logic:convention):


plugins {
    `kotlin-dsl`
}

group = "***.android.scandroid_2.buildlogic"

java {
    sourceCompatibility = JavaVersion.VERSION_1_8
    targetCompatibility = JavaVersion.VERSION_1_8
}

tasks.withType<KotlinCompile>().configureEach {
    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8.toString()
    }
}

dependencies {
    compileOnly(libs.kotlin.gradle.plugin)
    compileOnly(libs.android.gradlePlugin)
}

gradlePlugin {
    plugins {
        register("jvmLibraryPlugin") {
            id = "JvmLibraryPlugin"
            implementationClass = "JvmLibraryPlugin"
        }
    }
}

settings.gradle.kts (build-logic):

    repositories {
        google()
        mavenCentral()
    }

    versionCatalogs {
        create("libs") {
            from(files("../gradle/libs.versions.toml"))
        }
    }
}

rootProject.name = "build-logic"
include(":convention")

JvmLibraryPlugin:

class JvmLibraryPlugin : Plugin<Project> {

    override fun apply(target: Project) = with(target) {
        applyPlugins()
    }

    private fun Project.applyPlugins() {
        with(pluginManager) {
            apply("org.jetbrains.kotlin.jvm")
        }
    }
}

build.gradle.kts (Project):

plugins {
    alias(libs.plugins.ksp) apply false
    alias(libs.plugins.android.application) apply false
    alias(libs.plugins.android.library) apply false
    alias(libs.plugins.kotlin.jvm) apply false
}

settings.gradle Project

pluginManagement {
    includeBuild("build-logic")
    repositories {
        google()
        mavenCentral()
        gradlePluginPortal()
    }
}
dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
    }
}

rootProject.name = "Scandroid_2"

include(":app")
include(":core-db-impl")
include(":core-domain")
include(":feature:settings-impl")
include(":feature:scanner-api")
include(":feature:scanner-impl")
include(":feature:code-list-api")
include(":feature:code-list-impl")
include(":feature:code-details-api")
include(":feature:code-details-impl")
include(":core-ui")
include(":core-resources")
include(":feature:settings-api")
include(":core-utils")
include(":core-executor")
include(":core-mvi")

gradle-wrapper.properties:

distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

What am I doing wrong? Tell me please.


Solution

  • I changed the android gradle plugin version to 8.4.2. In addition I did:

    JavaVersion.VERSION_1_8 -> JavaVersion.VERSION_17 jvmTarget = JavaVersion.VERSION_1_8.toString() -> JavaVersion.VERSION_17.toString()

    enter image description here

    Settings gradle JDK = 17

    enter image description here