`idea` task fails with `sourceCompatibility` in gradle.properties

This cropped up when trying to import a Gradle 2.11-rc-1 project into IntelliJ, so I raised it as an issue with JetBrains. The basic error looks like this:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':ideaModule'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
    Caused by: java.lang.IllegalArgumentException: No enum constant org.gradle.api.JavaVersion.1.6
        at org.gradle.plugins.ide.idea.IdeaPlugin.getMaxJavaModuleCompatibilityVersionFor(IdeaPlugin.groovy:116)
        at org.gradle.plugins.ide.idea.IdeaPlugin$_configureIdeaProject_closure3$_closure10.doCall(IdeaPlugin.groovy:95)
        at org.gradle.api.internal.ConventionAwareHelper$1.getValue(ConventionAwareHelper.java:72)
        at org.gradle.api.internal.ConventionAwareHelper$MappedPropertyImpl.getValue(ConventionAwareHelper.java:136)
        at org.gradle.api.internal.ConventionAwareHelper.getConventionValue(ConventionAwareHelper.java:114)
        at org.gradle.plugins.ide.idea.model.IdeaProject_Decorated.getLanguageLevel(Unknown Source)
        at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.getProperty(BeanDynamicObject.java:166)
        at org.gradle.api.internal.BeanDynamicObject.getProperty(BeanDynamicObject.java:109)
        at org.gradle.api.internal.CompositeDynamicObject.getProperty(CompositeDynamicObject.java:81)

I’ve selectively removed some parts of the stacktrace. The IntelliJ import has the same error, but a different stacktrace. I’m wondering whether something changed in the Tooling API.

The source of the problem seems to be having the sourceCompatibility and targetCompatibility properties in gradle.properties rather than directly in the build file. If I move them to the build file, everything works fine.

Note that I’m not seeing this problem with either Gradle 2.10 or 2.8.

It seems that gradle doesn’t do a good job in having these properties set in the gradle.properties file. My guess is (without looking deeper) is that when you declare that property explicitly in the gradle.properties file, the JavaConvention object is silently ignored. When setting the target and sourceCompatibility in the build.gradle file you implicitly always convert it so a JavaVersion enum. The changes we made in the Idea plugin model now relies on JavaVersion and exposes this bad behaviour. We’ll discuss internally how to proceed here. (see e.g. https://github.com/gradle/gradle/blob/25fa7ed34ee6bf338cc1b1a6462dad0512febc3e/subprojects/plugins/src/main/groovy/org/gradle/api/plugins/JavaPluginConvention.groovy#L157-L159)

@pledbrook as far as I can tell, setting sourceCompatibility in a gradle.properties file has never worked. Those values were simply silently ignored and not actually passed to the compiler. This is likely generally true of any convention property that is added by a plugin (ex. webAppDirName from the ‘war’ plugin).

@mark_vieira I’m actually OK with that behaviour, except for the silent bit. Is it possible to detect clashes between ext properties and project convention properties?

We are discussing ways to deal with this better.

@pledbrook Can you confirm that 2.11-rc-2 fixes your issue, in that it no longer results in an error.

@mark_vieira 2.11-rc-2 fixes the problem with the idea task, but the project still fails to import into IntelliJ 15. I’ve put what I think are the relevant stacktraces on Pastebin.

@pledbrook let’s try this again :slight_smile: Can you try with RC3 that was just released?

Nope, same error. (here are some more characters to satisfy Discourse’s minimum post length…)

@pledbrook It seems my latest changes were not included in the most recent RC. I’ve created a snapshot release that should fix this issue. Can you confirm? Thanks for your patience.


OK, that seems to be working now, thanks.

I take it the properties are still being ignored? I plan to move them into the build file anyway, but was just wondering.

Yes, they are ignored.