-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Quarkus code-gen (Gradle): Fix behavior to filter unavailable services
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
- Loading branch information
Showing
12 changed files
with
130 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
integration-tests/gradle/src/main/resources/custom-config-sources/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
plugins { | ||
id 'java' | ||
id 'io.quarkus' | ||
} | ||
|
||
repositories { | ||
mavenLocal { | ||
content { | ||
includeGroupByRegex 'io.quarkus.*' | ||
} | ||
} | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}") | ||
implementation "io.quarkus:quarkus-grpc" // Need a `CodeGenProvider` on the class path for this test! | ||
compileOnly "io.smallrye.config:smallrye-config-core" | ||
} | ||
|
||
compileJava { | ||
options.compilerArgs << '-parameters' | ||
} |
2 changes: 2 additions & 0 deletions
2
integration-tests/gradle/src/main/resources/custom-config-sources/gradle.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
quarkusPlatformArtifactId=quarkus-bom | ||
quarkusPlatformGroupId=io.quarkus |
15 changes: 15 additions & 0 deletions
15
integration-tests/gradle/src/main/resources/custom-config-sources/settings.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
pluginManagement { | ||
repositories { | ||
mavenLocal { | ||
content { | ||
includeGroupByRegex 'io.quarkus.*' | ||
} | ||
} | ||
mavenCentral() | ||
gradlePluginPortal() | ||
} | ||
plugins { | ||
id 'io.quarkus' version "${quarkusPluginVersion}" | ||
} | ||
} | ||
rootProject.name='custom-config-sources' |
35 changes: 35 additions & 0 deletions
35
...src/main/resources/custom-config-sources/src/main/java/org/acme/InMemoryConfigSource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.acme; | ||
|
||
import org.eclipse.microprofile.config.spi.ConfigSource; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class InMemoryConfigSource implements ConfigSource { | ||
private static final Map<String, String> configuration = new HashMap<>(); | ||
|
||
static { | ||
configuration.put("my.prop", "1234"); | ||
} | ||
|
||
@Override | ||
public int getOrdinal() { | ||
return 275; | ||
} | ||
|
||
@Override | ||
public Set<String> getPropertyNames() { | ||
return configuration.keySet(); | ||
} | ||
|
||
@Override | ||
public String getValue(final String propertyName) { | ||
return configuration.get(propertyName); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return InMemoryConfigSource.class.getSimpleName(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...rc/main/resources/custom-config-sources/src/main/java/org/acme/MyConfigSourceFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.acme; | ||
|
||
import io.smallrye.config.ConfigSourceContext; | ||
import io.smallrye.config.ConfigSourceFactory; | ||
import org.eclipse.microprofile.config.spi.ConfigSource; | ||
|
||
import java.util.List; | ||
|
||
public class MyConfigSourceFactory implements ConfigSourceFactory { | ||
@Override | ||
public Iterable<ConfigSource> getConfigSources(ConfigSourceContext context) { | ||
return List.of(new InMemoryConfigSource()); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...onfig-sources/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceFactory
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.acme.MyConfigSourceFactory |
1 change: 1 addition & 0 deletions
1
...ces/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
org.acme.InMemoryConfigSource |
1 change: 1 addition & 0 deletions
1
...gradle/src/main/resources/custom-config-sources/src/main/resources/application.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Need an empty application.properties to trigger config loading mandatory for CustomConfigSourcesTest |
19 changes: 19 additions & 0 deletions
19
integration-tests/gradle/src/test/java/io/quarkus/gradle/CustomConfigSourcesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.quarkus.gradle; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class CustomConfigSourcesTest extends QuarkusGradleWrapperTestBase { | ||
|
||
@Test | ||
public void testCustomConfigSources() throws Exception { | ||
var projectDir = getProjectDir("custom-config-sources"); | ||
|
||
// The test is successful, if the build works, see https://github.com/quarkusio/quarkus/issues/36716 | ||
runGradleWrapper(projectDir, "clean", "build", "--no-build-cache"); | ||
|
||
var p = projectDir.toPath().resolve("build").resolve("quarkus-app").resolve("quarkus-run.jar"); | ||
assertThat(p).exists(); | ||
} | ||
} |