我正在尝试从Gradle 7迁移我的Java项目。6版本到gradle 8。1版本,但在迁移时,我得到下面的错误。
我不确定我需要进一步做什么。有人能帮帮我吗下面是我目前得到的代码:
if (args[i].split("=")[0].equalsIgnoreCase("SUITE")) {testSuite = args[i].split("=")[1]}
project.setProperty("country", country)
System.properties.put("country", country)
project.setProperty("environment", environment + "." + country)
System.properties.put("environment", environment + "." + country)
systemProperties System.properties
project.logger.lifecycle("Finished extracting params - attempting to kick off tests with JUnit")
//Find and execute the tests using JUnit by including only the combinations of annotations given in the command line
useJUnitPlatform {
if (project.hasProperty('includeTags')) {includeTags project.getProperty('includeTags')}
includeTags "" + country + " & " + testSuite
project.logger.lifecycle("Junit Starting - using test suite: " + testSuite + ", country" + country+ " and environment: " + environment)
}
错误:
org.gradle.api.internal.tasks.testing.TestSuiteExecutionException: Could not complete execution for Gradle Test Executor 6.
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:64)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
at com.sun.proxy.$Proxy2.stop(Unknown Source)
at org.gradle.api.internal.tasks.testing.worker.TestWorker$3.run(TestWorker.java:193)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100)
at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60)
at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:113)
at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:65)
at worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
at worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)
Caused by: org.junit.platform.commons.PreconditionViolationException: Unable to parse tag expression " & SMOKE": missing lhs operand for '&' at index <1>
at org.junit.platform.launcher.TagFilter.lambda$parse$8(TagFilter.java:181)
at org.junit.platform.launcher.tagexpression.ParseResult.tagExpressionOrThrow(ParseResult.java:42)
at org.junit.platform.launcher.TagFilter.parse(TagFilter.java:180)
at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193)
at java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1384)
at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:482)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:472)
at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
at org.junit.platform.launcher.TagFilter.parseAll(TagFilter.java:176)
at org.junit.platform.launcher.TagFilter.includeMatching(TagFilter.java:133)
at org.junit.platform.launcher.TagFilter.includeTags(TagFilter.java:89)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.addTagsFilter(JUnitPlatformTestClassProcessor.java:166)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.createLauncherDiscoveryRequest(JUnitPlatformTestClassProcessor.java:150)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.access$400(JUnitPlatformTestClassProcessor.java:58)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:108)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:90)
at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:85)
at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:62)
... 18 more
1条答案
按热度按时间o3imoua41#
依赖性冲突:Gradle 8可以具有更严格的依赖性冲突解决。您可能需要更新某些依赖项以解决冲突。您可以使用以下命令查看依赖项冲突:
./gradlew dependencies --configuration <configuration>
替换为要检查的配置,例如
compileClasspath
已弃用的功能:Gradle 8可能会弃用Gradle 7中提供的某些功能。您应该查看Gradle发行说明以了解任何弃用通知,并相应地更新您的构建。
生成扫描:您可以使用生成扫描来诊断生成的问题。要创建构建扫描,请运行以下命令:
./gradlew build --scan
这将生成一个URL,您可以与其他人共享该URL或使用该URL自己查看扫描结果。
如果您在升级到Gradle 8后运行JUnit测试用例时遇到问题,则可能是您使用的JUnit版本与Gradle 8不兼容。Gradle 8已经将其默认的JUnit版本更新为JUnit 5,其使用的语法和API与JUnit 4不同。
要解决此问题,您可以尝试以下步骤:
更新JUnit版本:您可以在构建中更新JUnit版本。gradle文件使用JUnit 5。为此,请将以下行添加到依赖关系块:
这将向您的项目添加JUnit 5依赖项。
更新测试任务:如果您使用的是默认的Gradle测试任务,则可能需要更新它以使用JUnit 5运行器。为此,请将以下行添加到构建中。gradle文件:
这将配置测试任务以使用JUnit 5运行器。
更新测试代码:如果您有任何JUnit 4测试代码使用了已弃用的API,则可能需要更新它以使用新的JUnit 5语法和API。您可以在JUnit 5用户指南中找到有关JUnit 5语法和API的更多信息。
运行测试:在进行更改后,再次运行测试,看看它们是否运行时没有错误。