无法解析 com.android.tools.build:gradle:7.4.2 约定模块

问题描述 投票:0回答:1

我正在尝试在我的 android 项目中编写 gradle 插件。我有一个包含约定模块的构建逻辑模块。我编写了一个小插件 JvmLibraryPlugin 并将其注册到约定模块 build.gradle.kts 文件中。我试图在 build.gradle.kts 文件的约定模块中指定 com.android.tools.build:gradle 插件依赖项,但我无法保持项目同步。我收到错误:

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')

我尝试将版本从 7.4.2 更改为 8.x.x,但没有帮助。我遇到类似的错误。 我尝试将设置中的gradle JDK更改为版本11、15、17、19,但没有帮助。

构建逻辑模块的层次结构:

Hierarchy

build.gradle.kts(构建逻辑:约定):


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(构建逻辑):

    repositories {
        google()
        mavenCentral()
    }

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

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

JvmLibrary插件:

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(项目):

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 项目

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

我做错了什么?请告诉我。

android kotlin gradle android-gradle-plugin gradle-plugin
1个回答
0
投票

我将android gradle插件版本更改为8.4.2。 另外我还做了:

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

enter image description here

设置 gradle JDK = 17

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.