2

Given:

$cat build.sbt 
scalaVersion := "2.11.8"

libraryDependencies ++= List(
  "io.spray"          %% "spray-client"        % "1.3.3"
  ,"io.spray"          %%  "spray-json"         % "1.3.2"
  ,"com.typesafe.akka" %% "akka-actor"          % "2.4.2"
  ,"com.typesafe"      % "config" % "1.3.0"
  ,"org.scalatest" % "scalatest_2.11" % "2.2.6" % "test"
)

Using this answer, I attempted to use JDK 7.

However, I got the following errors:

$sbt -java-home /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/ clean test
[info] Loading project definition from /Users/Kevin/Workspace/Work/project/project
[info] Set current project to project (in build file:/Users/Kevin/Workspace/Work/project/)
[success] Total time: 0 s, completed Mar 14, 2016 3:51:10 PM
[info] Updating {file:/Users/Kevin/Workspace/Work/project/}project...
[info] Resolving jline#jline;2.12.1 ...
[info] Done updating.
[info] Compiling 9 Scala sources to /Users/Kevin/Workspace/Work/project/target/scala-2.11/classes...
[error] Class java.time.Duration not found - continuing with a stub.
[error] Class java.time.Duration not found - continuing with a stub.
[error] two errors found
[error] (compile:compileIncremental) Compilation failed
[error] Total time: 5 s, completed Mar 14, 2016 3:51:16 PM

Looking at this answer, I'm guessing/speculating that I need to add a java8 time library as a dependency?

Community
  • 1
  • 1
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384

2 Answers2

2

I'm not sure how to fix this error.

This error indicates that somewhere in your code you're relaying on java.time.Duration which is a new API exposed in Java 8. Since you've downgraded to Java 7, this class is no longer available.

Either remove the dependency, or revert back to Java8.

Yuval Itzchakov
  • 146,575
  • 32
  • 257
  • 321
2

Akka 2.4 requires JDK8 unless you are using a commercial build, this is mentionned in the documentation.

relevant extract

Akka requires that you have Java 8 or later installed on your machine.

Typesafe provides a commercial build of Akka and related projects such as Scala or Play as part of the Reactive Platform which is made available for Java 6 in case your project can not upgrade to Java 8 just yet. It also includes additional commercial features or libraries.

Typesafe config 1.3.0 also depends on java8

Version 1.2.1 and earlier were built for Java 6, while newer versions (1.3.0 and above) will be built for Java 8.

Also beware that spray-client 1.3.3 depends on Akka 2.3.9 (see http://spray.io/project-info/current-versions/#current-versions) you may want to upgrade to akka-http which is the successor to spray.

(since you seem to use a posix compliant system, you may want to have a look at jenv for managing per project jdk versions)

Jean
  • 21,329
  • 5
  • 46
  • 64
  • I downgraded from Akka v. `2.4.2` to `2.3.14`, per `Akka 2.3.14 (previous stable release) for Scala 2.10 / 2.11 and Java 6+` in the [docs](http://akka.io/docs/). But, when re-running the same `sbt -java-home .../jdk7/...`, I got the same error. – Kevin Meredith Mar 15 '16 at 01:13
  • 1
    check your typesafe config version, downgrading both akka and typesafe config, the warning disappears. – Jean Mar 15 '16 at 08:19
  • Thanks, Jean, downgrading to `"com.typesafe.akka" %% "akka-actor" % "2.3.14"` and `"com.typesafe" % "config" % "1.2.1"` worked for JDK7. How'd you know to change the `typesafe config` too? – Kevin Meredith Mar 15 '16 at 15:20
  • Well through technical watch I know lightbend/typesafe has been migrating its OSS libraries to support java 8 (for performance with the lambda bytecode emitter and for business by providing java 6 compatible builds to paying customers). I copied the akka hello-world sample and tried to compile them with your build definition. After downgrading akka I noticed I was still getting the warning and checked the `config` documentation :) – Jean Mar 15 '16 at 15:31