Skip to content

Commit

Permalink
Add the Micronaut GraalVM dependency consistently (#843)
Browse files Browse the repository at this point in the history
In previous releases of the plugin, there was an inconsistency in how the
`micronaut-graal` processor was added. In particular, the dependency was
only added if the JVM _running the build_ was GraalVM, but only for Kotlin.
For Java and Groovy, the dependency was added in any case.

In fact, the behavior for Kotlin was wrong, since there's no reason
that the toolchain used to compile the app is the same as the one
running the build. Therefore, this commit changes the behavior so that
as soon as the `io.micronaut.graalvm` plugin is applied, then the
dependency is added.

It is a slight behavioral change for users who do _not_ use GraalVM
but who would still apply the `io.micronaut.application` plugin.
Before this change, they wouldn't have a `micronaut-graalvm` annotation
processor on classpath. After this change, they will, because
the `application` plugin applies the `graalvm` plugin. It is however
significantly easier to reason about and more correct.
  • Loading branch information
melix authored Sep 25, 2023
1 parent 4476879 commit 2d49314
Showing 1 changed file with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.micronaut.gradle;

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;
Expand Down Expand Up @@ -199,21 +198,21 @@ private static void configureAdditionalSourceSet(String compilerType, Dependency
configureAnnotationProcessors(p,
implementationConfigurationName,
annotationProcessorConfigurationName);
if (GraalUtil.isGraalJVM()) {
new AutomaticDependency(annotationProcessorConfigurationName,
"io.micronaut:micronaut-graal",
Optional.of(CORE_VERSION_PROPERTY)).applyTo(p);
}
p.getPluginManager().withPlugin("io.micronaut.graalvm", unused ->
new AutomaticDependency(annotationProcessorConfigurationName,
"io.micronaut:micronaut-graal",
Optional.of(CORE_VERSION_PROPERTY)).applyTo(p)
);
}

private static void addGraalVmDependencies(String[] compilerConfigurations, Project project) {
if (GraalUtil.isGraalJVM()) {
project.getPluginManager().withPlugin("io.micronaut.graalvm", unused -> {
for (String configuration : compilerConfigurations) {
new AutomaticDependency(configuration,
"io.micronaut:micronaut-graal",
Optional.of(CORE_VERSION_PROPERTY)).applyTo(project);
}
}
});
}

private static void configureAllOpen(Project project) {
Expand Down

0 comments on commit 2d49314

Please sign in to comment.