diff --git a/devtools/gradle/src/main/java/io/quarkus/gradle/QuarkusPlugin.java b/devtools/gradle/src/main/java/io/quarkus/gradle/QuarkusPlugin.java index e85e8d7f4bab0..109d1bfdf1b34 100644 --- a/devtools/gradle/src/main/java/io/quarkus/gradle/QuarkusPlugin.java +++ b/devtools/gradle/src/main/java/io/quarkus/gradle/QuarkusPlugin.java @@ -39,6 +39,8 @@ public class QuarkusPlugin implements Plugin { public static final String QUARKUS_BUILD_TASK_NAME = "quarkusBuild"; public static final String GENERATE_CONFIG_TASK_NAME = "generateConfig"; public static final String QUARKUS_DEV_TASK_NAME = "quarkusDev"; + + @Deprecated public static final String BUILD_NATIVE_TASK_NAME = "buildNative"; public static final String TEST_NATIVE_TASK_NAME = "testNative"; public static final String QUARKUS_TEST_CONFIG_TASK_NAME = "quarkusTestConfig"; @@ -111,9 +113,14 @@ private void registerTasks(Project project) { .extendsFrom(configurations.findByName(JavaPlugin.TEST_RUNTIME_ONLY_CONFIGURATION_NAME)); Task testNative = tasks.create(TEST_NATIVE_TASK_NAME, QuarkusTestNative.class); - testNative.dependsOn(buildNative); + testNative.dependsOn(quarkusBuild); testNative.setShouldRunAfter(Collections.singletonList(tasks.findByName(JavaPlugin.TEST_TASK_NAME))); + Consumer configureTestNativeTask = t -> project.getExtensions().getExtraProperties() + .set("quarkus.package.type", "native"); + tasks.withType(QuarkusTestNative.class).forEach(configureTestNativeTask); + tasks.withType(QuarkusTestNative.class).whenTaskAdded(configureTestNativeTask::accept); + Consumer configureTestTask = t -> { // Quarkus test configuration task which should be executed before any Quarkus test t.dependsOn(quarkusTestConfig); diff --git a/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusNative.java b/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusNative.java index 58bbd3c6c28f5..71213e332b357 100644 --- a/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusNative.java +++ b/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusNative.java @@ -22,6 +22,14 @@ import io.quarkus.bootstrap.resolver.AppModelResolver; import io.quarkus.bootstrap.resolver.AppModelResolverException; +/** + * Legacy task for backwards compatibility reasons. This should not be used in new projects + * + * This has been replaced by setting quarkus.package.type=native in the configuration. + * + * @deprecated + */ +@Deprecated public class QuarkusNative extends QuarkusTask { private boolean reportErrorsAtRuntime = false; @@ -353,9 +361,9 @@ public void setReportExceptionStackTraces(boolean reportExceptionStackTraces) { this.reportExceptionStackTraces = reportExceptionStackTraces; } - @TaskAction + @TaskAction() public void buildNative() { - getLogger().lifecycle("building native image"); + getLogger().warn("buildNative task is deprecated in favor of quarkusBuild -Dquarkus.package.type=native"); final AppArtifact appArtifact = extension().getAppArtifact(); final AppModelResolver modelResolver = extension().getAppModelResolver(); diff --git a/docs/src/main/asciidoc/gradle-tooling.adoc b/docs/src/main/asciidoc/gradle-tooling.adoc index 3f543ae6a06c8..78f1fff99ac9d 100644 --- a/docs/src/main/asciidoc/gradle-tooling.adoc +++ b/docs/src/main/asciidoc/gradle-tooling.adoc @@ -261,7 +261,7 @@ Native executables make Quarkus applications ideal for containers and serverless Make sure to have `GRAALVM_HOME` configured and pointing to GraalVM version {graalvm-version}. -Create a native executable using: `./gradlew buildNative`. +Create a native executable using: `./gradlew quarkusBuild -Dquarkus.package.type=native`. A native executable will be present in `build/`. === Build a container friendly executable @@ -271,18 +271,7 @@ To create an executable that will run in a container, use the following: [source,shell] ---- -./gradlew buildNative ----- - -==== Customize the build native task - -There are situations where it may be required to alter the default values of the `buildNative` task (whose implementation can be found link:https://github.com/quarkusio/quarkus/blob/master/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusNative.java[here]). - -The easiest way to supply custom configuration is via the command line. For example to use docker to build the native image, simply add the `--docker-build=true` flag like so: - -[source,shell] ----- -./gradlew buildNative --docker-build=true +./gradlew quarkusBuild -Dquarkus.package.type=native -Dquarkus.native.container-build=true ---- The produced executable will be a 64 bit Linux executable, so depending on your operating system it may no longer be runnable. @@ -300,35 +289,6 @@ The list of the available Docker images can be found on https://quay.io/reposito Be aware that a given Quarkus version might not be compatible with all the images available. ==== -Another way of customizing the native build image build process is to configure the task inside the Gradle build script. If for example it is required to set the `enableHttpUrlHandler`, it can be done like so: - -[source,groovy] ----- -buildNative { - enableHttpUrlHandler = true -} ----- - -or, if you use the Gradle Kotlin DSL: - -[source,kotlin,subs=attributes+] ----- -tasks { - named("buildNative") { - setEnableHttpUrlHandler(true) - } -} ----- - - -The native executable would then be produced by executing: - -[source,shell] ----- -./gradlew buildNative ----- - - == Running native tests Run the native tests using: @@ -338,7 +298,7 @@ Run the native tests using: ./gradlew testNative ---- -This task depends on `buildNative`, so it will generate the native image before running the tests. +This task depends on `quarkusBuild`, so it will generate the native image before running the tests. == Building Uber-Jars @@ -360,4 +320,4 @@ The entries are relative to the root of the generated Uber-Jar. You can specify == Building with `./gradlew build` -Starting from 1.1.0.Final, `./gradlew build` will no longer build the native image. Use the `buildNative` task explicitly as explained above if needed. +Starting from 1.1.0.Final, `./gradlew build` will no longer build the native image. Use the `quarkusBuild -Dquarkus.package.type=native` task explicitly as explained above if needed.