You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Disable toolchain detection by default
With the changes coming in GraalVM regarding versioning, in particular
the fact that the GraalVM version becomes internal and that the
vendor string is changing, toolchain detection will clearly be broken
for all users.
This commit therefore disables toolchain detection by default, and
makes sure to document properly the new behavior.
* Apply suggestions from code review
Co-authored-by: Fabio Niephaus <code@fniephaus.com>
---------
Co-authored-by: Fabio Niephaus <code@fniephaus.com>
The plugin relies on Gradle's https://docs.gradle.org/7.1.1/userguide/toolchains.html[JVM toolchain support], allowing to decorrelate the tool used to run Gradle, the compiler used to build your application, and eventually the SDK used to generate a native image.
95
-
96
-
In practice, it means that this plugin will try to locate a suitable installation of GraalVM for you, even if you don't run Gradle itself with GraalVM.
97
-
For this, it will look into conventional places on your machine, including from installations done by popular tools like https://sdkman.io/[SDKMAN!] or https://github.com/shyiko/jabba[Jabba].
98
-
99
-
WARNING: Even if you have a GraalVM SDK installed, Gradle will _not_ automatically detect if `native-image` is also installed.
100
-
Therefore, you will need to make sure that you have executed `gu install native-image` as indicated in the <<graalvm-setup.adoc#,setup instructions>>.
101
-
102
-
If Gradle cannot find a GraalVM installation on the machine, it will fail with an error like this:
103
-
104
-
----
105
-
> No compatible toolchains found for request filter: {languageVersion=11, vendor=matching('GraalVM'), implementation=vendor-specific} (auto-detect true, auto-download true)
106
-
----
107
-
108
-
This happens because there's no automatic provisioning of the GraalVM toolchain available yet, so you will have to install it first.
109
-
Follow the <<graalvm-setup.adoc#,following instructions>> to install it properly.
94
+
By default, the plugin will try to use the `native-image` tool that is bundled with the JDK that is used to run Gradle.
95
+
This means you must make sure that you run Gradle with a GraalVM JDK.
3. Set up a `GRAALVM_HOME` environment variable pointing to your GraalVM installation
116
-
117
-
Note that none of the above options is recommended as they are more fragile.
99
+
1. Set up a `GRAALVM_HOME` environment variable pointing to your GraalVM installation, in which case the JDK pointed at this location will be used for Native Image builds instead
100
+
2. <<configuration-toolchains-enabling, Enable toolchain support to automatically>>
118
101
119
102
[[configuration]]
120
103
== Configuration
@@ -139,44 +122,49 @@ The main executable is configured by the image named `main`, while the test exec
139
122
The link:javadocs/native-gradle-plugin/org/graalvm/buildtools/gradle/dsl/NativeImageOptions.html[NativeImageOptions] allows you to tweak how the native image is going to be built.
140
123
141
124
[[configuration-toolchains]]
142
-
==== Selecting the GraalVM toolchain
125
+
=== Using Gradle toolchains
143
126
144
-
By default, the plugin will select a Java 11 GraalVM toolchain.
145
-
If you want to use a different toolchain, for example a GraalVM Community Edition for Java 8, you can configure the toolchain like this:
127
+
[[configuration-toolchains-enabling]]
128
+
==== Enabling toolchain detection
146
129
147
-
.Selecting the GraalVM toolchain
148
-
[source, groovy, role="multi-language-sample"]
130
+
Instead of relying on the JDK which is used to run Gradle, you can use the https://docs.gradle.org/current/userguide/toolchains.html[Gradle toolchain support] to select a specific GraalVM installation.
131
+
132
+
However, because of limitations in Gradle, the plugin may not be able to properly detect the toolchain.
133
+
In particular, this will only work properly if you _only_ have GraalVM JDKs installed on the machine: **Otherwise, Gradle will not be able to reliably detect GraalVM JDKs**, nor detect GraalVM distributions from different vendors.
134
+
135
+
Should you still want to enable toolchain support, you do it via the `graalvmNative` extension:
If you do this, the plugin will search for 2 environment variables: `GRAALVM_HOME` and `JAVA_HOME` _in that order_.
178
-
If one of them is set, it will assume that it points to a valid GraalVM installation and completely bypass toolchain selection.
179
-
Therefore, it becomes your responsibility to make sure that the environment variable points to a JDK that is compatible with your build script requirements (in particular, the language version).
167
+
Again, be aware that the toolchain detection _cannot_ distinguish between GraalVM JDKs and standard JDKs without Native Image support: if you have both installed on the machine, Gradle may randomly pick one or the other.
Copy file name to clipboardExpand all lines: native-gradle-plugin/src/functionalTest/groovy/org/graalvm/buildtools/gradle/NativeImageOptionsTest.groovy
+2
Original file line number
Diff line number
Diff line change
@@ -29,6 +29,8 @@ class NativeImageOptionsTest extends Specification {
0 commit comments