Skip to content

Commit

Permalink
deprecate buildNative gradle task
Browse files Browse the repository at this point in the history
  • Loading branch information
glefloch committed Apr 1, 2020
1 parent a327a4b commit 13cbe9f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public class QuarkusPlugin implements Plugin<Project> {
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";
Expand Down Expand Up @@ -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<QuarkusTestNative> configureTestNativeTask = t -> project.getExtensions().getExtraProperties()
.set("quarkus.package.type", "native");
tasks.withType(QuarkusTestNative.class).forEach(configureTestNativeTask);
tasks.withType(QuarkusTestNative.class).whenTaskAdded(configureTestNativeTask::accept);

Consumer<Test> configureTestTask = t -> {
// Quarkus test configuration task which should be executed before any Quarkus test
t.dependsOn(quarkusTestConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
48 changes: 4 additions & 44 deletions docs/src/main/asciidoc/gradle-tooling.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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<QuarkusNative>("buildNative") {
setEnableHttpUrlHandler(true)
}
}
----


The native executable would then be produced by executing:

[source,shell]
----
./gradlew buildNative
----


== Running native tests

Run the native tests using:
Expand All @@ -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

Expand All @@ -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.

0 comments on commit 13cbe9f

Please sign in to comment.