Skip to content

Commit 4f869f4

Browse files
Fix review feedback
1 parent 0afe2d8 commit 4f869f4

File tree

5 files changed

+36
-29
lines changed

5 files changed

+36
-29
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", "6.7.1"]
56+
gradle-version: ["current", "7.3.3", "7.2", "7.1", "6.8.3", "6.7.1"]
5757
graalvm-version: [ dev ]
5858
java-version: [ 11 ]
5959
os: [ ubuntu-20.04 ]

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,12 @@ Build Configuration]. It is also possible to customize the plugin within a
158158
<useArgFile>true</useArgFile>
159159
----
160160
`<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:
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 (alternatively set the `GRAALVM_QUICK_BUILD` environment variable to `true`):
162162
[source,xml]
163163
----
164164
<quickBuild>true</quickBuild>
165165
----
166+
166167
`<excludeConfig>`::
167168
In order to exclude configuration from present jar files, specify:
168169
[source,xml]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ public String getName() {
205205

206206
/**
207207
* 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.
208+
* during image building. It consists of dependency coordinates and a list of
209+
* regular expressions that match resources that should be excluded.
210210
*
211211
* @return a map of filters for configuration exclusion
212212
*/

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

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@
4343

4444
import org.graalvm.buildtools.gradle.dsl.NativeImageOptions;
4545
import org.graalvm.buildtools.utils.NativeImageUtils;
46-
import org.gradle.api.Project;
4746
import org.gradle.api.Transformer;
47+
import org.gradle.api.artifacts.Configuration;
4848
import org.gradle.api.artifacts.component.ModuleComponentIdentifier;
4949
import org.gradle.api.file.FileSystemLocation;
5050
import org.gradle.api.file.RegularFile;
@@ -56,6 +56,7 @@
5656

5757
import java.io.File;
5858
import java.util.ArrayList;
59+
import java.util.Collection;
5960
import java.util.Collections;
6061
import java.util.List;
6162
import java.util.stream.Collectors;
@@ -68,20 +69,17 @@ public class NativeImageCommandLineProvider implements CommandLineArgumentProvid
6869
private final Provider<String> outputDirectory;
6970
private final Provider<RegularFile> classpathJar;
7071
private final Provider<Boolean> useArgFile;
71-
private final Project project;
7272

7373
public NativeImageCommandLineProvider(Provider<NativeImageOptions> options,
7474
Provider<String> executableName,
7575
Provider<String> outputDirectory,
7676
Provider<RegularFile> classpathJar,
77-
Provider<Boolean> useArgFile,
78-
Project project) {
77+
Provider<Boolean> useArgFile) {
7978
this.options = options;
8079
this.executableName = executableName;
8180
this.outputDirectory = outputDirectory;
8281
this.classpathJar = classpathJar;
8382
this.useArgFile = useArgFile;
84-
this.project = project;
8583
}
8684

8785
@Nested
@@ -108,24 +106,33 @@ private List<String> buildExcludeConfigArgs(NativeImageOptions options) {
108106
List<String> args = new ArrayList<>();
109107
options.getExcludeConfig().get().forEach((dependency, listOfResourcePatterns) -> {
110108
// Resolve jar for this dependency.
111-
project.getConfigurations().getByName("runtimeClasspath").getIncoming().artifactView(view -> {
112-
view.setLenient(true);
113-
view.componentFilter(id -> {
114-
if (id instanceof ModuleComponentIdentifier) {
115-
ModuleComponentIdentifier mid = (ModuleComponentIdentifier) id;
116-
String gav = String.format("%s:%s",
117-
mid.getGroup(),
118-
mid.getModule()
119-
);
120-
return dependency.startsWith(gav);
121-
}
122-
return false;
123-
});
124-
}).getFiles().forEach(jarPath -> listOfResourcePatterns.forEach(resourcePattern -> {
125-
args.add("--exclude-config");
126-
args.add(jarPath.toPath().toAbsolutePath().toString());
127-
args.add(String.format("\"%s\"", resourcePattern));
128-
}));
109+
options.getClasspath()
110+
.getFrom().stream()
111+
.filter(Configuration.class::isInstance)
112+
.map(Configuration.class::cast)
113+
.map(configuration -> configuration.getIncoming().artifactView(view -> {
114+
view.setLenient(true);
115+
view.componentFilter(id -> {
116+
if (id instanceof ModuleComponentIdentifier) {
117+
ModuleComponentIdentifier mid = (ModuleComponentIdentifier) id;
118+
String gav = String.format("%s:%s:%s",
119+
mid.getGroup(),
120+
mid.getModule(),
121+
mid.getVersion()
122+
);
123+
return gav.startsWith(dependency);
124+
}
125+
return false;
126+
});
127+
}).getFiles().getFiles())
128+
.flatMap(Collection::stream)
129+
.distinct()
130+
.forEach(jarPath -> listOfResourcePatterns.forEach(resourcePattern -> {
131+
args.add("--exclude-config");
132+
args.add(jarPath.toPath().toAbsolutePath().toString());
133+
args.add(String.format("\"%s\"", resourcePattern));
134+
}));
135+
129136
});
130137
return args;
131138
}

native-gradle-plugin/src/main/java/org/graalvm/buildtools/gradle/tasks/BuildNativeImageTask.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,7 @@ private List<String> buildActualCommandLineArgs() {
155155
// a mapped value before the task was called, when we are actually calling it...
156156
getProviders().provider(() -> getOutputDirectory().getAsFile().get().getAbsolutePath()),
157157
getClasspathJar(),
158-
getUseArgFile(),
159-
getProject()
158+
getUseArgFile()
160159
).asArguments();
161160
}
162161

0 commit comments

Comments
 (0)