Setting target directory for gRPC classes generated by Quarkus Gradle plugin

Viewed 710

Running ./gradlew quarkusGenerateCode works well, however the generated sources fall under the build directory:

enter image description here

I wouldn't like to set this path as a Gradle SourcesSet, "Mark Directory As" Generated Sources Root in Intellij, and so on as it's under the build directory.

Is there a way to set the output dir to something such as src/quarkus-generated-sources? The Quarkus user guides and the gradle plugin documentation are not too informative regarding that subject.

There's the build.gradle, nothing much special about it

plugins {
    id 'io.quarkus'
}

dependencies {
    implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
    implementation 'io.quarkus:quarkus-grpc'
    ... 
}
1 Answers

There is no way to specify an alternative path for the built-in code generation mechanism.

The classes generated by Quarkus from your *.proto files may change quite often. If you run Quarkus in the development mode, they will be regenerated on each change (in the *.proto files). In such a set up this is an outcome of the build rather than a source, that's why I put it in build.

I think you could use Gradle protobuf plugin to generate the java files. It has an option to specify the output directory. Don't forget to register quarkus-grpc-protoc-plugin similarly to Maven protobuf plugin configuration. The drawback of switching to it is that you won't be able to use the full power of the development mode when modifying the *.proto files.

Related