Skip to content

Commit

Permalink
Merge pull request #38688 from vemilyus/respecting-maven-exclusions-i…
Browse files Browse the repository at this point in the history
…n-gradle

Making sure deployment modules excluded in POM files aren't pulled in by the Gradle plugin
  • Loading branch information
aloubyansky authored Feb 19, 2024
2 parents 4f10eec + 62483ed commit 58408af
Show file tree
Hide file tree
Showing 17 changed files with 475 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ private void registerTasks(Project project, QuarkusExtensionConfiguration quarku
Configuration runtimeModuleClasspath = project.getConfigurations()
.getByName(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME);

TaskProvider<ValidateExtensionTask> validateExtensionTask = tasks.register(VALIDATE_EXTENSION_TASK_NAME,
ValidateExtensionTask.class, quarkusExt, runtimeModuleClasspath);

TaskProvider<ExtensionDescriptorTask> extensionDescriptorTask = tasks.register(EXTENSION_DESCRIPTOR_TASK_NAME,
ExtensionDescriptorTask.class, quarkusExt, mainSourceSet, runtimeModuleClasspath);

TaskProvider<ValidateExtensionTask> validateExtensionTask = tasks.register(VALIDATE_EXTENSION_TASK_NAME,
ValidateExtensionTask.class, quarkusExt, runtimeModuleClasspath);
extensionDescriptorTask.configure(task -> task.dependsOn(validateExtensionTask));

project.getPlugins().withType(
JavaPlugin.class,
Expand Down
1 change: 1 addition & 0 deletions devtools/gradle/gradle-model/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {

dependencies {
compileOnly(libs.kotlin.gradle.plugin.api)
gradleApi()
}

group = "io.quarkus"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,6 @@ private void collectConditionalDependencies(Set<ResolvedArtifact> runtimeArtifac
queueConditionalDependency(extension, conditionalDep);
}
}

// If the extension doesn't have any conditions we just enable it by default
if (extension.getDependencyConditions().isEmpty()) {
extension.setConditional(true);
enableConditionalDependency(extension.getExtensionId());
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions devtools/gradle/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ quarkus-project-core-extension-codestarts = { module = "io.quarkus:quarkus-proje

kotlin-gradle-plugin-api = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin-api", version.ref = "kotlin" }
smallrye-config-yaml = { module = "io.smallrye.config:smallrye-config-source-yaml", version.ref = "smallrye-config" }
jackson-databind = {module="com.fasterxml.jackson.core:jackson-databind"}
jackson-dataformat-yaml = {module="com.fasterxml.jackson.dataformat:jackson-dataformat-yaml"}
jackson-databind = { module = "com.fasterxml.jackson.core:jackson-databind" }
jackson-dataformat-yaml = { module = "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml" }

junit-bom = { module = "org.junit:junit-bom", version.ref = "junit5" }
junit-api = { module = "org.junit.jupiter:junit-jupiter-api" }
Expand Down
10 changes: 5 additions & 5 deletions docs/src/main/asciidoc/writing-extensions.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,12 @@ Your extension project should be setup as a multi-module project with two submod

Your runtime artifact should depend on `io.quarkus:quarkus-core`, and possibly the runtime artifacts of other Quarkus
modules if you want to use functionality provided by them.

Your deployment time module should depend on `io.quarkus:quarkus-core-deployment`, your runtime artifact,
and possibly the deployment artifacts of other Quarkus modules if you want to use functionality provided by them.
and the deployment artifacts of any other Quarkus extensions your own extension depends on. This is essential, otherwise any transitively
pulled in extensions will not provide their full functionality.

NOTE: The Maven and Gradle plugins will validate this for you and alert you to any deployment artifacts you might have forgotten to add.

[WARNING]
====
Expand Down Expand Up @@ -573,10 +577,6 @@ dependencies {
}
----

[WARNING]
====
This plugin is still experimental, it does not validate the extension dependencies as the equivalent Maven plugin does.
====

[[build-step-processors]]
=== Build Step Processors
Expand Down
34 changes: 34 additions & 0 deletions integration-tests/gradle/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-orm-panache</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-reactive-panache</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-search-orm-elasticsearch</artifactId>
Expand Down Expand Up @@ -136,6 +140,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-kubernetes-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-reactive-pg-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
Expand Down Expand Up @@ -242,6 +250,19 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-reactive-panache-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-search-orm-elasticsearch-deployment</artifactId>
Expand Down Expand Up @@ -307,6 +328,19 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-reactive-pg-client-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-deployment</artifactId>
Expand Down
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"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
quarkusPlatformArtifactId=quarkus-bom
quarkusPlatformGroupId=io.quarkus
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'
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";
}
}
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;
}

Large diffs are not rendered by default.

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
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.
}
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"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ dependencies {


api project(':another-example-extension') // why: https://quarkus.io/guides/building-my-first-extension
implementation ('org.acme.extensions:example-extension-deployment')

implementation 'io.quarkus:quarkus-core-deployment'
implementation 'io.quarkus:quarkus-arc-deployment'
implementation ('org.acme.libs:libraryB')
Expand Down
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");
}
}

0 comments on commit 58408af

Please sign in to comment.