gpt4 book ai didi

gradle - 次要Gradle升级中断测试编译

转载 作者:行者123 更新时间:2023-12-03 03:48:09 25 4
gpt4 key购买 nike

我想逐步升级Gradle包装器,以提高构建速度。从2.3迁移到2.4后,测试编译失败,并出现incompatible types错误,我正在为依赖项而苦苦挣扎。

考虑一下此Spock测试:

class DetailsSortKeySpec extends Specification {
def 'Simple Test'() {
given:
TestDetailsSortKey testDetailsSortKey = new TestDetailsSortKey(details, collationKey)

expect:
testDetailsSortKey.details.equals(details)

where:
details | collationKey
new TestDetails(id: 0) | Collator.getInstance(Locale.ENGLISH).getCollationKey('')
}

private class TestDetailsSortKey extends DetailsSortKey<TestDetails> {
TestDetailsSortKey(TestDetails details, CollationKey collationKey) {
super(details, collationKey)
}
}
}

这个Java类:

public class DetailsSortKey<T extends Details> {

private final T details;
private final CollationKey collationKey;

public DetailsSortKey(final T details, final CollationKey collationKey) {
this.details = details;
this.collationKey = Objects.requireNonNull(collationKey);
}

public final T getDetails() {
return details;
}
}

运行 compileTestGroovy时出现以下错误消息:
/var/lib/jenkins/workspace/gradle_upgrade/build/tmp/compileTestGroovy/groovy-java-stubs/com/vendor/transfer/sorting/DetailsSortKeySpec.java:25: error: incompatible types: Details cannot be converted to TestDetails
super ((com.vendor.common.transfer.Details)null, (java.text.CollationKey)null);
^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error
startup failed:
Compilation failed; see the compiler error output for details.

1 error

FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':WEB-Commons:compileTestGroovy'.
> Compilation failed; see the compiler error output for details.

Release Notes没有列出似乎对此负责的任何问题,因此我仔细研究了Groovy Issues,这可能是根本原因,并且确实找到了 issue about Generics。但是该错误应该已经修复。我不明白在哪里以及为何尝试将 Details隐蔽为 TestDetails,这只是 Details类的简单而空的派生。

这些是两个Gradle发行版中使用的Groovy版本:

Gradle 2.3 :Groovy:2.3.9

Gradle 2.4 :Groovy 2.3.10

在我看来,这似乎完全像所引用的Groovy错误一样,但是应该从2.3.8开始就修复该错误,并且不应该影响此构建。此外,在项目中声明依赖项如下:
dependencies {
// mandatory dependencies for using Spock
compile "org.codehaus.groovy:groovy-all:2.4.11"
testCompile "org.spockframework:spock-core:1.1-groovy-2.4"
}

两个 gradlew :dependencies的输出之间的差异仅包含发行说明中提到的工具,但不属于测试范围。

最终,这里使用哪个Groovy版本?

最佳答案

我认为您希望使用与Gradle bundle 在一起的版本不同的Groovy进行编译。参见GroovyCompile.groovyClasspath

例如:

configurations {
groovy
}
dependencies {
groovy 'org.codehaus.groovy:groovy-all:2.4.11'
compile 'org.codehaus.groovy:groovy-all:2.4.11'
testCompile('org.spockframework:spock-core:1.0-groovy-2.4') {
exclude module: 'groovy-all'
}
}
compileGroovy {
groovyClasspath = configurations.groovy
}

*编辑*

要查看选择了哪个版本(由于依赖关系解析),您可以
gradle dependencies

或(其中xxx是子项目名称)
gradle xxx:dependencies

要强制特定的依赖版本,您可以
configurations.all {
resolutionStrategy {
force 'org.codehaus.groovy:groovy-all:2.4.11'
}
}

参见 ResolutionStrategy

关于gradle - 次要Gradle升级中断测试编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48383397/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com