Static Compilation Regression in Gradle 3.0-m2


(Ethan Hall) #1

I was trying to get my plugins to build with Gradle 3.0-m2 and ran into a strange regression.

I have a class (annotated with @CompileStatic) that has this snippit

ideaModel.module.with {
    testSourceDirs += project.file('src/integTest/java')
    testSourceDirs += project.file('src/integTest/groovy')
    testSourceDirs += project.file('src/integTest/scala')
    testSourceDirs += project.file('src/integTest/resources')
}

Using Gradle 2.13 it compiles just fine, but when I update to 3.0-m2 I get a static compilation error:

<skipping path>/LiIdeaPlugin.groovy: 158: [Static type checking] - Cannot assign value of type java.io.File to variable of type java.util.Set <java.io.File>
 @ line 158, column 9.
           testSourceDirs += project.file('src/integTest/java')
           ^

<skipping path>/LiIdeaPlugin.groovy: 159: [Static type checking] - Cannot assign value of type java.io.File to variable of type java.util.Set <java.io.File>
 @ line 159, column 9.
           testSourceDirs += project.file('src/integTest/groovy')
           ^

<skipping path>/LiIdeaPlugin.groovy: 160: [Static type checking] - Cannot assign value of type java.io.File to variable of type java.util.Set <java.io.File>
 @ line 160, column 9.
           testSourceDirs += project.file('src/integTest/scala')
           ^
<skipping path>/LiIdeaPlugin.groovy: 161: [Static type checking] - Cannot assign value of type java.io.File to variable of type java.util.Set <java.io.File>
 @ line 161, column 9.
           testSourceDirs += project.file('src/integTest/resources')

This may be an issue with upgrading to a later version of Groovy but I though I would report it.


(Stefan Wolf) #2

Hi Ethan,

thank you for reporting.
I analyzed the problem: We converted the underlying class IdeaModule to Java. As a consequence the static Groovy compiler does not allow using += on collections, even though the classes look the same. Running the same code without @CompileStatic works.

An version of your plugin compiled with Gradle 2.13 should still work with Gradle 3.0 - we did not break binary compatibility. Could you please try that out?

Could you please replace your snippet with

ideaModel.module.with {
    testSourceDirs = testSourceDirs + [
        project.file('src/integTest/java'),
        project.file('src/integTest/groovy'),
        project.file('src/integTest/scala'),
        project.file('src/integTest/resources')
    ]
}

Sorry for the inconvenience.


(Ethan Hall) #3

Hey Stefan,

I have already fixed the issue just wanted to let you know so it can be put in the release notes. I don’t believe I had issues with this at runtime.

Thanks for getting back to me.