can IntelliJ set project JDK from build.gradle settings
Hello,
I am working on an open source project which is currently based on java 8. I would like to upgrade the JDK to openJDK 11 and ideally, I would like to do it so via Gradle file to make sure that all devs get the change on their next fecth).
I locally made a test by defining (JavaVersion sourceCompatibility) in build.gradle but it seems IntelliJ ignore that parameter and still use Java 1.8. My current JVM setting is set to "use project JDK".
Hence, I have the following question:
- Knowing most of the devs are using inteliiJ, what is the best way to ensure all of them start building the project against openJDK 11? Is there another option than setting that parameter in build.gradle ? I also saw this parameters in .idea/misc.xml, would it work if I change it manually both in that file and in build.graddle to make sure that all devs got it ? I would prefer to have it right before I push anything on git
I am open to suggestion and I would like to thank you in advance for your help.
BR
make sure that all other devs will have
Please sign in to leave a comment.
Hello,
It's not possible to switch project JDK via gradle build script. It could only set language/bytecode version, so errors will be shown when old JDK is used.
Hello,
Just to make sure I understand correctly what you are saying.
If I setup JavaVersion = OpenJDK 11.0 in build.gradle and commit the file.
Other devs using intelliJ will get an error message if their project JDK.was not set to the version specified. They will have to do update it manually but it will at least ensure, all devs are building using the same JDK, correct ? This would be sufficient for me.
What surprise me, is that when I tried earlier, I did not get error message, Intellij just build using java 1.8. I had no error message at all.
Thank you for your help-
Not exactly. I meant compatibility tag:
ok great
Thank you for your help !
You are welcome!
Hi! I had pretty much the same question https://stackoverflow.com/questions/55831655/what-should-i-put-in-build-gradle-to-set-ideas-project-jdk
I understand that
don't set project JDK to 11 on import of a Gradle project, but shouldn't Idea Gradle plugin handle this?
If not, could you explain what's the purpose of "jdkName" here?
JDK that you use in project or module must be set manually.
The mentioned settings control the Java language level source/target compatibility for the project (or module). See also https://stackoverflow.com/a/12900859/2000323.
>If not, could you explain what's the purpose of jdkName here?
Gradle idea plugin is developed by Gradle team. Please consult the plugin's documentation.
Ok, thanks.
I created a feature request for this functionality https://youtrack.jetbrains.net/issue/IDEA-211597
Why would a JDK, set manually in Project Structure to be JDK 8, occassionally switch itself to JDK 11 ? IDEA 2019.2 Ultimate :(
See https://youtrack.jetbrains.com/issue/IDEA-229164 Most likely you have 11 JDK set for Gradle JVM (Settings (Preferences on macOS) | Build, Execution, Deployment | Build Tools | Gradle | Gradle JVM). The JDK from Gradle JVM setting is actually used to build the project.
The feature request for this was marked as 'obsolete' on February 27, but it's still not working for me as of build 201.6668.121 (April 8, 2020).
Has it been superseded by another issue I can track?
Hello,
JDK is set from Gradle used JDK, while language level is configured according to source compability.