Strange behaviour of IdeaProject.languageLevel

Assume that I have simple flat multi module (java) project where I specify ‘sourceCompatibility’ and ‘targetCompatibility’ on the subprojects. Here is what I have noticed:

‘IdeaProject.jdkName’ is always set properly according to ‘targetCompatibility’ but ‘IdeaProject.languageLevel’ does not. That is, ‘languageLevel’ is only set properly if I apply the ‘java’ and the ‘idea’ (in this order) plugins on the root project. This is undesirable because the root project should not be a ‘java’ project. I expect the ‘languageLevel’ to behave the same way as ‘jdkName’.

Of course, it is always possible to set these properties manually, the code below works properly:

// Applied on the root build script
apply plugin: 'idea'
idea.project.languageLevel = '1.7'
idea.project.jdkName= '1.7'

EDIT: I’m accessing these properties through the Tooling API.

‘jdkName’ is set based on the JDK version used to execute Gradle, making the reasonable assumption that most people will want to use the same JDK version in IDEA.

‘languageLevel’ is currently hardcoded to 1.6, except when the root project has the ‘java’ plugin applied, in which case ‘project.sourceCompatibility’ is used. I agree that this is far from perfect. A much better default would be to take the maximum source compatibility found in any subproject. (In IDEA this is a per-project setting, or in other words a per-Gradle-build setting.) I’ll open an issue to track this.