简体   繁体   English

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

[英]java.lang.NoClassDefFoundError: scala/Product$class for gradle JUNIT test

I have a scala application with a build.gradle (using gradleVersion 4.4.1). 我有一个带有build.gradle的scala应用程序(使用gradleVersion 4.4.1)。 I am using the JUnit Framework. 我正在使用JUnit Framework。 The dependency and test task sections of my gradle.build is below 我的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
}

When I run gradle test 当我进行gradle测试时

Task :test FAILED 任务:测试失败

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

1 test completed, 1 failed 1个测试完成,1个失败

When I run gradle test --debug 当我运行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)

Below is The App Structure. 以下是应用程序结构。

.
├── 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

It seems scala classes are not available for the unit tests at run time, I have added testCompile for the scala-library as well in my dependencies and I still get the same error. 似乎scala类在运行时不适用于单元测试,我在我的依赖项中也为scala库添加了testCompile,但仍然遇到相同的错误。 None of my unit tests will run, rather JsonToSchemaSpec or others. 我的任何单元测试都不会运行,而是JsonToSchemaSpec或其他。

Such things usually happen when you accidentally mix different incompatible versions of scala/spark/scaletest. 当您意外混合使用不同的不兼容版本的scala / spark / scaletest时,通常会发生此类情况。 See this for example NoClassDefFoundError: scala/Product$class 请参见此示例NoClassDefFoundError:scala / Product $ class

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM