无法使用Gradle 6.1.1解析junit-jupiter-params:5.6.2和junit-jupiter-engine:5.6.2 [英] Can not resolve junit-jupiter-params:5.6.2 and junit-jupiter-engine:5.6.2 with Gradle 6.1.1

查看:106
本文介绍了无法使用Gradle 6.1.1解析junit-jupiter-params:5.6.2和junit-jupiter-engine:5.6.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android项目,其中包含2个Android模块和一个纯Java模块.
将android构建工具更新为com.android.tools.build:gradle:4.0.0并将gradle包装器更新为gradle-6.1.1之后,所有纯Java模块都无法再解析junit了.
与gradle文件同步时出现以下错误:

I have an Android project with 2 Android modules and one pure Java module.
After updating the android build tools to com.android.tools.build:gradle:4.0.0 and the gradle wrapper to gradle-6.1.1-all the pure Java module can not resolve junit anymore.
I get the following error while syncing with the gradle files:

Failed to resolve: org.junit.jupiter:junit-jupiter-params:5.6.2 
Failed to resolve: org.junit.jupiter:junit-jupiter-engine:5.6.2

如果我尝试直接运行测试,则会得到以下输出:

If I try to run the tests directly I get the following output:

Could not resolve all files for configuration ':domain:testCompileClasspath'.
   > Could not resolve org.junit.jupiter:junit-jupiter-params:5.6.2.
     Required by:
         project :domain
      > Cannot choose between the following variants of org.junit.jupiter:junit-jupiter-params:5.6.2:
          - javadocElements
          - sourcesElements
        All of them match the consumer attributes:
          - Variant 'javadocElements' capability org.junit.jupiter:junit-jupiter-params:5.6.2:
              - Unmatched attributes:
                  - Found org.gradle.category 'documentation' but wasn't required.
                  - Found org.gradle.docstype 'javadoc' but wasn't required.
                  - Required org.gradle.jvm.version '7' but no value provided.
                  - Required org.gradle.libraryelements 'classes' but no value provided.
                  - Found org.gradle.status 'release' but wasn't required.
                  - Required org.jetbrains.kotlin.platform.type 'jvm' but no value provided.
              - Compatible attributes:
                  - Required org.gradle.dependency.bundling 'external' and found compatible value 'external'.
                  - Required org.gradle.usage 'java-api' and found compatible value 'java-runtime'.
          - Variant 'sourcesElements' capability org.junit.jupiter:junit-jupiter-params:5.6.2:
              - Unmatched attributes:
                  - Found org.gradle.category 'documentation' but wasn't required.
                  - Found org.gradle.docstype 'sources' but wasn't required.
                  - Required org.gradle.jvm.version '7' but no value provided.
                  - Required org.gradle.libraryelements 'classes' but no value provided.
                  - Found org.gradle.status 'release' but wasn't required.
                  - Required org.jetbrains.kotlin.platform.type 'jvm' but no value provided.
              - Compatible attributes:
                  - Required org.gradle.dependency.bundling 'external' and found compatible value 'external'.
                  - Required org.gradle.usage 'java-api' and found compatible value 'java-runtime'.

如何告诉Gradle应该在哪里寻找正确的junit依赖项?

How can I tell Gradle where it should look for the correct junit dependencies?

推荐答案

我发现的一个类似问题(我的问题是org.junit.jupiter:junit-jupiter-api)的解决方案是更新Java的源兼容性.测试到1.8.

The solution I have found for a similar issue (mine was with org.junit.jupiter:junit-jupiter-api) is to update the source compatibility of the tests to 1.8.

compileJava {
    sourceCompatibility = "1.7"
    targetCompatibility = "1.7"
}
compileTestJava {
    sourceCompatibility = "1.8"
    targetCompatibility = "1.8"
}

通过这种方式,生产源仍与1.7兼容以允许Android构建.

This way the production source is still compatible with 1.7 to allow the Android build.

这篇关于无法使用Gradle 6.1.1解析junit-jupiter-params:5.6.2和junit-jupiter-engine:5.6.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆