Emil D
Emil D

Reputation: 1904

How do I compile Java 8 sources with SBT

I am trying to compile a project containing some Java 8 source files using lambdas using SBT 0.13.7. Now, I set

-java-home /Library/Java/JavaVirtualMachines/jdk1.8.0_25.jdk/Home

in

/usr/local/etc/sbtopts

And apparently SBT does take this into consideration, because if I supply the wrong path it complains about no java being present.

However, when I try compiling, I get the following

[error] /Users/edafinov/GitRepos/Java8SBTTest/src/main/java/Main.java:10: error: illegal start of        expression
[error]     new ArrayList<Integer>().stream().filter(i -> i%2 ==0).count();
[error]                                                 ^
[error] 1 error
[error] (compile:compile) javac returned nonzero exit code
[error] Total time: 1 s, completed Dec 26, 2014 12:28:55 PM

This seems to indicate that SBT does not use javac 1.8, but rather the 1.7 one which is the default one for my system.

What am I doing wrong?

Thank you in advance

Upvotes: 1

Views: 1972

Answers (1)

Emil D
Emil D

Reputation: 1904

Apparently if you have a JDK in the path, SBT would try to use that one, even when you have explicitly set the -java-home option. I solved my problem by removing the default JDK from $PATH

Upvotes: 2

Related Questions