首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >不能使用Kotlin 1.7.10

不能使用Kotlin 1.7.10
EN

Stack Overflow用户
提问于 2022-08-13 07:58:41
回答 6查看 8.1K关注 0票数 6

我在IntelliJ IDEA中有一个Kotlin项目(不是针对安卓系统),现在可以用Kotlin1.6.10编译。当我更改为1.7.10时,会得到以下错误:

代码语言:javascript
运行
复制
FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'jwotd'.
> Could not resolve all artifacts for configuration ':classpath'.
   > Could not resolve org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0.
     Required by:
         project :
      > The consumer was configured to find a runtime of a component compatible with Java 8, packaged as a jar, and its dependencies declared externally. However we cannot choose between the following variants of org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0:
          - gradle70JavadocElements
          - gradle70RuntimeElements
          - gradle70SourcesElements
          - javadocElements
          - runtimeElements
          - sourcesElements
        All of them match the consumer attributes:
          - Variant 'gradle70JavadocElements' capability org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0 declares a runtime of a component, and its dependencies declared externally:
              - Unmatched attributes:
                  - Provides documentation but the consumer didn't ask for it
                  - Provides javadocs but the consumer didn't ask for it
                  - Doesn't say anything about its target Java version (required compatibility with Java 8)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Provides attribute 'org.gradle.plugin.api-version' with value '7.0' but the consumer didn't ask for it
                  - Provides release status but the consumer didn't ask for it
          - Variant 'gradle70RuntimeElements' capability org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0 declares a runtime of a component compatible with Java 8, packaged as a jar, and its dependencies declared externally:
              - Unmatched attributes:
                  - Provides a library but the consumer didn't ask for it
                  - Provides attribute 'org.gradle.jvm.environment' with value 'standard-jvm' but the consumer didn't ask for it
                  - Provides attribute 'org.gradle.plugin.api-version' with value '7.0' but the consumer didn't ask for it
                  - Provides release status but the consumer didn't ask for it
                  - Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' but the consumer didn't ask for it
          - Variant 'gradle70SourcesElements' capability org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0 declares a runtime of a component, and its dependencies declared externally:
              - Unmatched attributes:
                  - Provides documentation but the consumer didn't ask for it
                  - Provides sources but the consumer didn't ask for it
                  - Doesn't say anything about its target Java version (required compatibility with Java 8)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Provides attribute 'org.gradle.plugin.api-version' with value '7.0' but the consumer didn't ask for it
                  - Provides release status but the consumer didn't ask for it
          - Variant 'javadocElements' capability org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0 declares a runtime of a component, and its dependencies declared externally:
              - Unmatched attributes:
                  - Provides documentation but the consumer didn't ask for it
                  - Provides javadocs but the consumer didn't ask for it
                  - Doesn't say anything about its target Java version (required compatibility with Java 8)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Provides release status but the consumer didn't ask for it
          - Variant 'runtimeElements' capability org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0 declares a runtime of a component compatible with Java 8, packaged as a jar, and its dependencies declared externally:
              - Unmatched attributes:
                  - Provides a library but the consumer didn't ask for it
                  - Provides attribute 'org.gradle.jvm.environment' with value 'standard-jvm' but the consumer didn't ask for it
                  - Provides release status but the consumer didn't ask for it
                  - Provides attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' but the consumer didn't ask for it
          - Variant 'sourcesElements' capability org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0 declares a runtime of a component, and its dependencies declared externally:
              - Unmatched attributes:
                  - Provides documentation but the consumer didn't ask for it
                  - Provides sources but the consumer didn't ask for it
                  - Doesn't say anything about its target Java version (required compatibility with Java 8)
                  - Doesn't say anything about its elements (required them packaged as a jar)
                  - Provides release status but the consumer didn't ask for it
        The following variants were also considered but didn't match the requested attributes:
          - Variant 'apiElements' capability org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0 declares a component compatible with Java 8, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares an API of a component and the consumer needed a runtime of a component
          - Variant 'gradle70ApiElements' capability org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0 declares a component compatible with Java 8, packaged as a jar, and its dependencies declared externally:
              - Incompatible because this component declares an API of a component and the consumer needed a runtime of a component

我的顶级build.gradle:

代码语言:javascript
运行
复制
buildscript {
    ext.kotlin_version = '1.7.10'
    repositories {
        jcenter()
        mavenCentral()
    }
    dependencies {
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

allprojects {
    repositories {
        jcenter()
        mavenCentral()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

我的一个项目build.gradle (有几个项目,都类似):

代码语言:javascript
运行
复制
apply plugin: 'org.jetbrains.kotlin.jvm'

sourceSets {
    main {
        java.srcDirs "src/java"
    }
}

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

dependencies {
    api project(':cjk')
    implementation project(':kokuban')
    implementation platform('org.jetbrains.kotlin:kotlin-bom')
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.beust:klaxon:5.0.1' 
    implementation "com.oracle.database.xml:xmlparserv2:21.1.0.0"
}
EN

回答 6

Stack Overflow用户

发布于 2022-09-29 11:08:14

打开gradle/wrapper/ gradle -wrapper.properties文件,并将gradle版本修改为:

代码语言:javascript
运行
复制
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip
票数 13
EN

Stack Overflow用户

发布于 2022-08-14 07:16:46

我不得不手动升级gradle

代码语言:javascript
运行
复制
./gradlew wrapper --gradle-version 7.5.1
./gradlew --version
./gradlew build

之后,gradlew构建了Kotlin 1.7.10代码,并在IntelliJ IDEA中成功地构建了Kotlin 1.7.10代码。有趣的是,IntelliJ抱怨不可用的特性(绝对是输入T& Any),但是它可以编译它,而且它似乎可以工作。

感觉像是IntelliJ IDEA CE还没有正式支持Kotlin 1.7.10吗?

票数 5
EN

Stack Overflow用户

发布于 2022-08-21 10:40:24

在我的例子中,只需替换为

代码语言:javascript
运行
复制
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21'

从…

代码语言:javascript
运行
复制
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.10'
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73342537

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档