我使用kotlin
DSL遵循这个Gradle用户指南,试图使子项目使用根项目中指定的依赖版本。以下是根build.gradle.kts
:的一部分
plugins {
`java-platform`
}
dependencies {
constraints {
api("com.google.guava:guava:28.0-jre")
api("org.testng:testng:6.14.3")
}
}
这是一个子项目的build.gradle.kts
:
plugins {
`java-library`
}
dependencies {
testImplementation("org.testng:testng")
}
val test by tasks.getting(Test::class) {
useTestNG()
}
当我在项目根目录中运行./gradlew run
时,一切都很顺利。然而,当我运行./gradlew test
时,它会抱怨:
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':misc:java:compileTestJava'.
> Could not resolve all files for configuration ':misc:java:testCompileClasspath'.
> Could not find org.testng:testng:.
Required by:
project :misc:java
我在网上到处找,但没有找到。我想我应该在根构建脚本中使用类似testapi("org.testng:testng:6.14.3")
的东西。
正如评论中已经回答的那样,您的子项目中缺少对平台的引用:
dependencies {
implementation(platform(rootProject)) // Will use the constraints defined in the platform
testImplementation("org.testng:testng")
}