can IntelliJ set project JDK from build.gradle settings

Answered

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 

0
12 comments

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.

0

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-

0

Not exactly. I meant compatibility tag:

sourceCompatibility = 11
targetCompatibility = 11

 

0

ok great

Thank you for your help !

0

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

sourceCompatibility = 11
targetCompatibility = 11

don't set project JDK to 11 on import of a Gradle project, but shouldn't Idea Gradle plugin handle this?

idea {
    module {
        jdkName = '11'
    }
}

If not, could you explain what's the purpose of "jdkName" here?

0

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.

 
0

Ok, thanks.
I created a feature request for this functionality https://youtrack.jetbrains.net/issue/IDEA-211597

0

Why would a JDK, set manually in Project Structure to be JDK 8, occassionally switch itself to JDK 11 ? IDEA 2019.2 Ultimate :(

0

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.

0

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?

0

Hello,

JDK is set from Gradle used JDK, while language level is configured according to source compability.

0

Please sign in to leave a comment.