forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Making sure deployment modules excluded in POM files aren't pulled in…
… by the Gradle plugin This makes sure that exclusions in POM files of deployment modules are respects. Once case where this is critical is when using quarkus-hibernate-reactive. Its deployment module takes care of pulling in quarkus-hibernate-orm-deployment where it excludes Agroal and Narayana. If that exclusion isn't taken into account by the Gradle plugin, it pulls in quarkus-hibernate-orm-deployment on its own, where those other modules aren't excluded, which leads to a failure at runtime because Agroal tries to initialize and looks for a JDBC driver which isn't typically available in reactive DB scenarios. Fixes quarkusio#38533
- Loading branch information
Showing
16 changed files
with
561 additions
and
11 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
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
69 changes: 69 additions & 0 deletions
69
devtools/gradle/gradle-model/src/main/java/io/quarkus/gradle/tooling/pom/PomUtils.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,69 @@ | ||
package io.quarkus.gradle.tooling.pom; | ||
|
||
import java.io.FileReader; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.HashSet; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
import org.apache.maven.model.Dependency; | ||
import org.apache.maven.model.Model; | ||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader; | ||
import org.gradle.api.Project; | ||
import org.gradle.api.artifacts.result.ArtifactResolutionResult; | ||
import org.gradle.api.artifacts.result.ArtifactResult; | ||
import org.gradle.api.artifacts.result.ComponentArtifactsResult; | ||
import org.gradle.api.internal.artifacts.DefaultModuleIdentifier; | ||
import org.gradle.api.internal.artifacts.result.DefaultResolvedArtifactResult; | ||
import org.gradle.internal.component.external.model.DefaultModuleComponentIdentifier; | ||
import org.gradle.maven.MavenModule; | ||
import org.gradle.maven.MavenPomArtifact; | ||
|
||
import io.quarkus.maven.dependency.ArtifactCoords; | ||
|
||
public final class PomUtils { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
vemilyus
Author
Owner
|
||
public static Set<String> readDeploymentDependencies(Project project, ArtifactCoords artifactCoords) { | ||
@SuppressWarnings("unchecked") | ||
ArtifactResolutionResult resolutionResult = project | ||
.getDependencies().createArtifactResolutionQuery() | ||
.forComponents( | ||
new DefaultModuleComponentIdentifier( | ||
DefaultModuleIdentifier.newId( | ||
artifactCoords.getGroupId(), | ||
artifactCoords.getArtifactId()), | ||
artifactCoords.getVersion())) | ||
.withArtifacts(MavenModule.class, MavenPomArtifact.class) | ||
.execute(); | ||
|
||
MavenXpp3Reader pomReader = new MavenXpp3Reader(); | ||
|
||
final Set<String> results = new HashSet<>(); | ||
|
||
for (ComponentArtifactsResult resolvedComponent : resolutionResult.getResolvedComponents()) { | ||
for (ArtifactResult artifact : resolvedComponent.getArtifacts(MavenPomArtifact.class)) { | ||
if (artifact instanceof DefaultResolvedArtifactResult) { | ||
DefaultResolvedArtifactResult resolvedArtifact = (DefaultResolvedArtifactResult) artifact; | ||
|
||
Model pom; | ||
try (FileReader fr = new FileReader(resolvedArtifact.getFile(), StandardCharsets.UTF_8)) { | ||
pom = pomReader.read(fr); | ||
} catch (Exception e) { | ||
project.getLogger().warn("Failed to read pom.xml for " + resolvedArtifact, e); | ||
continue; | ||
} | ||
|
||
for (Dependency pomDependency : pom.getDependencies()) { | ||
if (!Objects.equals("test", pomDependency.getScope())) { | ||
results.add(pomDependency.getGroupId() + ":" + pomDependency.getArtifactId()); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
return results; | ||
} | ||
|
||
private PomUtils() { | ||
} | ||
} |
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
32 changes: 32 additions & 0 deletions
32
...tion-tests/gradle/src/main/resources/maven-exclusion-in-extension-dependency/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,32 @@ | ||
plugins { | ||
id 'java' | ||
id 'io.quarkus' | ||
} | ||
|
||
repositories { | ||
mavenLocal { | ||
content { | ||
includeGroupByRegex 'io.quarkus.*' | ||
includeGroup 'org.hibernate.orm' | ||
} | ||
} | ||
mavenCentral() | ||
} | ||
|
||
dependencies { | ||
implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}") | ||
implementation 'io.quarkus:quarkus-resteasy-reactive-jackson' | ||
implementation 'io.quarkus:quarkus-hibernate-reactive-panache' | ||
implementation 'io.quarkus:quarkus-reactive-pg-client' | ||
implementation 'io.quarkus:quarkus-arc' | ||
implementation 'io.quarkus:quarkus-resteasy-reactive' | ||
testImplementation 'io.quarkus:quarkus-junit5' | ||
testImplementation 'io.rest-assured:rest-assured' | ||
} | ||
|
||
group 'org.acme' | ||
version '1.0.0-SNAPSHOT' | ||
|
||
test { | ||
systemProperty "java.util.logging.manager", "org.jboss.logmanager.LogManager" | ||
} |
2 changes: 2 additions & 0 deletions
2
...tests/gradle/src/main/resources/maven-exclusion-in-extension-dependency/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 |
17 changes: 17 additions & 0 deletions
17
...n-tests/gradle/src/main/resources/maven-exclusion-in-extension-dependency/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,17 @@ | ||
pluginManagement { | ||
repositories { | ||
mavenLocal { | ||
content { | ||
includeGroupByRegex 'io.quarkus.*' | ||
includeGroup 'org.hibernate.orm' | ||
} | ||
} | ||
mavenCentral() | ||
gradlePluginPortal() | ||
} | ||
plugins { | ||
id 'io.quarkus' version "${quarkusPluginVersion}" | ||
} | ||
} | ||
|
||
rootProject.name='code-with-quarkus' |
16 changes: 16 additions & 0 deletions
16
...rces/maven-exclusion-in-extension-dependency/src/main/java/org/acme/GreetingResource.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,16 @@ | ||
package org.acme; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.MediaType; | ||
|
||
@Path("/hello") | ||
public class GreetingResource { | ||
|
||
@GET | ||
@Produces(MediaType.TEXT_PLAIN) | ||
public String hello() { | ||
return "Hello from RESTEasy Reactive"; | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...in/resources/maven-exclusion-in-extension-dependency/src/main/java/org/acme/MyEntity.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 jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.Id; | ||
import java.util.UUID; | ||
|
||
@Entity | ||
public class MyEntity { | ||
@Id | ||
@GeneratedValue | ||
private UUID id; | ||
} |
285 changes: 285 additions & 0 deletions
285
.../maven-exclusion-in-extension-dependency/src/main/resources/META-INF/resources/index.html
Large diffs are not rendered by default.
Oops, something went wrong.
5 changes: 5 additions & 0 deletions
5
...sources/maven-exclusion-in-extension-dependency/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,5 @@ | ||
quarkus.datasource.db-kind = postgresql | ||
quarkus.datasource.username = quarkus_test | ||
quarkus.datasource.password = quarkus_test | ||
quarkus.datasource.reactive.url = vertx-reactive:postgresql://localhost:5432/quarkus_test | ||
#quarkus.datasource.jdbc=false |
8 changes: 8 additions & 0 deletions
8
...n-exclusion-in-extension-dependency/src/native-test/java/org/acme/GreetingResourceIT.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,8 @@ | ||
package org.acme; | ||
|
||
import io.quarkus.test.junit.QuarkusIntegrationTest; | ||
|
||
@QuarkusIntegrationTest | ||
class GreetingResourceIT extends GreetingResourceTest { | ||
// Execute the same tests but in packaged mode. | ||
} |
21 changes: 21 additions & 0 deletions
21
.../maven-exclusion-in-extension-dependency/src/test/java/org/acme/GreetingResourceTest.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,21 @@ | ||
package org.acme; | ||
|
||
import static io.restassured.RestAssured.given; | ||
import static org.hamcrest.CoreMatchers.is; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.test.junit.QuarkusTest; | ||
|
||
@QuarkusTest | ||
class GreetingResourceTest { | ||
@Test | ||
void testHelloEndpoint() { | ||
given() | ||
.when().get("/hello") | ||
.then() | ||
.statusCode(200) | ||
.body(is("Hello from RESTEasy Reactive")); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...c/test/java/io/quarkus/gradle/devmode/MavenExclusionInExtensionDependencyDevModeTest.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,27 @@ | ||
package io.quarkus.gradle.devmode; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
/** | ||
* This makes sure that exclusions in POM files of deployment modules are respected. | ||
* <p> | ||
* One case where this is critical is when using quarkus-hibernate-reactive. Its deployment | ||
* module takes care of pulling in quarkus-hibernate-orm-deployment where it excludes | ||
* Agroal and Narayana. | ||
* <p> | ||
* If that exclusion isn't taken into account by the Gradle plugin, it pulls in | ||
* quarkus-hibernate-orm-deployment on its own, where those other modules aren't excluded, | ||
* which leads to a failure at runtime because Agroal tries to initialize and looks | ||
* for a JDBC driver which isn't typically available in reactive DB scenarios. | ||
*/ | ||
public class MavenExclusionInExtensionDependencyDevModeTest extends QuarkusDevGradleTestBase { | ||
@Override | ||
protected String projectDirectoryName() { | ||
return "maven-exclusion-in-extension-dependency"; | ||
} | ||
|
||
@Override | ||
protected void testDevMode() throws Exception { | ||
assertThat(getHttpResponse("/hello")).contains("Hello"); | ||
} | ||
} |
Oh, is this really necessary?
One point to keep in mind is that, when we resolve deployment dependencies, we need to resolve only the top level one deployment artifact. So in that issue we are fixing, it'll be
quarkus-hibernate-reactive-deployment
. It will already resolve its dependencies with the exclusions applied.Then we "simply" replace the
quarkus-hibernate-reactive
withquarkus-hibernate-reactive-deployment
and its dependencies (wherequarkus-hibernate-reactive
is also present) to create the Quarkus build classpath.However, when we resolve
quarkus-hibernate-reactive-deployment
we should apply exclusions from the dependencies that appear higher in the hierarchy, e.g. ifquarkus-hibernate-reactive
was a dependency ofacme-lib
andmy-app
had a dependency onacme-lib
withquarkus-hibernate-reactive
pulled in as its transitive dependency. So, ifmy-app
configured dependency exclusions onacme-lib
dependency, those exclusions that should also apply when we resolve dependencies ofquarkus-hibernate-reactive-deployment
.