Micronaut-core: Project fails to compile with Java 11 module, micronaut 1.2.3 and gradle 5.6.2

Created on 15 Oct 2019  路  11Comments  路  Source: micronaut-projects/micronaut-core

Hi, I'm trying to create a simple application with Java 11 and modules (module-info.java present). I'm having a hard time getting things to compile, as soon as I add:

annotationProcessor(platform("io.micronaut:micronaut-bom:$micronautVersion"))
annotationProcessor("io.micronaut:micronaut-inject-java")

to my gradle project, then the build fails with:

> Task :app.runner:compileJava FAILED                              

FAILURE: Build failed with an exception.                           

* What went wrong:                                                 
Execution failed for task ':app.runner:compileJava'.               
> java.lang.IllegalArgumentException: Unexpected element app.runner

The environment is Java 11, Gradle 5.6.2 and Micronaut 1.2.3. The --stacktrace and --debug options does not tell me anything useful.

The module is named "app.runner" - and if I change the module name, the error changes accordingly. If I add the lombok annotation processor instead, the build also seems to work.

I asked on Gitter and Graeme Rocher pointed me to a working project (https://github.com/weiqigao/micronaut-test-modules-issue).

That sample project is running on my system after adding a gradle 5.6.2 wrapper and still using Java 11.
However when I bump the micronaut version in the sample project from 1.1.0 to 1.2.3 the compileJava task fails again with the same "unexpected element " error as I see in my project.

awaiting third-party bug

All 11 comments

This seems to be a Gradle bug to me. The stack trace is coming from Gradle's incremental compilation APIs

I recommend using Maven until this is resolved in the Gradle side

It is interesting that build works with micronaut 1.2.1, but broken with 1.2.2
tested with cli-app-modular-java
by changing version for micronaut-bom

dependencyManagement {
    imports {
        mavenBom 'io.micronaut:micronaut-bom:1.2.1'
    }
}

Yes the root cause is that we added support for Gradle incremental annotation processors in 1.2.2 to remove warnings that Kotlin emits when non-incremental annotation processors are present.

However Gradle's support for incremental annotation processors is broken with modules. Hence https://github.com/gradle/gradle/issues/11059

Thanks for clarification!
Will it help to disable incremental annotation processors and is there easy way to do it?

not that I am aware, but we should probably make it possible. Dagger allows you to disable it.

Alternative is to switch to Maven

Alternative is to switch to Maven

Or stick with earlier versions of Micronaut.

I tried it with Gradle 6.0 RC2 and the same problem occurs.

Update: Still occurs with 6.0 RC3, as well.

@graemerocher says the Gradle issue is fixed in Gradle 6.1: https://github.com/gradle/gradle/issues/11059#issuecomment-580358363

I just updated my project that was failing with Micronaut 1.2.2+ to Gradle 6.1.1 and Micronaut 1.2.10 and it builds and runs successfully.

Was this page helpful?
0 / 5 - 0 ratings