gradlequarkusgradle-multi-project-build

Quarkus - Modular Rest Endpoints in Gradle Multi-Project Build


Is it possible to create a gradle multi-project build with following gradle-projects that depend on each other and contain Quarkus REST-Endpoints, that are then available in the started server?

The server1 project should be the typical quarkus-application that contains its application.conf and can be startable and has a Hello-World Rest-Endpoint.

The module1 defines some quarkus rest-endpoints

When server1 is started all! rest-endpoints (including those of module1 and module2) must be available.

Can someone give me an example how to achieve this, as i can not seem to get it to work, that a REST-Endpoint that is outside of "server1" is ever published/available to the web, when i start server1.

When i talk of REST-Endpoints i mean:

When i talk of Gradle Multi-Project i mean:

Im using:

For my example-project where i can not get it to work, see:


Solution

  • i found the solution how to do this now, after some research.

    The @Path Annotations of the REST-Endpoints are considered as "Beans".

    When reading the gradle-tooling section of the quarkus-documentation carefully, we can see in the chapter "Working with multi-module projects", that we need to do something to make quarkus discover the beans in other modules

    because by default, quarkus does not discover beans in other projects of the multi-module project.

    So the solution can be to defined the "jandex" plugin in the gradle.build file of the "module1" and "module2" projects. Then the "server1" project will load all beans (including @Path annotated) at startup.

    build.gradle

    plugins {
        id 'org.kordamp.gradle.jandex'
    }
    
    // needed, so jandex does not throw an error for enums. See: https://github.com/helidon-io/helidon/issues/7659
    jandex {
        version = '3.1.5'
    }
    

    Alternatively (and more recommended) it is also possible to create a folder src/main/resources/META-INF in the module1 and module2 project, and put a file beans.xml into this folder. That way quarkus will also recognize those projects as relevant for bean-discovery.