未找到 XXX 的匹配变体。消费者被配置为查找具有值“platform”和“version-catalog”的属性

Ely*_*lye 6 gradle

导出versionCatalogs为库并被其他应用程序使用后,错误状态

   > No matching variant of io.github.elye:plugin-dependencies:1.0.0 was found. The consumer was configured to find attribute 'org.gradle.category' with value 'platform', attribute 'org.gradle.usage' with value 'version-catalog' but:
       - Variant 'apiElements' capability io.github.elye:plugin-dependencies:1.0.0:
           - Incompatible because this component declares attribute 'org.gradle.category' with value 'library', attribute 'org.gradle.usage' with value 'java-api' and the consumer needed attribute 'org.gradle.category' with value 'platform', attribute 'org.gradle.usage' with value 'version-catalog'
       - Variant 'runtimeElements' capability io.github.elye:plugin-dependencies:1.0.0:
           - Incompatible because this component declares attribute 'org.gradle.category' with value 'library', attribute 'org.gradle.usage' with value 'java-runtime' and the consumer needed attribute 'org.gradle.category' with value 'platform', attribute 'org.gradle.usage' with value 'version-catalog'
Run Code Online (Sandbox Code Playgroud)

我的 versionCatalogs 库编写如下

plugins {
    id 'java-library'
    id 'kotlin'
    id 'version-catalog'
}

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

catalog {
    // declare the aliases, bundles and versions in this block
    versionCatalog {
        alias('androidx-core').to('androidx.core:core-ktx:1.6.0')
        alias('androidx-appcompat').to('androidx.appcompat:appcompat:1.3.1')
        alias('androidx-constraintlayout').to('androidx.constraintlayout:constraintlayout:2.1.0')
        alias('android-material').to('com.google.android.material:material:1.4.0')
        bundle('androidx', ['androidx-core',
                            'androidx-appcompat',
                            'androidx-constraintlayout'])
    }
}

ext {
    PUBLISH_GROUP_ID = 'io.github.elye'
    PUBLISH_VERSION = '1.0.0'
    PUBLISH_ARTIFACT_ID = 'plugin-dependencies'
}

apply from: "./publish-module.gradle"
Run Code Online (Sandbox Code Playgroud)

当我尝试访问 versionCatalog 库时,如下所示

dependencyResolutionManagement {

    // Some other codes

    versionCatalogs {
        xlibs {
            from("io.github.elye:plugin-dependencies:1.0.0")
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我该如何修复该错误?

Ely*_*lye 2

看起来我只需要从库build.gradle文件中删除以下内容。

plugins {
    id 'java-library'
    id 'kotlin'
}
Run Code Online (Sandbox Code Playgroud)

因此代码如下所示

plugins {
    id 'version-catalog'
}

catalog {
    // declare the aliases, bundles and versions in this block
    versionCatalog {
        alias('androidx-core').to('androidx.core:core-ktx:1.6.0')
        alias('androidx-appcompat').to('androidx.appcompat:appcompat:1.3.1')
        alias('androidx-constraintlayout').to('androidx.constraintlayout:constraintlayout:2.1.0')
        alias('android-material').to('com.google.android.material:material:1.4.0')
        bundle('androidx', ['androidx-core',
                            'androidx-appcompat',
                            'androidx-constraintlayout'])
    }
}

ext {
    PUBLISH_GROUP_ID = 'io.github.elye'
    PUBLISH_VERSION = '1.0.0'
    PUBLISH_ARTIFACT_ID = 'plugin-dependencies'
}

apply from: "./publish-module.gradle"
Run Code Online (Sandbox Code Playgroud)