5

I'm building a small database query utility using Scala and Slick, with Maven as my build and packaging tool.

My code compiles without any syntax errors, but the build fails with this:

[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)

Note that the Mapper class is not my code. I think it's part of Slick? I'm using Scala 2.10.1 for the maven-scala plugin:

<dependency>
  <groupId>org.scala-lang</groupId>
  <artifactId>scala-library</artifactId>
  <version>2.10.1</version>
</dependency>

and Slick 2.10 (currently build with Scala 2.10.1):

<dependency>
   <groupId>com.typesafe.slick</groupId>
   <artifactId>slick_2.10</artifactId>
   <version>1.0.1</version>
</dependency>

I've compiled with maven debug turned on, and this is the Java call that generates the errors above.

/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/scala-compiler/2.10.1/scala-compiler-2.10.1.jar:/home/lreeder/.m2/repository/org/scala-lang/scala-reflect/2.10.1/scala-reflect-2.10.1.jar:/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

What am I missing here? What needs to be set in the maven-scala plugin configuration to get rid of these errors.

lreeder
  • 12,047
  • 2
  • 56
  • 65

1 Answers1

6

This error:

error: bad symbolic reference. A signature in Mapper.class refers to term runtime in package scala.reflect which is not available.

is saying that scala.reflect.runtime is missing from the classpath. And, indeed, upon checking /tmp/scala-maven-6314934214401019063.args, it was not in the classpaths listed there.

Slick 2.10 has dependencies on the Scala reflection package. See https://github.com/slick/slick/blob/master/src/main/scala/scala/slick/direct/MetadataProvider.scala. So, the POM for Slick should list scala-reflect so that other projects can resolve it as a transitive dependency. However, slick_2.10-1.0.1.pom does not list scala-reflect.

Adding scala-reflect as a dependency in my own project POM fixed this.

lreeder
  • 12,047
  • 2
  • 56
  • 65
  • I am having the same but inside a multi-module project, and the missing class is a class which belongs to one of my modules (and in fact is there).Any suggestion? – Edmondo Aug 08 '13 at 13:53
  • Make sure the module that depends on the missing class has module that contains the as a dependency in your Maven POM. If that is set, run maven in debug mode (-X option) and check the ".args" file in the maven-scala-plugin command (see the end of the java command in my question). That args file should contain the jar with your dependency in its classpath. If not, you need to find a way to get it there. I was able to do so by adding a dependency to my POM. – lreeder Aug 08 '13 at 14:21
  • 1
    Actually I have found the problem. If you have two scala package objects with the same name (and different hierarchy), this does not compile. – Edmondo Aug 12 '13 at 06:46