Skip to content

Commit ac68bce

Browse files
Fixing tests and docs
1 parent 1a90901 commit ac68bce

File tree

23 files changed

+362
-87
lines changed

23 files changed

+362
-87
lines changed

.github/workflows/test-native-gradle-plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
strategy:
5454
fail-fast: false
5555
matrix:
56-
gradle-version: ["current", "7.3.3", "7.2", "7.1", "6.8.3","6.7.1"]
56+
gradle-version: ["current", "7.3.3", "6.7.1"]
5757
graalvm-version: [ dev ]
5858
java-version: [ 11 ]
5959
os: [ ubuntu-20.04 ]

docs/src/docs/asciidoc/gradle-plugin.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ include::../snippets/gradle/kotlin/settings.gradle.kts[tags=pre-release, indent=
6767
----
6868
====
6969

70-
=== Installing GraalVM native image tool
70+
=== Installing GraalVM Native Image tool
7171

7272
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.
7373

docs/src/docs/asciidoc/index.adoc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@ If you are interested in contributing, please refer to our https://github.com/gr
2323
* Introduced the `metadataCopy` task.
2424
* Introduced the concept of agent modes.
2525
** Under the hood, the agent mode dictates what options are passed to the agent and how metadata produced by multiple runs get merged.
26-
* Added `excludeConfig` configuration option that allows skipping of configuration files that are present in classpath `jar` s.
26+
* Added `excludeConfig` configuration option that allows skipping of configuration files that are present in dependencies.
2727
* `useArgFile` is now set to true by default only on Windows.
28+
* Added `quickBuild` configuration option.
2829

2930
==== Maven plugin
3031
* Completely reworked Maven plugin (should fix many of previous issues and inconsistencies between main and test builds).
31-
* Added `classesDirectory`, `debug`, `fallback`, `verbose`, `sharedLibrary`, `configurationFileDirectories`, `excludeConfig` and `jvmArgs` properties in order to match those present in the Gradle plugin.
32+
* Added `classesDirectory`, `debug`, `fallback`, `verbose`, `sharedLibrary`, `configurationFileDirectories`, `excludeConfig`, `quickBuild`, and `jvmArgs` properties in order to match those present in the Gradle plugin. +
33+
+
34+
See <<maven-plugin.adoc#,docs>> for more information.
3235
* `useArgFile` is now set to true by default only on Windows.
36+
* Changed lookup order for `native-image` discovery -- `GRAALVM_HOME`, `JAVA_HOME`, `PATH`.
3337

3438
=== Release 0.9.11
3539

docs/src/docs/asciidoc/maven-plugin.adoc

Lines changed: 119 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,118 @@ Build Configuration]. It is also possible to customize the plugin within a
114114
image name is not supplied, the artifact ID of the project will be used by default.
115115
`<buildArgs>`::
116116
If you want to pass additional arguments to the native image builder, use `<buildArgs>`
117-
in the configuration of the plugin.
117+
in the configuration of the plugin:
118+
[source,xml]
119+
----
120+
<buildArgs>
121+
<arg>--argument</arg>
122+
</buildArgs>
123+
----
118124
`<skipNativeBuild>`::
119-
To skip generation of the native image, supply
120-
`<skipNativeBuild>true</skipNativeBuild>` in the configuration of the plugin.
125+
To skip generation of the native image, supply the following in the configuration of the plugin:
126+
[source,xml]
127+
----
128+
<skipNativeBuild>true</skipNativeBuild>
129+
----
130+
`<skipNativeTests>`::
131+
To skip generation and execution of the native image compiled tests, supply the following in the configuration of the plugin:
132+
[source,xml]
133+
----
134+
<skipNativeTests>true</skipNativeTests>
135+
----
136+
`<debug>`::
137+
If you want to enable generation of debugging information supply the following in the configuration of the plugin:
138+
[source,xml]
139+
----
140+
<debug>true</debug>
141+
----
142+
`<verbose>`::
143+
If you want to enable verbose output during native-image building supply the following in the configuration of the plugin:
144+
[source,xml]
145+
----
146+
<verbose>true</verbose>
147+
----
148+
`<sharedLibrary>`::
149+
If you want to build image as a shared library supply the following in the configuration of the plugin:
150+
[source,xml]
151+
----
152+
<sharedLibrary>true</sharedLibrary>
153+
----
154+
`<useArgFile>`::
155+
If you want to use argument file for native-image building supply the following in the configuration of the plugin:
156+
[source,xml]
157+
----
158+
<useArgFile>true</useArgFile>
159+
----
160+
`<quickBuild>`::
161+
If you want to build the image using https://blogs.oracle.com/java/post/graalvm-enterprise-221--faster-smarter-leaner[quick build mode], supply the following in the configuration of the plugin:
162+
[source,xml]
163+
----
164+
<quickBuild>true</quickBuild>
165+
----
166+
`<excludeConfig>`::
167+
In order to exclude configuration from present jar files, specify:
168+
[source,xml]
169+
----
170+
<excludeConfig>
171+
<entry>
172+
<jarPath>dummy/path/to/file.jar</jarPath>
173+
<resourcePattern>*</resourcePattern>
174+
</entry>
175+
</excludeConfig>
176+
----
177+
`<environment>`::
178+
To set environment options for native-image building supply the following in the configuration of the plugin:
179+
[source,xml]
180+
----
181+
<environment>
182+
<variable>value</variable>
183+
</environment>
184+
----
185+
`<systemPropertyVariables>`::
186+
To specify system properties used for native-image building supply the following in the configuration of the plugin:
187+
[source,xml]
188+
----
189+
<systemPropertyVariables>
190+
<propertyName>value</propertyName>
191+
</systemPropertyVariables>
192+
----
193+
`<jvmArgs>`::
194+
To specify JVM arguments used for native-image building supply the following in the configuration of the plugin:
195+
[source,xml]
196+
----
197+
<jvmArgs>
198+
<arg>argument1</arg>
199+
<arg>argument2</arg>
200+
</jvmArgs>
201+
----
202+
`<configurationFileDirectories>`::
203+
If you want to specify custom directories where configuration files should be looked up, supply the following in the configuration of the plugin:
204+
[source,xml]
205+
----
206+
<configurationFileDirectories>
207+
<dir>path/to/dir</dir>
208+
</configurationFileDirectories>
209+
----
210+
`<classpath`::
211+
Sets a custom classpath instead of plugin generated one. Usage:
212+
[source,xml]
213+
----
214+
<classpath>
215+
<entry>path/to/file.jar</entry>
216+
<entry>path/to/classes</entry>
217+
</classpath>
218+
----
219+
`<classesDirectory>`::
220+
If you want to specify custom path to packed JAR, or a custom directory that contains
221+
only application classes, but want the plugin to still automatically add classpath entries for
222+
dependencies, simply add:
223+
[source,xml]
224+
----
225+
<classesDirectory>
226+
path/to/dir
227+
</classesDirectory>
228+
----
121229
`<agent>`::
122230
Configuration of the <<agent-support, native agent>>. See <<agent-support-enabling>>
123231
and <<agent-support-configuring-options>> for details.
@@ -126,15 +234,17 @@ For example, to build a native image named `executable-name` that uses
126234
`org.example.ClassName` as its main class with assertions enabled, add the following
127235
`<configuration>` block for the `native-maven-plugin`.
128236

129-
```xml
237+
[source,xml]
238+
----
130239
<configuration>
131240
<imageName>executable-name</imageName>
132241
<mainClass>org.example.ClassName</mainClass>
133-
<buildArgs>
134-
<buildArg>--no-fallback</buildArg>
135-
</buildArgs>
242+
<fallback>false</fallback>
243+
<verbose>true</verbose>
136244
</configuration>
137-
```
245+
----
246+
247+
NOTE: Most of the aforementioned properties can also be set from command line as a part of Maven invocation -- for example if you want to temporarily enable verbose mode you can append `-Dverbose` to your Maven invocation.
138248

139249
NOTE: If you use GraalVM Enterprise as the `JAVA_HOME` environment, the plugin builds a native image with enterprise features enabled -- for example, an executable will automatically be built with https://medium.com/graalvm/isolates-and-compressed-references-more-flexible-and-efficient-memory-management-for-graalvm-a044cc50b67e[compressed references] and other optimizations enabled.
140250

@@ -152,7 +262,7 @@ The `<buildArgs>` element can be combined between parent and children POMs. Supp
152262
<imageName>${project.artifactId}</imageName>
153263
<mainClass>${exec.mainClass}</mainClass>
154264
<buildArgs>
155-
<buildArg>--no-fallback<buildArg>
265+
<buildArg>--no-fallback</buildArg>
156266
</buildArgs>
157267
</configuration>
158268
</plugin>
@@ -323,7 +433,6 @@ Depending on the other plugins your build uses (typically the Spring Boot plugin
323433
...
324434
----
325435

326-
327436
To be able to <<testing-support,execute tests in native mode>>, you will need more setup:
328437

329438
- Create a `src/assembly/test-jar-with-dependencies.xml` file with the following contents:

docs/src/docs/snippets/gradle/groovy/build.gradle

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2021 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2022 Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -119,9 +119,11 @@ graalvmNative {
119119
verbose = true // Add verbose output, defaults to false
120120
fallback = true // Sets the fallback mode of native-image, defaults to false
121121
sharedLibrary = false // Determines if image is a shared library, defaults to false if `java-library` plugin isn't included
122+
quickBuild = false // Determines if image is being built in quick build mode
122123

123124
systemProperties = [name1: 'value1', name2: 'value2'] // Sets the system properties to use for the native image builder
124125
configurationFileDirectories.from(file('src/my-config')) // Adds a native image configuration file directory, containing files like reflection configuration
126+
excludeConfig.put("org.example.test", ["META-INF/native-image/*", "config/*"]) // Excludes configuration that matches one of given regexes from JAR of dependency with said coordinates.
125127

126128
// Advanced options
127129
buildArgs.add('-H:Extra') // Passes '-H:Extra' to the native image builder options. This can be used to pass parameters which are not directly supported by this extension

docs/src/docs/snippets/gradle/kotlin/build.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2021 Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2022 Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -77,9 +77,11 @@ graalvmNative {
7777
verbose.set(true) // Add verbose output, defaults to false
7878
fallback.set(true) // Sets the fallback mode of native-image, defaults to false
7979
sharedLibrary.set(false) // Determines if image is a shared library, defaults to false if `java-library` plugin isn't included
80+
quickBuild.set(false) // Determines if image is being built in quick build mode
8081

8182
systemProperties.putAll(mapOf("name1" to "value1", "name2" to "value2")) // Sets the system properties to use for the native image builder
8283
configurationFileDirectories.from(file("src/my-config")) // Adds a native image configuration file directory, containing files like reflection configuration
84+
excludeConfig.put("org.example.test", listOf("META-INF/native-image/*", "config/*")) // Excludes configuration that matches one of given regexes from JAR of dependency with said coordinates.
8385

8486
// Advanced options
8587
buildArgs.add("-H:Extra") // Passes '-H:Extra' to the native image builder options. This can be used to pass parameters which are not directly supported by this extension

native-gradle-plugin/src/main/java/org/graalvm/buildtools/gradle/dsl/NativeImageOptions.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import org.gradle.api.tasks.Optional;
5757
import org.gradle.jvm.toolchain.JavaLauncher;
5858

59+
import java.util.List;
5960
import java.util.Map;
6061

6162

@@ -162,6 +163,14 @@ public interface NativeImageOptions extends Named {
162163
@Input
163164
Property<Boolean> getSharedLibrary();
164165

166+
/**
167+
* Gets the value which determines if image is being built in quick build mode.
168+
*
169+
* @return The value which determines if image is being built in quick build mode.
170+
*/
171+
@Input
172+
Property<Boolean> getQuickBuild();
173+
165174
/**
166175
* Returns the toolchain used to invoke native-image. Currently pointing
167176
* to a Java launcher due to Gradle limitations.
@@ -180,14 +189,14 @@ public interface NativeImageOptions extends Named {
180189
ConfigurableFileCollection getConfigurationFileDirectories();
181190

182191
/**
183-
* Returns the map that as contains information about configuration that should be excluded
184-
* during image building. It consists of a jar regular expression as a key and a resource
185-
* regular expression as a value.
192+
* Returns the MapProperty that contains information about configuration that should be excluded
193+
* during image building. It consists of a dependency coordinates and a list of
194+
* regular expressions that match resources that should be excluded as a value.
186195
*
187196
* @return a map of filters for configuration exclusion
188197
*/
189198
@Input
190-
MapProperty<String, String> getExcludeConfig();
199+
MapProperty<String, List<String>> getExcludeConfig();
191200

192201
@Nested
193202
NativeResourcesOptions getResources();

native-gradle-plugin/src/main/java/org/graalvm/buildtools/gradle/internal/BaseNativeImageOptions.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2022, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -64,6 +64,7 @@
6464

6565
import javax.inject.Inject;
6666
import java.util.Arrays;
67+
import java.util.List;
6768
import java.util.Map;
6869
import java.util.stream.Collectors;
6970
import java.util.stream.StreamSupport;
@@ -178,7 +179,15 @@ public String getName() {
178179
public abstract Property<Boolean> getSharedLibrary();
179180

180181
/**
181-
* Returns the toolchain used to invoke native-image. Currently pointing
182+
* Gets the value which determines if image is being built in quick build mode.
183+
*
184+
* @return The value which determines if image is being built in quick build mode.
185+
*/
186+
@Input
187+
public abstract Property<Boolean> getQuickBuild();
188+
189+
/**
190+
* Returns the toolchain used to invoke native-image. Currently, pointing
182191
* to a Java launcher due to Gradle limitations.
183192
*/
184193
@Nested
@@ -194,6 +203,16 @@ public String getName() {
194203
@InputFiles
195204
public abstract ConfigurableFileCollection getConfigurationFileDirectories();
196205

206+
/**
207+
* Returns the MapProperty that contains information about configuration that should be excluded
208+
* during image building. It consists of a dependency coordinates and a list of
209+
* regular expressions that match resources that should be excluded as a value.
210+
*
211+
* @return a map of filters for configuration exclusion
212+
*/
213+
@Input
214+
public abstract MapProperty<String, List<String>> getExcludeConfig();
215+
197216
@Nested
198217
public abstract NativeResourcesOptions getResources();
199218

@@ -212,6 +231,7 @@ public BaseNativeImageOptions(String name,
212231
getDebug().convention(false);
213232
getFallback().convention(false);
214233
getVerbose().convention(false);
234+
getQuickBuild().convention(false);
215235
getSharedLibrary().convention(false);
216236
getImageName().convention(defaultImageName);
217237
getUseFatJar().convention(false);

0 commit comments

Comments
 (0)