Fork me on GitHub
#leiningen
<
2018-05-02
>
peter hull12:05:48

Should leiningen 2.8.1 work with JDK 9 & 10 on Linux?

peter hull12:05:30

I am getting "Java compiler not found; Be sure to use java from a JDK rather than a JRE by modifying PATH or setting JAVA_CMD." on a project with Java in it.

peter hull12:05:02

(This is Fedora 28)

peter hull12:05:56

More info - in JShell I get this: jshell> ToolProvider.getSystemJavaCompiler() $2 ==> com.sun.tools.javac.api.JavacTool@271053e1 But in lein repl, this: user=> (javax.tools.ToolProvider/getSystemJavaCompiler) nil JDK 1.8.0 is OK, so I've switched to that.

nfisher17:05:58

@peterhull90 I haven’t tried and it’s not immediately clear from this thread; https://github.com/technomancy/leiningen/issues/2149

nfisher18:05:59

From the news I would assume there’s some compatibility so it might be down to the specific plugins you’re using. https://github.com/technomancy/leiningen/blob/master/NEWS.md

peter hull20:05:27

Thanks @nfisher! I did see that bug and it looked different to what I'm seeing. I admit I didn't spend long but it seemed like lein basically worked with JDK9/10 (lein repl was fine, etc.) but could not invoke javac. I cannot believe I'm the only person to have tried it, so, you may well be right to suggest it's something to do with my plugins. Will investigate further.

mikerod20:05:25

Are you sure you have the JDK of 1.9 and not just the JRE ? 😛

peter hull07:05:16

I am fairly sure I have JDK10 installed:

peter hull07:05:19

[peter@dell ~]$ dnf list installed |grep java-openjdk java-openjdk.x86_64 1:10.0.0.46-10.fc28 @updates java-openjdk-devel.x86_64 1:10.0.0.46-10.fc28 @updates java-openjdk-headless.x86_64 1:10.0.0.46-10.fc28 @updates [peter@dell ~]$ javac -version javac 10

peter hull07:05:28

Also I don't understand why javax.tools.ToolProvider.getSystemJavaCompiler returns an instance of com.sun.tools.javac.api.JavacTool in jshell and nil in lein repl

mikerod13:05:40

Well, it is possible you have the two tools configured to a different location of the jdk vs jre, but I’m not sure what may be the issue

mikerod13:05:45

perhaps set JAVA_CMD for lein to whatever the jshell is using to be sure that isn’t the case

peter hull19:05:03

I'm thinking it's a module thing - the javadocs say it might return null if jdk.compiler module is not available: https://docs.oracle.com/javase/10/docs/api/javax/tools/ToolProvider.html#getSystemJavaCompiler() so may be some way to specify java modules to lein?

mikerod20:05:09

Ah yeah, if it is something like that

mikerod20:05:38

I’m not sure at what level of lein you are seeing the problem, but there are ways to give jvm args

mikerod20:05:29

for jvm options for your own project, you can add :jvm-opts ["--add-modules" "the.module.you.need.here"]

mikerod20:05:09

that may be all you need, if you know what module the java compiler is in that you need

mikerod20:05:17

if it more at a leins own jvm process level, then you can look into the JVM_OPTS environment variable or LEIN_JVM_OPTS, I’m not sure the difference offhand, both are referenced in the sample project here https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L515

peter hull20:05:02

Thanks. I am at home now but I will try those various options tomorrow at work. I feel I don't really understand java any more...

mikerod20:05:40

Well, the Java module system stuff has certainly caused some thrash I’d say

mikerod20:05:10

I haven’t done much with Java 9+ yet. I’ll be surprised if you have found a lein config issue with a new jdk that no one else had for some reason.

mikerod20:05:56

A lot of lein stuff had issues at first with it trying to load stuff on the bootclasspath and also some dependencies on some now-not-auto-included jdk modules around xml bindings

mikerod20:05:08

However, your problem seemed to be a different one with the Java compiler

peter hull20:05:05

Yes, I am sure the problem is more likely to be at my end than something wrong with Fedora or Java or Leiningen. I was hoping someone here would have come across it already and know the answer!

😬 4
peter hull08:05:48

I solved my problem by using the 'alternatives' utility to set the 'java' alternative to Java 10 - it was set to 1.8, even though 'javac' and 'java_sdk_openjdk' were set to Java 10. This seems to have caused confusion.

👍 4
mikerod12:05:46

Hah. Well good you tracked it down.

👍 4