1

I have installed both OpenJDK 6 and OpenJDK 7; before I was exclusively working with JDK 6. Now I have a couple of Scala projects which produce compile errors because of a problem with Java Generics introduced to Swing in Java 7 (e.g. scala.ListView produces an error with javax.swing.JList).

How can I configure my sbt project such that it enforces the use of JDK 6? I would like to enable this on a per-project basis, as I might have other projects which make use of Java 7 API. I would like this configuration to be not depending on my particular local setup, such that if someone checks out my git repository, compilation will still work seemless on the other person's machine.

0__
  • 66,707
  • 21
  • 171
  • 266
  • 1
    `javacOptions ++= Seq("-source", "1.5", "-target", "1.5")` do not work? – om-nom-nom Feb 20 '14 at 10:44
  • 1
    http://stackoverflow.com/questions/7701692/setting-up-sbt-to-use-java-7-for-compilation – goozez Feb 20 '14 at 12:13
  • @om-nom-nom no that has no effect. The `-source` and `-target` settings merely specify class file format compatibility. It will still use the default javac and thus fail. – 0__ Feb 20 '14 at 13:10
  • @goozez ok, so `sbt -java-home /usr/lib/jvm/java-6-openjdk-amd64/ compile` works for me, but it's not exactly cool to tell other people to figure out where their jdk 6 is and to run sbt like this. Is there no way to specify this in the build file and without using absolute paths? – 0__ Feb 20 '14 at 13:17
  • 2
    It will always depend on your particular setup, because there is no OS(or distribution)-independent way of discovering multiple JDKs. There is the one on the PATH, and/or JAVA_HOME, and that's it. At best, you could have an SBT task as part of your build that checks the JDK version and yells at the developer if it is wrong. – gourlaysama Feb 20 '14 at 14:35

0 Answers0