我是 Scala 和 XGBoost 的新手。我从一位在生产中工作的同事那里收到了一个 Gradle Scala 项目,我正在尝试在我的机器上运行它。当我尝试运行时,出现此错误:
Exception in thread "main" java.lang.NoClassDefFoundError: scala/Serializable
(...)
Caused by: java.lang.ClassNotFoundException: scala.Serializable
我对 Scala 比较陌生,但在 Java 方面经验丰富,但我在网上找不到这个错误的好答案。
仅当涉及 XGBoost 库时才会发生此错误,否则项目运行正常。
我还应该提到,我在使用 Metals 从 Visual Studio Code 运行时收到此消息:
2021.12.03 18:11:49 INFO no build target: using presentation compiler with only scala-library: 2.13.5
摇篮设置:
apply plugin: 'scala'
apply plugin: 'java'
apply plugin: 'idea'
idea {
module {
inheritOutputDirs = true
downloadJavadoc = false
downloadSources = false
}
}
sourceCompatibility = 1.11
targetCompatibility = 1.11
def scalaVersion = '2.13.5'
def scalaRelease = scalaVersion.split('\\.').take(2).join('.')
repositories {
mavenCentral()
maven {url "https://repository.cloudera.com/artifactory/cloudera-repos/"}
}
//def deploy = 'desm'
def deploy = 'prod'
dependencies {
if (deploy == 'prod') {
compileOnly "org.scala-lang:scala-library:$scalaVersion"
compileOnly group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.11.2'
compileOnly group: 'com.fasterxml.jackson.module', name: "jackson-module-scala_$scalaRelease", version: '2.11.2'
compileOnly group: 'org.apache.hbase', name: 'hbase-client', version: '2.1.0-cdh6.3.3'
compileOnly group: 'org.apache.kafka', name: 'kafka-clients', version: '2.2.1-cdh6.3.3'
}else if (deploy == 'desm'){
compile "org.scala-lang:scala-library:$scalaVersion"
compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.11.2'
compile group: 'com.fasterxml.jackson.module', name: "jackson-module-scala_$scalaRelease", version: '2.11.2'
compile group: 'org.apache.hbase', name: 'hbase-client', version: '2.1.0-cdh6.3.3'
compile group: 'org.apache.kafka', name: 'kafka-clients', version: '2.2.1-cdh6.3.3'
}
compile group: 'ml.dmlc', name: 'xgboost4j', version: '0.72', {
exclude group: 'com.typesafe.akka', module: 'akka-actor_2.11'
exclude group: 'com.typesafe.akka', module: 'akka-testkit_2.11'
exclude group: 'junit', module: 'junit'
exclude group: 'org.scala-lang', module: 'scala-compiler'
exclude group: 'org.scala-lang', module: 'scala-reflect'
exclude group: 'org.scala-lang', module: 'scala-library'
exclude group: 'org.scalatest', module: 'scalatest_2.11'
}
}
JVM:11.0.13
XGBoost:0.72(我知道这是旧版本)
Scala:2.13.5