mamoe / mirai-console

mirai 的高效率 QQ 机器人控制台
GNU Affero General Public License v3.0
1.19k stars 412 forks source link

mirai-gradle插件与gradle多模块项目冲突 #288

Closed Itsusinn closed 3 years ago

Itsusinn commented 3 years ago

有问题的构建文件:

plugins {
   kotlin("jvm")
   java
   kotlin("plugin.serialization")
   id("net.mamoe.mirai-console") 
}

mirai {
   coreVersion = "2.3.2" 
}

group = Project.Group
version = Project.Version

val compileKotlin: org.jetbrains.kotlin.gradle.tasks.KotlinCompile by tasks
compileKotlin.kotlinOptions.jvmTarget = "1.8"

dependencies {

   runtimeOnly(Dependency.Kotlin.StdLib) //buildSrc中定义的变量,下同
   runtimeOnly(Dependency.KotlinX.Coroutine)

   // websocket
   implementation(project(":forward-client:okhttp-client"))
   implementation(Dependency.Ktor.Client.WebSocket)
   compileOnly(Dependency.Ktor.Client.CIO)
   compileOnly(Dependency.Okhttp)

   implementation("io.github.microutils:kotlin-logging-jvm:2.0.2")
}

接着是build时的错误日志

Could not determine the dependencies of task ':message-source:mirai-source:compileJava'.
> Could not resolve all task dependencies for configuration ':message-source:mirai-source:compileClasspath'.
   > Could not resolve project :forward-client:okhttp-client.
     Required by:
         project :message-source:mirai-source
      > The consumer was configured to find an API of a library compatible with Java 8, preferably in the form of class files, and its dependencies declared externally, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm'. However we cannot choose between the following variants of project :forward-client:okhttp-client:
          - compile
          - default
          - runtime
          - testCompile
          - testRuntime
        All of them match the consumer attributes:
          - Variant 'compile' capability io.itsusinn:okhttp-client:0.1.1 declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm':
              - Unmatched attributes:
                  - Doesn't say anything about its component category (required a library)
                  - Doesn't say anything about how its dependencies are found (required its dependencies declared externally)
                  - 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 its usage (required an API)
                  - Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :forward-client:okhttp-client' but the consumer didn't ask for it
          - Variant 'default' capability io.itsusinn:okhttp-client:0.1.1 declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm':
              - Unmatched attributes:
                  - Doesn't say anything about its component category (required a library)
                  - Doesn't say anything about how its dependencies are found (required its dependencies declared externally)
                  - 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 its usage (required an API)
                  - Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :forward-client:okhttp-client' but the consumer didn't ask for it
          - Variant 'runtime' capability io.itsusinn:okhttp-client:0.1.1 declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm':
              - Unmatched attributes:
                  - Doesn't say anything about its component category (required a library)
                  - Doesn't say anything about how its dependencies are found (required its dependencies declared externally)
                  - 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 its usage (required an API)
                  - Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :forward-client:okhttp-client' but the consumer didn't ask for it
          - Variant 'testCompile' capability io.itsusinn:okhttp-client:0.1.1 declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm':
              - Unmatched attributes:
                  - Doesn't say anything about its component category (required a library)
                  - Doesn't say anything about how its dependencies are found (required its dependencies declared externally)
                  - 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 its usage (required an API)
                  - Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :forward-client:okhttp-client' but the consumer didn't ask for it
          - Variant 'testRuntime' capability io.itsusinn:okhttp-client:0.1.1 declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm':
              - Unmatched attributes:
                  - Doesn't say anything about its component category (required a library)
                  - Doesn't say anything about how its dependencies are found (required its dependencies declared externally)
                  - 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 its usage (required an API)
                  - Provides attribute 'org.jetbrains.kotlin.localToProject' with value 'local to :forward-client:okhttp-client' but the consumer didn't ask for it
        The following variants were also considered but didn't match the requested attributes:
          - Variant 'apiElements' capability io.itsusinn:okhttp-client:0.1.1 declares an API of a library, packaged as a jar, 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 15 and the consumer needed a component compatible with Java 8
          - Variant 'runtimeElements' capability io.itsusinn:okhttp-client:0.1.1 declares a runtime of a library, packaged as a jar, 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 15 and the consumer needed a component compatible with Java 8

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

我并不确定这一问题是否由插件引起,但是在我改为手动管理依赖后便不再报错。

如果我问题描述的不够清楚可以查看下面两个完整的构建文件,(或是我的public项目) good-build.gradle.kts.txt bad-build.gradle.kts.txt

Him188 commented 3 years ago

这个应该是 ktor 的问题, 尝试与 mirai 依赖同版本的 ktor 或更新 kotlin 到 1.4.30

我前几天也遇到过, 通过 exclude mirai 的 okhttp 间接依赖解决了

Itsusinn commented 3 years ago

Thanks!