Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Supports for building Java applications as GraalVM native images.
Using the [plugins DSL](https://docs.gradle.org/current/userguide/plugins.html#sec:plugins_block):
```groovy
plugins {
id 'com.formkiq.gradle.graalvm-native-plugin' version '1.7.0'
id 'com.formkiq.gradle.graalvm-native-plugin' version '1.7.3'
}
```

Expand All @@ -25,7 +25,7 @@ buildscript {
}
}
dependencies {
classpath "com.formkiq.gradle:graalvm-native-plugin:1.7.0"
classpath "com.formkiq.gradle:graalvm-native-plugin:1.7.3"
}
}

Expand All @@ -36,7 +36,7 @@ apply plugin: "com.formkiq.gradle.graalvm-native-plugin"
Using the [plugins DSL](https://docs.gradle.org/current/userguide/plugins.html#sec:plugins_block):
```kotlin
plugins {
id("com.formkiq.gradle.graalvm-native-plugin") version "1.7.0"
id("com.formkiq.gradle.graalvm-native-plugin") version "1.7.3"
}
```

Expand All @@ -49,7 +49,7 @@ buildscript {
}
}
dependencies {
classpath("com.formkiq.gradle:graalvm-native-plugin:1.7.0")
classpath("com.formkiq.gradle:graalvm-native-plugin:1.7.3")
}
}

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
}

group 'com.formkiq.gradle'
version '1.7.2'
version '1.7.3'

spotless {
java {
Expand Down
9 changes: 8 additions & 1 deletion config/gradle/spotbugs-exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ For a detailed description of spotbugs bug categories, see https://spotbugs.read
</OR>
</Match>

<Match>
<Bug pattern="EI_EXPOSE_REP"/>
<OR>
<Class name="com.formkiq.gradle.GraalvmNativeExtension"/>
</OR>
</Match>

<Match>
<Bug pattern="EI_EXPOSE_REP2"/>
<OR>
Expand All @@ -55,4 +62,4 @@ For a detailed description of spotbugs bug categories, see https://spotbugs.read
</OR>
</Match>

</FindBugsFilter>
</FindBugsFilter>
2 changes: 1 addition & 1 deletion samples/aws-lambda/HelloWorldFunction/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

plugins {
id 'java-library'
id 'com.formkiq.gradle.graalvm-native-plugin' version '1.7.0-SNAPSHOT'
id 'com.formkiq.gradle.graalvm-native-plugin' version '1.7.3'
}

repositories {
Expand Down
2 changes: 1 addition & 1 deletion samples/dockerfile/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
plugins {
id 'java'
id 'com.formkiq.gradle.graalvm-native-plugin' version '1.7.0-SNAPSHOT'
id 'com.formkiq.gradle.graalvm-native-plugin' version '1.7.3'
}

nativeImage {
Expand Down
2 changes: 1 addition & 1 deletion samples/helloworld/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id 'application'
id 'com.formkiq.gradle.graalvm-native-plugin' version '1.7.0-SNAPSHOT'
id 'com.formkiq.gradle.graalvm-native-plugin' version '1.7.3'
}

sourceCompatibility = "11"
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/formkiq/gradle/GraalvmNativeExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -289,10 +289,10 @@ public String getJniConfigurationFiles() {
/**
* Get Main Class Name.
*
* @return {@link String}
* @return {@link Property} {@link String}
*/
public String getMainClassName() {
return this.mainClassName.get();
public Property<String> getMainClassName() {
return this.mainClassName;
}

/**
Expand Down
93 changes: 79 additions & 14 deletions src/main/java/com/formkiq/gradle/GraalvmNativePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.plugins.JavaPlugin;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.SourceSet;
import org.gradle.api.tasks.SourceSetContainer;
import org.gradle.api.tasks.TaskProvider;

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

TaskProvider<GraalvmNativeTask> nativeImage =
project.getTasks().register("graalvmNativeImage", GraalvmNativeTask.class, task -> {
task.setGroup("Graalvm");
task.setDescription("Build GraalVM Native Image");
task.setExtension(ext);
task.usesService(svc);
project.afterEvaluate(p -> {
// Treat "configured" as: user set mainClassName (adjust the predicate if you prefer)
boolean configured = ext.getMainClassName().isPresent();

if (!configured) {
// User didn't declare nativeImage { ... } in this subproject — do nothing.
return;
}

// Register the task now that we know it's wanted in this project
TaskProvider<GraalvmNativeTask> nativeImage =
project.getTasks().register("graalvmNativeImage", GraalvmNativeTask.class, task -> {
task.setGroup("Graalvm");
task.setDescription("Build GraalVM Native Image");
task.setExtension(ext); // inject the extension (nested inputs)
task.usesService(svc);
task.getBuildDirectory().set(project.getLayout().getBuildDirectory().dir("graalvm"));
});

// Wire only if the Java plugin is applied
project.getPlugins().withType(JavaPlugin.class, jp -> {
SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
SourceSet main = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);

// Inputs
nativeImage.configure(t -> {
t.getSources().from(main.getAllSource()); // java + resources
t.getRuntimeClasspath().from(main.getRuntimeClasspath()); // runtime jars/classes
});

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

// only depend on `jar` if that task was applied
if (p.getTasks().findByName("jar") != null) {
task.dependsOn("jar");
}
}));
// If you want assemble to run AFTER native image in projects that opted in
project.getTasks()
.named(org.gradle.language.base.plugins.LifecycleBasePlugin.ASSEMBLE_TASK_NAME)
.configure(t -> t.dependsOn(nativeImage));

// If the Distribution plugin is applied, make distZip wait for native image
project.getPlugins().withId("distribution",
__ -> project.getTasks().named("distZip").configure(t -> t.dependsOn(nativeImage)));
});

// TaskProvider<GraalvmNativeTask> nativeImage =
// project.getTasks().register("graalvmNativeImage", GraalvmNativeTask.class, task -> {
// task.setGroup("Graalvm");
// task.setDescription("Build GraalVM Native Image");
// task.setExtension(ext);
// task.usesService(svc);
// task.onlyIf(t -> ext.getMainClassName().isPresent());
//
// task.getBuildDirectory().set(project.getLayout().getBuildDirectory().dir("graalvm"));
// });
//
// project.getPlugins().withType(JavaPlugin.class, jp -> {
// SourceSetContainer sourceSets =
// project.getExtensions().getByType(SourceSetContainer.class);
// SourceSet main = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
//
// // Inputs
// nativeImage.configure(t -> {
// t.getSources().from(main.getAllSource()); // sources (java + resources)
// t.getRuntimeClasspath().from(main.getRuntimeClasspath()); // runtime jars/classes
// });
//
// nativeImage.configure(t ->
// t.dependsOn(project.getTasks().named(JavaPlugin.JAR_TASK_NAME)));
// });
//
// // Make assemble run AFTER native image (i.e., assemble depends on native)
// project.getTasks()
// .named(org.gradle.language.base.plugins.LifecycleBasePlugin.ASSEMBLE_TASK_NAME)
// .configure(t -> t.dependsOn(nativeImage));
//
// // If using the Distribution plugin, make distZip run AFTER native image
// project.getPlugins().withId("distribution", p -> {
// project.getTasks().named("distZip").configure(t -> t.dependsOn(nativeImage));
// });
}
}
Loading