Skip to content

Commit f9be224

Browse files
authored
V1.7.3 (#35)
* Fixed project building Lifecycle * Updated dependencies to 1.7.3
1 parent 78e54fb commit f9be224

16 files changed

Lines changed: 201 additions & 233 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Supports for building Java applications as GraalVM native images.
1212
Using the [plugins DSL](https://docs.gradle.org/current/userguide/plugins.html#sec:plugins_block):
1313
```groovy
1414
plugins {
15-
id 'com.formkiq.gradle.graalvm-native-plugin' version '1.7.0'
15+
id 'com.formkiq.gradle.graalvm-native-plugin' version '1.7.3'
1616
}
1717
```
1818

@@ -25,7 +25,7 @@ buildscript {
2525
}
2626
}
2727
dependencies {
28-
classpath "com.formkiq.gradle:graalvm-native-plugin:1.7.0"
28+
classpath "com.formkiq.gradle:graalvm-native-plugin:1.7.3"
2929
}
3030
}
3131
@@ -36,7 +36,7 @@ apply plugin: "com.formkiq.gradle.graalvm-native-plugin"
3636
Using the [plugins DSL](https://docs.gradle.org/current/userguide/plugins.html#sec:plugins_block):
3737
```kotlin
3838
plugins {
39-
id("com.formkiq.gradle.graalvm-native-plugin") version "1.7.0"
39+
id("com.formkiq.gradle.graalvm-native-plugin") version "1.7.3"
4040
}
4141
```
4242

@@ -49,7 +49,7 @@ buildscript {
4949
}
5050
}
5151
dependencies {
52-
classpath("com.formkiq.gradle:graalvm-native-plugin:1.7.0")
52+
classpath("com.formkiq.gradle:graalvm-native-plugin:1.7.3")
5353
}
5454
}
5555

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ plugins {
1010
}
1111

1212
group 'com.formkiq.gradle'
13-
version '1.7.2'
13+
version '1.7.3'
1414

1515
spotless {
1616
java {

config/gradle/spotbugs-exclude.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ For a detailed description of spotbugs bug categories, see https://spotbugs.read
4141
</OR>
4242
</Match>
4343

44+
<Match>
45+
<Bug pattern="EI_EXPOSE_REP"/>
46+
<OR>
47+
<Class name="com.formkiq.gradle.GraalvmNativeExtension"/>
48+
</OR>
49+
</Match>
50+
4451
<Match>
4552
<Bug pattern="EI_EXPOSE_REP2"/>
4653
<OR>
@@ -55,4 +62,4 @@ For a detailed description of spotbugs bug categories, see https://spotbugs.read
5562
</OR>
5663
</Match>
5764

58-
</FindBugsFilter>
65+
</FindBugsFilter>

samples/aws-lambda/HelloWorldFunction/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
plugins {
33
id 'java-library'
4-
id 'com.formkiq.gradle.graalvm-native-plugin' version '1.7.0-SNAPSHOT'
4+
id 'com.formkiq.gradle.graalvm-native-plugin' version '1.7.3'
55
}
66

77
repositories {

samples/dockerfile/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
plugins {
88
id 'java'
9-
id 'com.formkiq.gradle.graalvm-native-plugin' version '1.7.0-SNAPSHOT'
9+
id 'com.formkiq.gradle.graalvm-native-plugin' version '1.7.3'
1010
}
1111

1212
nativeImage {

samples/helloworld/app/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
plugins {
1010
// Apply the application plugin to add support for building a CLI application in Java.
1111
id 'application'
12-
id 'com.formkiq.gradle.graalvm-native-plugin' version '1.7.0-SNAPSHOT'
12+
id 'com.formkiq.gradle.graalvm-native-plugin' version '1.7.3'
1313
}
1414

1515
sourceCompatibility = "11"

src/main/java/com/formkiq/gradle/GraalvmNativeExtension.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,10 @@ public String getJniConfigurationFiles() {
289289
/**
290290
* Get Main Class Name.
291291
*
292-
* @return {@link String}
292+
* @return {@link Property} {@link String}
293293
*/
294-
public String getMainClassName() {
295-
return this.mainClassName.get();
294+
public Property<String> getMainClassName() {
295+
return this.mainClassName;
296296
}
297297

298298
/**

src/main/java/com/formkiq/gradle/GraalvmNativePlugin.java

Lines changed: 79 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616

1717
import org.gradle.api.Plugin;
1818
import org.gradle.api.Project;
19+
import org.gradle.api.plugins.JavaPlugin;
1920
import org.gradle.api.provider.Provider;
21+
import org.gradle.api.tasks.SourceSet;
22+
import org.gradle.api.tasks.SourceSetContainer;
2023
import org.gradle.api.tasks.TaskProvider;
2124

2225
/** GraalVM Plugin to build a native-image from a Java application. */
@@ -31,22 +34,84 @@ public void apply(final Project project) {
3134
Provider<GraalvmBuildService> svc = project.getGradle().getSharedServices().registerIfAbsent(
3235
"web", GraalvmBuildService.class, spec -> spec.getMaxParallelUsages().set(1));
3336

34-
TaskProvider<GraalvmNativeTask> nativeImage =
35-
project.getTasks().register("graalvmNativeImage", GraalvmNativeTask.class, task -> {
36-
task.setGroup("Graalvm");
37-
task.setDescription("Build GraalVM Native Image");
38-
task.setExtension(ext);
39-
task.usesService(svc);
37+
project.afterEvaluate(p -> {
38+
// Treat "configured" as: user set mainClassName (adjust the predicate if you prefer)
39+
boolean configured = ext.getMainClassName().isPresent();
40+
41+
if (!configured) {
42+
// User didn't declare nativeImage { ... } in this subproject — do nothing.
43+
return;
44+
}
45+
46+
// Register the task now that we know it's wanted in this project
47+
TaskProvider<GraalvmNativeTask> nativeImage =
48+
project.getTasks().register("graalvmNativeImage", GraalvmNativeTask.class, task -> {
49+
task.setGroup("Graalvm");
50+
task.setDescription("Build GraalVM Native Image");
51+
task.setExtension(ext); // inject the extension (nested inputs)
52+
task.usesService(svc);
53+
task.getBuildDirectory().set(project.getLayout().getBuildDirectory().dir("graalvm"));
54+
});
55+
56+
// Wire only if the Java plugin is applied
57+
project.getPlugins().withType(JavaPlugin.class, jp -> {
58+
SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
59+
SourceSet main = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
60+
61+
// Inputs
62+
nativeImage.configure(t -> {
63+
t.getSources().from(main.getAllSource()); // java + resources
64+
t.getRuntimeClasspath().from(main.getRuntimeClasspath()); // runtime jars/classes
4065
});
4166

42-
project.afterEvaluate(p -> nativeImage.configure(task -> {
43-
// always depend on `check`
44-
task.dependsOn("check");
67+
// Ensure producers run first (jar is enough; avoids assemble cycles)
68+
nativeImage.configure(t -> t.dependsOn(project.getTasks().named(JavaPlugin.JAR_TASK_NAME)));
69+
});
4570

46-
// only depend on `jar` if that task was applied
47-
if (p.getTasks().findByName("jar") != null) {
48-
task.dependsOn("jar");
49-
}
50-
}));
71+
// If you want assemble to run AFTER native image in projects that opted in
72+
project.getTasks()
73+
.named(org.gradle.language.base.plugins.LifecycleBasePlugin.ASSEMBLE_TASK_NAME)
74+
.configure(t -> t.dependsOn(nativeImage));
75+
76+
// If the Distribution plugin is applied, make distZip wait for native image
77+
project.getPlugins().withId("distribution",
78+
__ -> project.getTasks().named("distZip").configure(t -> t.dependsOn(nativeImage)));
79+
});
80+
81+
// TaskProvider<GraalvmNativeTask> nativeImage =
82+
// project.getTasks().register("graalvmNativeImage", GraalvmNativeTask.class, task -> {
83+
// task.setGroup("Graalvm");
84+
// task.setDescription("Build GraalVM Native Image");
85+
// task.setExtension(ext);
86+
// task.usesService(svc);
87+
// task.onlyIf(t -> ext.getMainClassName().isPresent());
88+
//
89+
// task.getBuildDirectory().set(project.getLayout().getBuildDirectory().dir("graalvm"));
90+
// });
91+
//
92+
// project.getPlugins().withType(JavaPlugin.class, jp -> {
93+
// SourceSetContainer sourceSets =
94+
// project.getExtensions().getByType(SourceSetContainer.class);
95+
// SourceSet main = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
96+
//
97+
// // Inputs
98+
// nativeImage.configure(t -> {
99+
// t.getSources().from(main.getAllSource()); // sources (java + resources)
100+
// t.getRuntimeClasspath().from(main.getRuntimeClasspath()); // runtime jars/classes
101+
// });
102+
//
103+
// nativeImage.configure(t ->
104+
// t.dependsOn(project.getTasks().named(JavaPlugin.JAR_TASK_NAME)));
105+
// });
106+
//
107+
// // Make assemble run AFTER native image (i.e., assemble depends on native)
108+
// project.getTasks()
109+
// .named(org.gradle.language.base.plugins.LifecycleBasePlugin.ASSEMBLE_TASK_NAME)
110+
// .configure(t -> t.dependsOn(nativeImage));
111+
//
112+
// // If using the Distribution plugin, make distZip run AFTER native image
113+
// project.getPlugins().withId("distribution", p -> {
114+
// project.getTasks().named("distZip").configure(t -> t.dependsOn(nativeImage));
115+
// });
51116
}
52117
}

0 commit comments

Comments
 (0)