diff --git a/gradle/projects.main.properties b/gradle/projects.main.properties index 468cbdf75..b2f241463 100644 --- a/gradle/projects.main.properties +++ b/gradle/projects.main.properties @@ -27,6 +27,7 @@ polaris-quarkus-defaults=quarkus/defaults polaris-quarkus-service=quarkus/service polaris-quarkus-server=quarkus/server polaris-quarkus-admin=quarkus/admin +polaris-quarkus-run-script=quarkus/run-script polaris-eclipselink=extension/persistence/eclipselink polaris-jpa-model=extension/persistence/jpa-model polaris-tests=integration-tests diff --git a/quarkus/admin/build.gradle.kts b/quarkus/admin/build.gradle.kts index 0d11b0c70..cbad25e10 100644 --- a/quarkus/admin/build.gradle.kts +++ b/quarkus/admin/build.gradle.kts @@ -28,6 +28,14 @@ plugins { id("distribution") } +val runScript by configurations.creating { description = "Used to reference the run.sh script" } + +val distributionZip by + configurations.creating { description = "Used to reference the distribution zip" } + +val distributionTar by + configurations.creating { description = "Used to reference the distribution tarball" } + dependencies { implementation(project(":polaris-core")) implementation(project(":polaris-version")) @@ -53,10 +61,12 @@ dependencies { testRuntimeOnly(project(":polaris-eclipselink")) testRuntimeOnly("org.postgresql:postgresql") + + runScript(project(":polaris-quarkus-run-script", "runScript")) } quarkus { - quarkusBuildProperties.put("quarkus.package.type", "uber-jar") + quarkusBuildProperties.put("quarkus.package.type", "fast-jar") // Pull manifest attributes from the "main" `jar` task to get the // release-information into the jars generated by Quarkus. quarkusBuildProperties.putAll( @@ -72,28 +82,48 @@ quarkus { ) } -publishing { - publications { - named("maven") { - val quarkusBuild = tasks.getByName("quarkusBuild") - artifact(quarkusBuild.runnerJar) { - classifier = "runner" - builtBy(quarkusBuild) - } +distributions { + main { + contents { + from(runScript) + from(project.layout.buildDirectory.dir("quarkus-app")) + from("../../NOTICE") + from("../../LICENSE-BINARY-DIST").rename("LICENSE-BINARY-DIST", "LICENSE") } } } -tasks.named("distZip") { dependsOn("quarkusBuild") } +val quarkusBuild = tasks.named("quarkusBuild") -tasks.named("distTar") { dependsOn("quarkusBuild") } +val distTar = + tasks.named("distTar") { + dependsOn(quarkusBuild) + // Trigger resolution (and build) of the run-script artifact + inputs.files(runScript) + compression = Compression.GZIP + } -distributions { - main { - contents { - from("../../NOTICE") - from("../../LICENSE-BINARY-DIST").rename("LICENSE-BINARY-DIST", "LICENSE") - from(project.layout.buildDirectory) { include("polaris-quarkus-admin-*-runner.jar") } +val distZip = + tasks.named("distZip") { + dependsOn(quarkusBuild) + // Trigger resolution (and build) of the run-script artifact + inputs.files(runScript) + } + +// Expose runnable jar via quarkusRunner configuration for integration-tests that require the +// server. +artifacts { + add(distributionTar.name, provider { distTar.get().archiveFile }) { builtBy(distTar) } + add(distributionZip.name, provider { distZip.get().archiveFile }) { builtBy(distZip) } +} + +afterEvaluate { + publishing { + publications { + named("maven") { + artifact(distTar.get().archiveFile) { builtBy(distTar) } + artifact(distZip.get().archiveFile) { builtBy(distZip) } + } } } } diff --git a/quarkus/run-script/build.gradle.kts b/quarkus/run-script/build.gradle.kts new file mode 100644 index 000000000..315e88edd --- /dev/null +++ b/quarkus/run-script/build.gradle.kts @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +val runScript by + configurations.creating { description = "Used to provide the run.sh script" } + +description = "Provides run.sh script for Quarkus fast-jar for distribution tar/zip" + +// This is a separate project that only provides run scripts (run.sh). +// It is a separate project, because it is not good practice to directly +// reference files outside any project. +// +// Artifacts are NOT published as a Maven artifacts. + +artifacts { + add(runScript.name, project.layout.projectDirectory.file("scripts/run.sh")) +} + +// Need this task to be present, there are no checks/tests in this project though +tasks.register("check") diff --git a/quarkus/run-script/scripts/run.sh b/quarkus/run-script/scripts/run.sh new file mode 100755 index 000000000..1cea71574 --- /dev/null +++ b/quarkus/run-script/scripts/run.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +# Linux Quarkus fast-jar run script for Apache Polaris + +set -e + +script_dir="$(dirname "$0")" + +if [ -z "$JAVA_HOME" ] ; then + JAVACMD="`\\unset -f command; \\command -v java`" +else + JAVACMD="$JAVA_HOME/bin/java" +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "The JAVA_HOME environment variable is not defined correctly," >&2 + echo "this environment variable is needed to run this program." >&2 + exit 1 +fi + +exec "${JAVACMD}" -jar "${script_dir}/quarkus-run.jar" diff --git a/quarkus/server/build.gradle.kts b/quarkus/server/build.gradle.kts index ac19236bb..04b7030c9 100644 --- a/quarkus/server/build.gradle.kts +++ b/quarkus/server/build.gradle.kts @@ -17,6 +17,7 @@ * under the License. */ +import io.quarkus.gradle.tasks.QuarkusBuild import io.quarkus.gradle.tasks.QuarkusRun plugins { @@ -28,6 +29,17 @@ plugins { id("distribution") } +val quarkusRunner by + configurations.creating { description = "Used to reference the generated runner-jar" } + +val runScript by configurations.creating { description = "Used to reference the run.sh script" } + +val distributionZip by + configurations.creating { description = "Used to reference the distribution zip" } + +val distributionTar by + configurations.creating { description = "Used to reference the distribution tarball" } + dependencies { implementation(project(":polaris-core")) implementation(project(":polaris-api-management-service")) @@ -42,6 +54,8 @@ dependencies { // enforce the Quarkus _platform_ here, to get a consistent and validated set of dependencies implementation(enforcedPlatform(libs.quarkus.bom)) implementation("io.quarkus:quarkus-container-image-docker") + + runScript(project(":polaris-quarkus-run-script", "runScript")) } quarkus { @@ -61,10 +75,6 @@ quarkus { ) } -tasks.named("distZip") { dependsOn("quarkusBuild") } - -tasks.named("distTar") { dependsOn("quarkusBuild") } - tasks.register("run") { dependsOn("quarkusRun") } tasks.named("quarkusRun") { @@ -75,6 +85,7 @@ tasks.named("quarkusRun") { distributions { main { contents { + from(runScript) from(project.layout.buildDirectory.dir("quarkus-app")) from("../../NOTICE") from("../../LICENSE-BINARY-DIST").rename("LICENSE-BINARY-DIST", "LICENSE") @@ -82,3 +93,39 @@ distributions { } } } + +val quarkusBuild = tasks.named("quarkusBuild") + +val distTar = + tasks.named("distTar") { + dependsOn(quarkusBuild) + inputs.files(runScript) + compression = Compression.GZIP + } + +val distZip = + tasks.named("distZip") { + dependsOn(quarkusBuild) + inputs.files(runScript) + } + +// Expose runnable jar via quarkusRunner configuration for integration-tests that require the +// server. +artifacts { + add(quarkusRunner.name, provider { quarkusBuild.get().fastJar.resolve("quarkus-run.jar") }) { + builtBy(quarkusBuild) + } + add(distributionTar.name, provider { distTar.get().archiveFile }) { builtBy(distTar) } + add(distributionZip.name, provider { distZip.get().archiveFile }) { builtBy(distZip) } +} + +afterEvaluate { + publishing { + publications { + named("maven") { + artifact(distTar.get().archiveFile) { builtBy(distTar) } + artifact(distZip.get().archiveFile) { builtBy(distZip) } + } + } + } +}