我有使用Java库的Scala控制台应用程序。我是Gradle和Scala的新手。我没有使用任何IDE,只有VS Code和Gradle。 我可以使用Gradle构建应用程序,但是尝试运行时出现异常,未找到类。
$ gradle run
Exception in thread "main" java.lang.NoClassDefFoundError: scala/Product$class
at scopt.Head$.<init>(options.scala:148)
at scopt.Head$.<clinit>(options.scala)
at scopt.OptionParser.head(options.scala:251)
at console.App$$anon$1.<init>(App.scala:20)
at console.App$.main(App.scala:19)
at console.App.main(App.scala)
Caused by: java.lang.ClassNotFoundException: scala.Product$class
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 6 more
我猜测jar文件不会复制到build / distribution或build / libs文件夹中。
构建文件如下:
plugins {
// Apply the scala plugin to add support for Scala
id 'scala'
id 'application'
id 'distribution'
}
repositories {
// Use jcenter for resolving your dependencies.
// You can declare any Maven/Ivy/file repository here.
jcenter()
maven {
url 'https://plugins.gradle.org/m2/'
}
}
dependencies {
implementation 'org.scala-lang:scala-library:2.12.7'
implementation 'org.mongodb.scala:mongo-scala-bson_2.12:2.5.0'
implementation 'org.apache.poi:poi:4.0.1'
implementation 'org.apache.logging.log4j:log4j-core:2.11.1'
implementation 'org.apache.logging.log4j:log4j-api:2.11.1'
implementation 'org.slf4j:slf4j-nop:1.7.25'
implementation 'org.apache.poi:poi-ooxml:4.0.1'
implementation group: 'com.github.scopt', name: 'scopt_2.11', version: '3.7.1'
implementation group: 'com.google.guava', name: 'guava', version: '27.0.1-jre'
implementation group: 'org.apache.logging.log4j', name: 'log4j-api-scala_2.12', version: '11.0'
implementation 'com.github.pcj:google-options:1.0.0'
// Use Scalatest for testing our library
testImplementation 'junit:junit:4.12'
testImplementation 'org.scalatest:scalatest_2.12:3.0.5'
// Need scala-xml at test runtime
testRuntimeOnly 'org.scala-lang.modules:scala-xml_2.12:1.1.1'
}
group = 'matches'
version = '1.0'
description = 'matches'
sourceCompatibility = '11'
mainClassName = 'console.App'
application {
mainClassName = "console.App"
}
我不确定需要添加什么内容。
答案 0 :(得分:2)
您正在混合库scala 2.11和scala 2.12。更改为 实现组:“ com.github.scopt”,名称:“ scopt_2.12”,版本:“ 3.7.1”