gpt4 book ai didi

java - java.lang.NoClassDefFoundError:用于gradle JUNIT测试的scala/Product $ class

转载 作者:行者123 更新时间:2023-12-03 05:07:58 26 4
gpt4 key购买 nike

我有一个带有build.gradle的scala应用程序(使用gradleVersion 4.4.1)。我正在使用JUnit框架。我的gradle.build的依赖项和测试任务部分如下

dependencies {
compile 'org.scala-lang:scala-library:2.11.12'
compile 'org.apache.spark:spark-core_2.11:2.0.2'
compile 'org.apache.spark:spark-sql_2.11:2.0.2'
compile 'org.apache.spark:spark-hive_2.11:2.0.2'
compile 'com.typesafe.play:play-json_2.12:2.6.9'
compile 'com.fasterxml.jackson.module:jackson-module-jsonSchema:2.9.8'
testCompile 'org.scalatest:scalatest_2.11:3.0.0'
testCompile 'junit:junit:4.12'
}


test {
testLogging.showStandardStreams = true
}

当我进行gradle测试时

Task :test FAILED


com.someOrg.gdpschemautils.JsonToSchemaSpec > initializationError FAILED
java.lang.NoClassDefFoundError
Caused by: java.lang.ClassNotFoundException

1个测试完成,1个失败

当我运行gradle test --debug
19:20:21.303 [DEBUG] [TestEventLogger] com.someOrg.gdpschemautils.JsonToSchemaSpec > initializationError FAILED
19:20:21.303 [DEBUG] [TestEventLogger] java.lang.NoClassDefFoundError: scala/Product$class
19:20:21.303 [DEBUG] [TestEventLogger] at org.scalatest.time.Units.<init>(Units.scala:33)
19:20:21.304 [DEBUG] [TestEventLogger] at org.scalatest.time.Days$.<init>(Units.scala:293)
19:20:21.304 [DEBUG] [TestEventLogger] at org.scalatest.time.Days$.<clinit>(Units.scala)
19:20:21.304 [DEBUG] [TestEventLogger] at org.scalatest.time.Span$.<init>(Span.scala:584)
19:20:21.304 [DEBUG] [TestEventLogger] at org.scalatest.time.Span$.<clinit>(Span.scala)
19:20:21.304 [DEBUG] [TestEventLogger] at org.scalatest.Suite$.<init>(Suite.scala:1399)
19:20:21.304 [DEBUG] [TestEventLogger] at org.scalatest.Suite$.<clinit>(Suite.scala)

以下是应用程序结构。
.
├── README.md
├── build.gradle
├── gradle.properties
├── settings.gradle
├── gradlew
├── gradlew.bat
├── src
└── main
└── scala
└── com
└── someOrg
└── gdpschemautils
├── Config
├── DataSourcePathException
├── JsonToSchema
├── ObjectToJsonSchema
├── SchemaConverter
├── SchemaToJson

└── test
└── resources
├── testJsonSchema.json

└── scala
└── com
└── someOrg
└── gdpschemautils
├── JsonToSchemaSpec

似乎scala类在运行时不适用于单元测试,我在我的依赖项中也为scala库添加了testCompile,但仍然遇到相同的错误。我的任何单元测试都不会运行,而是JsonToSchemaSpec或其他。

最佳答案

当您意外混合使用不同的不兼容版本的scala / spark / scaletest时,通常会发生此类情况。参见此示例NoClassDefFoundError: scala/Product$class

关于java - java.lang.NoClassDefFoundError:用于gradle JUNIT测试的scala/Product $ class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54432994/

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