我正在使用Scala和Slick构建一个小型数据库查询实用程序,Maven作为我的构建和打包工具。
我的代码编译时没有任何语法错误,但构建失败了:
[INFO] --- maven-scala-plugin:2.15.0:compile (default) @ origdups ---
[INFO] Checking for multiple versions of scala
[INFO] includes = [**/*.scala,**/*.java,]
[INFO] excludes = []
[INFO] /home/lreeder/dev/scala/origdups/src/main/scala:-1: info: compiling
[INFO] Compiling 4 source files to /home/lreeder/dev/scala/origdups/target/classes at 1375638972068
[INFO] No known dependencies. Compiling everything
[ERROR] error: bad symbolic reference. A signature in Mapper.class refers to term runtime
[INFO] in package scala.reflect which is not available.
[INFO] It may be completely missing from the current classpath, or the version on
[INFO] the classpath might be incompatible with the version used when compiling Mapper.class.
(several more similar errors)
请注意,Mapper类不是我的代码。我认为这是Slick的一部分?我正在使用Scala 2.10.1作为maven-scala插件:
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.10.1</version>
</dependency>
和Slick 2.10(目前使用Scala 2.10.1构建):
<dependency>
<groupId>com.typesafe.slick</groupId>
<artifactId>slick_2.10</artifactId>
<version>1.0.1</version>
</dependency>
我已经编译了maven debug打开,这是生成上述错误的Java调用。
/usr/local/jdk1.7.0_21/jre/bin/java -classpath /home/lreeder/.m2/repository/org/scala-lang/scala-library/2.10.1/scala-library-2.10.1.jar:/home/lreeder/.m2/repository/org/scala-lang/斯卡拉编译/ 2.10.1 /斯卡拉编译-2.10.1.jar:/home/lreeder/.m2/repository/org/scala-lang/scala-reflect/2.10.1/scala-reflect-2.10.1。罐子:/home/lreeder/.m2/repository/org/scala-tools/maven-scala-plugin/2.15.0/maven-scala-plugin-2.15.0.jar -Xbootclasspath / A:/home/lreeder/.m2/repository/org/scala-lang/scala-library/2.10.1/scala-library-2.10.1.jar org_scala_tools_maven_executions.MainWithArgsInFile scala.tools.nsc.Main /tmp/scala-maven-6314934214401019063.args
我在这里缺少什么?需要在maven-scala插件配置中设置什么才能消除这些错误。
答案 0 :(得分:6)
此错误:
error: bad symbolic reference. A signature in Mapper.class refers to term runtime in package scala.reflect which is not available.
表示类路径中缺少scala.reflect.runtime。事实上,在检查/tmp/scala-maven-6314934214401019063.args时,它不在那里列出的类路径中。
Slick 2.10依赖于Scala反射包。见https://github.com/slick/slick/blob/master/src/main/scala/scala/slick/direct/MetadataProvider.scala。因此,Slick的POM应列出scala-reflect,以便其他项目可以将其解析为传递依赖。但是,slick_2.10-1.0.1.pom不会列出scala-reflect。
在我自己的项目中添加scala-reflect作为依赖项POM解决了这个问题。