scalacenter/bloop

[Question] Does bloop support annotation processing for a pure Gradle Java project?

jdneo opened this issue ยท 3 comments

jdneo commented

Hi team ๐Ÿ‘‹,

I was recently aware of this build server and was playing around with it.

I tested it toward this project: https://github.com/mapstruct/mapstruct-examples/tree/main/mapstruct-on-gradle.

It's a Gradle project with pure Java codes.

The Bloop server works quite well, but it seems that the server won't include the generated folder build/generated/sources/annotationProcessor when dealing with the build target sources request. Is there anything I missed?

Thanks.

Hey @jdneo thanks for the question! It may just be the gradle plugin doesn't indeed correctly export the generated sources directory, meaning that Bloop doesn't know about them. I tried to reproduce this with the example repo you have, but I actually can't get the repo to build. Do you by chance have a more minimal reproduction that I could try this with?

@ckipp01 Gradle version being used is 6.2 so you have to use JDK 13 or lower to build with ./gradlew assemble
Or change the gradle/wrapper/gradle.properties file to contain distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip to upgrade and use up to JDK 19

I can get this to build with Gradle on the command line using ./gradlew assemble.

I can also get it to compile under Bloop with the warning Could not determine source for class org.mapstruct.example.SourceTargetMapperImpl but I'd expect that.

The javac options look correct as the generated sources are added using...

-s
  E:\mapstruct-examples\mapstruct-on-gradle\build\generated\sources\annotationProcessor\java\main

I can't compile under Metals though. The error is plug-in not found: semanticdb.

The plugin seems to be setup correctly with -Xplugin:semanticdb -sourceroot:E:\mapstruct-examples\mapstruct-on-gradle -targetroot:javac-classes-directory added to the javac options and E:\mapstruct-examples\mapstruct-on-gradle\null\bloop\cache\semanticdb\com.sourcegraph.semanticdb-javac.0.8.9\semanticdb-javac-0.8.9.jar added to the classpath (which is where the jar exists even though the null is odd)

I've tried this with the https://github.com/immutables/immutables annotation processor instead and I get the same issue.

So there seems to be some clash between annotation processors and the semanticdb plugin.

I don't really know this area well enough to know if something is missing from the javac options/classpath or whether there is actually an issue with the plugin. Do annotation processors work in SBT/Mill with Metals+Bloop+Java?

jdneo commented

As @Arthurm1 suggested, you can either update the gradle version in the gradle.properties or update the JDK version. A compatibility matrix can be found here: https://docs.gradle.org/current/userguide/compatibility.html.