Skip to content

Commit

Permalink
Merge pull request #37021 from aloubyansky/gradle-pass-sys-props-to-w…
Browse files Browse the repository at this point in the history
…orker

Gradle: set all discovered quarkus.* properties as system properties in QuarkusWorker
  • Loading branch information
aloubyansky authored Nov 13, 2023
2 parents 27f27e9 + bfdc329 commit ff547e9
Show file tree
Hide file tree
Showing 23 changed files with 385 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
import io.quarkus.utilities.OS;

public abstract class QuarkusTask extends DefaultTask {
private static final List<String> WORKER_BUILD_FORK_OPTIONS = List.of("quarkus.package.",
"quarkus.application.", "quarkus.gradle-worker.", "quarkus.analytics.");
private static final List<String> WORKER_BUILD_FORK_OPTIONS = List.of("quarkus.");

private final transient QuarkusPluginExtension extension;
protected final File projectDir;
Expand Down Expand Up @@ -89,7 +88,7 @@ private void configureProcessWorkerSpec(ProcessWorkerSpec processWorkerSpec, Map
}

// It's kind of a "very big hammer" here, but this way we ensure that all necessary properties
// ("quarkus.package.*","quarkus.application,*", "quarkus.gradle-worker.*") from all configuration sources
// "quarkus.*" from all configuration sources
// are (forcefully) used in the Quarkus build - even properties defined on the QuarkusPluginExtension.
// This prevents that settings from e.g. a application.properties takes precedence over an explicit
// setting in Gradle project properties, the Quarkus extension or even via the environment or system
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
plugins{
id "java"
id "io.quarkus"
}



group 'io.quarkus.test.application'
version '1.0-SNAPSHOT'


repositories {
mavenLocal()
mavenCentral()
}

dependencies {
implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
implementation 'io.quarkus:quarkus-resteasy-reactive'
implementation ('org.acme.extensions:example-extension')

testImplementation 'io.quarkus:quarkus-junit5'
testImplementation 'io.rest-assured:rest-assured'
}

test {
useJUnitPlatform()
}

quarkusIntTest {
environment "MY_RT_NAME", "genadiy"
}
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,20 @@
pluginManagement {
repositories {
mavenLocal {
content {
includeGroupByRegex 'io.quarkus.*'
}
}
mavenCentral()
gradlePluginPortal()
}
//noinspection GroovyAssignabilityCheck
plugins {
id 'io.quarkus' version "${quarkusPluginVersion}"
}
}

includeBuild('../extensions/example-extension'){

}
rootProject.name='application'
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.acme;

import io.quarkus.test.junit.QuarkusIntegrationTest;
import org.junit.jupiter.api.Test;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.is;

@QuarkusIntegrationTest
public class ExampleResourceIT {

@Test
public void testHelloEndpoint() {
given()
.when().get("/hello")
.then()
.statusCode(200)
.body(is("hello cheburashka"));
}

@Test
public void testRuntimeName() {
given()
.when().get("/hello/runtime-name")
.then()
.statusCode(200)
.body(is("genadiy"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.acme.quarkus.sample;

import jakarta.inject.Inject;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

import org.acme.example.extension.runtime.ExampleBuildOptions;
import org.acme.example.extension.runtime.ExampleRuntimeConfig;

@Path("/hello")
public class HelloResource {

@Inject
ExampleBuildOptions buildOptions;

@Inject
ExampleRuntimeConfig rtConfig;

@GET
@Produces(MediaType.TEXT_PLAIN)
public String hello() {
return "hello " + buildOptions.name;
}

@GET
@Produces(MediaType.TEXT_PLAIN)
@Path("/runtime-name")
public String runtimeName() {
return rtConfig.runtimeName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
quarkus.example.runtime-name=${MY_RT_NAME:none}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
plugins{
id 'java-library'
id 'maven-publish'
}
subprojects {subProject->
apply plugin: 'java-library'
apply plugin: 'maven-publish'

group 'org.acme.extensions'
version '1.0-SNAPSHOT'
publishing {
publications {
maven(MavenPublication) {
groupId = 'org.acme.extensions'
artifactId = subProject.name
version = '1.0-SNAPSHOT'
from components.java
}
}
}
}

publishing {
publications {
maven(MavenPublication) {
groupId = 'org.acme.extensions'
artifactId = rootProject.name
version = '1.0-SNAPSHOT'
from components.java
}
}
}
group 'org.acme.extensions'
version '1.0-SNAPSHOT'
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
plugins {
id 'java'
id 'java-library'
}
repositories {
mavenLocal()
mavenCentral()
}

dependencies {
implementation platform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
annotationProcessor "io.quarkus:quarkus-extension-processor:${quarkusPlatformVersion}"


api project(':example-extension')
implementation 'io.quarkus:quarkus-arc-deployment'
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.acme.example.extension.deployment;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigRoot;

@ConfigRoot
public class ExampleConfig {

/**
* name
*/
@ConfigItem(defaultValue = "none")
String name;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package org.acme.example.extension.deployment;

import jakarta.inject.Singleton;

import org.acme.example.extension.runtime.ExampleBuildOptions;
import org.acme.example.extension.runtime.ExampleRecorder;
import io.quarkus.arc.deployment.SyntheticBeanBuildItem;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.FeatureBuildItem;

class ExampleProcessor {

private static final String FEATURE = "example";

@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}

@BuildStep
@Record(ExecutionTime.STATIC_INIT)
SyntheticBeanBuildItem syntheticBean(ExampleRecorder recorder, ExampleConfig config) {
return SyntheticBeanBuildItem.configure(ExampleBuildOptions.class)
.scope(Singleton.class)
.runtimeValue(recorder.buildOptions(config.name))
.done();
}
}
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,20 @@

plugins {
id 'io.quarkus.extension'
}

quarkusExtension {
deploymentModule = 'example-extension-deployment'
}

repositories {
mavenLocal()
mavenCentral()
}

dependencies {
implementation platform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
annotationProcessor "io.quarkus:quarkus-extension-processor:${quarkusPlatformVersion}"
implementation 'io.quarkus:quarkus-arc'
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.acme.example.extension.runtime;

public class ExampleBuildOptions {

public final String name;

public ExampleBuildOptions(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.acme.example.extension.runtime;

import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.annotations.Recorder;

@Recorder
public class ExampleRecorder {

public RuntimeValue<ExampleBuildOptions> buildOptions(String name) {
System.out.println("ExampleRecorder.buildOptions " + name);
return new RuntimeValue<>(new ExampleBuildOptions(name));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.acme.example.extension.runtime;

import io.quarkus.runtime.annotations.ConfigItem;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;

@ConfigRoot(phase = ConfigPhase.RUN_TIME)
public class ExampleRuntimeConfig {

/**
* Whether the banner will be displayed
*/
@ConfigItem(defaultValue = "none")
public String runtimeName;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
deployment-artifact=org.acme.extensions\:example-extension-deployment\:1.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
name: Quarkus Example Extension
artifact: ${project.groupId}:${project.artifactId}:${project.version}
metadata:
config:
- "quarkus.example.extension."
keywords:
- "logzio"
- "logging"
categories:
- "logging"
description: "Quarkus example extension"
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
pluginManagement {
repositories {
gradlePluginPortal()
mavenLocal()
}
plugins {
id 'io.quarkus.extension' version "${quarkusPluginVersion}"
}
}
dependencyResolutionManagement {
repositories {
mavenLocal()
mavenCentral()
}

}
rootProject.name = 'example-extension-parent'
include(':deployment')
include(':runtime')
project(':deployment').name='example-extension-deployment'
project(':runtime').name='example-extension'
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,18 @@
pluginManagement {
repositories {
mavenLocal {
content {
includeGroupByRegex 'io.quarkus.*'
}
}
mavenCentral()
gradlePluginPortal()
}
//noinspection GroovyAssignabilityCheck
plugins {
id 'io.quarkus' version "${quarkusPluginVersion}"
}
}

includeBuild('extensions/example-extension')
includeBuild('application')
Loading

0 comments on commit ff547e9

Please sign in to comment.