Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quarkus code-gen (Gradle): Fix behavior to filter unavailable services #36800

Merged

Conversation

snazy
Copy link
Contributor

@snazy snazy commented Oct 31, 2023

Java Services (those in META-INF/services/* files) that are defined in the (Gradle) project that uses the Quarkus Gradle plugin, are not available when Quarkus code generation runs. This is simply a task-dependency requirement in Gradle, because Java compilation happens after code generation. If a Java service, for example a Smallrye config sources, is present and the (Smallrye) configuration is needed by a Quarkus extension, the build fails during Quarkus code generation with an error message like this:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':quarkusGenerateCode'.
...
Caused by: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing io.quarkus.gradle.tasks.worker.CodeGenWorker
...
Caused by: java.util.ServiceConfigurationError: io.smallrye.config.ConfigSourceFactory: Provider xyz not found

io.quarkus.deployment.CodeGenerator has a mechanism to filter out unavailable services via getUnavailableConfigServices(). However the callback passed to io.quarkus.paths.PathTree.apply() can stop before all roots/trees (io.quarkus.paths.PathTree.getRoots()) have been "asked" (MultiRootPathTree), because the callback can return a non-null value. This "early stop" happens before the root/tree containing the source with the META-INF/services/* has been processed.

The bug is only triggered, if a Java service is defined in the Gradle project using the Quarkus Gradle plugin and if a Quarkus extension using the configuration is a dependency of that project.

This change updates the callback implementation to collect all unavailable services from all PathTree roots/trees.

An integration test using the Gradle plugin is included as well.

Two logging/spelling mistakes have been fixed as well.

Fixes #36716

Java Services (those in `META-INF/services/*` files) that are defined in the (Gradle) project that uses the Quarkus Gradle plugin, are not available when Quarkus code generation runs. This is simply a task-dependency requirement in Gradle, because Java compilation happens after code generation. If a Java service, for example a Smallrye config sources, is present and the (Smallrye) configuration is needed by a Quarkus extension, the build fails during Quarkus code generation with an error message like this:
```
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':quarkusGenerateCode'.
...
Caused by: org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing io.quarkus.gradle.tasks.worker.CodeGenWorker
...
Caused by: java.util.ServiceConfigurationError: io.smallrye.config.ConfigSourceFactory: Provider xyz not found
```

`io.quarkus.deployment.CodeGenerator` has a mechanism to filter out unavailable services via `getUnavailableConfigServices()`. However the callback passed to `io.quarkus.paths.PathTree.apply()` can stop before all roots/trees (`io.quarkus.paths.PathTree.getRoots()`) have been "asked" (`MultiRootPathTree`), because the callback can return a non-`null` value. This "early stop" happens before the root/tree containing the source with the `META-INF/services/*` has been processed.

The bug is only triggered, if a Java service is defined in the Gradle project using the Quarkus Gradle plugin and if a Quarkus extension using the configuration is a dependency of that project.

This change updates the callback implementation to collect all unavailable services from all `PathTree` roots/trees.

An integration test using the Gradle plugin is included as well.

Two logging/spelling mistakes have been fixed as well.

Fixes quarkusio#36716
@quarkus-bot quarkus-bot bot added area/core area/devtools Issues/PR related to maven, gradle, platform and cli tooling/plugins area/gradle Gradle labels Oct 31, 2023
@snazy
Copy link
Contributor Author

snazy commented Oct 31, 2023

Hm - the CI failures in the Devtools Tests look unrelated to me.

This comment has been minimized.

@radcortez
Copy link
Member

Hm - the CI failures in the Devtools Tests look unrelated to me.

Let's rebuild again, just in case.

Thanks for the PR!

@radcortez radcortez requested a review from aloubyansky November 2, 2023 11:02

This comment has been minimized.

Copy link

quarkus-bot bot commented Nov 3, 2023

✔️ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

@aloubyansky aloubyansky merged commit e6c6752 into quarkusio:main Nov 3, 2023
49 of 50 checks passed
@quarkus-bot quarkus-bot bot added this to the 3.6 - main milestone Nov 3, 2023
@gsmet gsmet modified the milestones: 3.6 - main, 3.5.1 Nov 6, 2023
@snazy snazy deleted the gradle-plugin-unavailable-services branch November 6, 2023 20:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core area/devtools Issues/PR related to maven, gradle, platform and cli tooling/plugins area/gradle Gradle kind/bugfix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot build project with quarkus-cxf extension and custom ConfigSourceFactory: Provider not found
4 participants