Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use an automatic dependency for graal #725

Merged
merged 1 commit into from
May 22, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class MicronautGraalPluginSpec extends AbstractEagerConfiguringFunctionalTest {
void 'native-image is called with the generated JSON file directory (Micronaut Application)'() {
given:
withSwaggerMicronautApplication()
withNativeImageDryRun()

when:
def result = build('nativeCompile', '-i', '--stacktrace')
Expand All @@ -76,6 +77,7 @@ class MicronautGraalPluginSpec extends AbstractEagerConfiguringFunctionalTest {
void 'native-image is called with the generated JSON file directory (regular Application)'() {
given:
withSwaggerApplication()
withNativeImageDryRun()

when:
def result = build('nativeCompile', '-i', '--stacktrace')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io.micronaut.gradle.MicronautExtension;
import io.micronaut.gradle.MicronautRuntime;
import io.micronaut.gradle.PluginsHelper;
import io.micronaut.gradle.internal.AutomaticDependency;
import org.graalvm.buildtools.gradle.NativeImagePlugin;
import org.graalvm.buildtools.gradle.dsl.GraalVMExtension;
import org.graalvm.buildtools.gradle.dsl.GraalVMReachabilityMetadataRepositoryExtension;
Expand All @@ -24,8 +25,11 @@
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;

import static io.micronaut.gradle.PluginsHelper.CORE_VERSION_PROPERTY;

/**
* Support for building GraalVM native images.
*
Expand Down Expand Up @@ -127,10 +131,9 @@ private static void configureAnnotationProcessing(Project project, MicronautExte

private static void addGraalVMAnnotationProcessorDependency(Project project, Iterable<SourceSet> sourceSets) {
for (SourceSet sourceSet : sourceSets) {
project.getDependencies().add(
sourceSet.getAnnotationProcessorConfigurationName(),
"io.micronaut:micronaut-graal"
);
new AutomaticDependency(sourceSet.getAnnotationProcessorConfigurationName(),
"io.micronaut:micronaut-graal",
Optional.of(CORE_VERSION_PROPERTY)).applyTo(project);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class NativeImageTaskSpec extends AbstractGradleBuildSpec {
mainClassName="example.Application"

"""
withNativeImageDryRun()

testProjectDir.newFolder("src", "main", "java", "example")
def javaFile = testProjectDir.newFile("src/main/java/example/Application.java")
javaFile.parentFile.mkdirs()
Expand Down Expand Up @@ -82,6 +84,7 @@ class Application {
}
}
"""
withNativeImageDryRun()
testProjectDir.newFolder("src", "main", "java", "example")
def javaFile = testProjectDir.newFile("src/main/java/example/Application.java")
javaFile.parentFile.mkdirs()
Expand All @@ -103,7 +106,6 @@ class Application {
def task = result.task(":nativeCompile")
then:
result.output.contains("Native Image written to")
result.output.contains("Generating 'basic-app'")
argFileContentsOf(result).contains('-Dfoo=bar')
task.outcome == TaskOutcome.SUCCESS
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.google.devtools.ksp.gradle.KspExtension;
import io.micronaut.gradle.graalvm.GraalUtil;
import io.micronaut.gradle.internal.AutomaticDependency;
import org.gradle.api.Project;
import org.gradle.api.artifacts.Configuration;
import org.gradle.api.artifacts.Dependency;
Expand All @@ -20,10 +21,12 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.function.Consumer;

import static io.micronaut.gradle.PluginsHelper.resolveMicronautPlatform;
import static io.micronaut.gradle.PluginsHelper.CORE_VERSION_PROPERTY;
import static io.micronaut.gradle.PluginsHelper.configureAnnotationProcessors;
import static io.micronaut.gradle.PluginsHelper.resolveMicronautPlatform;

/**
* Extension to integration support for Kotlin.
Expand Down Expand Up @@ -141,7 +144,7 @@ private static void configureKotlinCompilerPlugin(Project project, String[] comp
// add inject-java to kapt scopes
DependencyHandler dependencies = project.getDependencies();
PluginsHelper.registerAnnotationProcessors(project, annotationProcessorModules, compilerConfigurations);
addGraalVmDependencies(compilerConfigurations, dependencies);
addGraalVmDependencies(compilerConfigurations, project);

Configuration kotlinProcessors = project.getConfigurations().getByName(KOTLIN_PROCESSORS);
for (String compilerConfiguration : compilerConfigurations) {
Expand Down Expand Up @@ -197,20 +200,18 @@ private static void configureAdditionalSourceSet(String compilerType, Dependency
implementationConfigurationName,
annotationProcessorConfigurationName);
if (GraalUtil.isGraalJVM()) {
dependencies.add(
annotationProcessorConfigurationName,
"io.micronaut:micronaut-graal"
);
new AutomaticDependency(annotationProcessorConfigurationName,
"io.micronaut:micronaut-graal",
Optional.of(CORE_VERSION_PROPERTY)).applyTo(p);
}
}

private static void addGraalVmDependencies(String[] compilerConfigurations, DependencyHandler dependencies) {
private static void addGraalVmDependencies(String[] compilerConfigurations, Project project) {
if (GraalUtil.isGraalJVM()) {
for (String configuration : compilerConfigurations) {
dependencies.add(
configuration,
"io.micronaut:micronaut-graal"
);
new AutomaticDependency(configuration,
"io.micronaut:micronaut-graal",
Optional.of(CORE_VERSION_PROPERTY)).applyTo(project);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,14 @@ abstract class AbstractGradleBuildSpec extends Specification {
}
}

void withNativeImageDryRun() {
buildFile << """
graalvmNative.binaries.all {
buildArgs.add("--dry-run")
}
"""
}

private void prepareBuild() {
if (postSettingsStatements) {
postSettingsStatements.each {
Expand Down