Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ IDEA and Gradle - Cannot be applied to '(groovy.lang.Closure)'

I have a Gradle file which, whenever I load open it in IntelliJ IDEA 14.1.5, shows IDE errors for the entire file. Namely all the errors seem to be either:

java.lang.String errors

java.lang.String errors

or

groovy.lang.Closure errors

groovy.lang.Closure errors

I've tried clearing the file's contents and only writing the top line:

group 'com.me.blah'

but even that results in an error.

For context's sake - this is an individual module in a larger SpringBoot project. This module is a set of simple static files (with Gradle for CSS compilation, static analysis, etc), while the rest are Java modules, and are not having Gradle issues.

Can anyone think why IntelliJ would be struggling to understand this Gradle file?

like image 238
Seb Charrot Avatar asked Oct 02 '15 10:10

Seb Charrot


4 Answers

I've noticed this often. When creating a new project and using the 'Gradle' template, IntelliJ seems to get it all wrong. So what I've resorted to doing is after creating a new project, delete the .idea and .iml files and re-open the project directly from the Gradle file. IntelliJ seems to better understand what is going on in this case.

like image 141
Jon Nichols Avatar answered Nov 12 '22 16:11

Jon Nichols


For the first part of the question: group is a property, so there must be an assignment, not a function call. The right code is:

group = 'com.me.blah'
like image 32
Beholder Avatar answered Nov 12 '22 17:11

Beholder


I found this suggestion in the IDEA bug tracker(IDEA-142683):

Workaround:
One can add a comment such as
//noinspection GroovyAssignabilityCheck
to suppress the warning, but this should not be necessary as these are standard every day Gradle usages.

This issue was recently updated and is marked fixed, ready for release with version 2016.2 release.

like image 18
FGreg Avatar answered Nov 12 '22 17:11

FGreg


Try File | Invalidate Caches and restart. It worked for me after i mess the syntaxe somewhere else in the file.

like image 17
Bancarel Valentin Avatar answered Nov 12 '22 16:11

Bancarel Valentin