@groovy.transform.CompileStatic class GrailsGradlePlugin extends java.lang.Object implements Plugin<Project>
The main Grails gradle plugin implementation
| Type | Name and description |
|---|---|
java.util.List<java.lang.Class<Plugin>> |
basePluginClasses |
java.util.List<java.lang.String> |
excludedGrailsAppSourceDirs |
java.util.List<java.lang.String> |
grailsAppResourceDirs |
| Constructor and description |
|---|
GrailsGradlePlugin(ToolingModelBuilderRegistry registry) |
| Type Params | Return Type | Name and description |
|---|---|---|
|
void |
apply(Project project) |
|
protected void |
applyBasePlugins(Project project) |
|
protected void |
applyDefaultPlugins(Project project) |
|
protected void |
applyGrailsBom(Project project)Applies a single Grails BOM as a Gradle platform and enables property-based version overrides via the standalone org.apache.grails.gradle.bom-property-overrides plugin. |
|
protected void |
applySpringBootPlugin(Project project) |
|
protected void |
configureAheadOfTimeProcessing(Project project)Generates the application's bean definitions for the environment it will be run in. |
|
protected void |
configureAotCache(Project project)Wires up the cache the JDK can write for an application, so the next start reads what a training run worked out rather than working it out again. |
|
protected void |
configureAssetCompilation(Project project) |
|
protected void |
configureBootRunPidFile(Project project) |
<T extends JavaForkOptions & DefaultTask> |
protected void |
configureForkSettings(Project project, java.lang.String grailsVersion) |
|
protected void |
configureGrailsSourceDirs(Project project) |
|
protected void |
configureGroovy(Project project) |
|
protected void |
configureI18nDescriptor(Project project)Records the message bundles this artifact ships into META-INF/grails/i18n.properties. |
|
protected void |
configureJavaCompatibilityArgs(Project project)Configures JVM arguments required for compatibility with Java 23+. |
|
protected void |
configureMicronaut(Project project) |
|
protected void |
configureNativeImage(Project project)What a Grails application needs of a native image that an image cannot work out for itself. |
|
protected void |
configureNativeMetadata(Project project)Records the application's own classes and pages so a native image keeps them usable. |
|
protected void |
configureNativeMetadataTrace(Project project)Records the reflection a running application does, which is the half of an image's metadata that reading the build output cannot supply. |
|
protected void |
configureProfile(Project project) |
|
protected void |
configureTemplateResources(Project project)Packages src/main/templates into the main resources as META-INF/templates. |
|
protected void |
configureToolchainForForkTasks(Project project)Configures JavaExec tasks to inherit the project's Java toolchain. |
|
protected void |
createBuildPropertiesTask(Project project) |
|
protected TaskProvider<Task> |
createNative2AsciiTask(TaskContainer tasks, java.lang.Object src, java.lang.Object dest) |
|
protected void |
enableNative2Ascii(Project project, java.lang.String grailsVersion)Enables native2ascii processing of resource bundles |
|
protected void |
excludeDependencies(Project project) |
|
protected java.lang.String |
getDefaultProfile() |
|
protected groovy.lang.Closure<java.lang.String> |
getGroovyCompilerScript(GroovyCompile compile, Project project) |
|
protected static Provider<java.lang.String> |
getMainClassProvider(Project project) |
|
protected Provider<java.lang.String> |
grailsArtifactName(Project project)The artifact.name recorded in the i18n descriptor. |
|
protected java.lang.String |
grailsArtifactType()The artifact.type recorded in the i18n descriptor. |
|
protected boolean |
isGrailsSourceDirectory(java.io.File subdir) |
|
protected void |
registerFindMainClassTask(Project project) |
|
protected GrailsExtension |
registerGrailsExtension(Project project) |
|
protected void |
registerToolingModelBuilder(Project project, ToolingModelBuilderRegistry registry) |
|
protected java.util.List<java.io.File> |
resolveGrailsResourceDirs(Project project) |
|
protected java.util.List<java.io.File> |
resolveGrailsSourceDirs(Project project) |
|
protected java.lang.String |
resolveGrailsVersion(Project project) |
|
protected static void |
validateMicronautBom(Project project)Validates that a Micronaut-compatible BOM is applied as an enforcedPlatform when micronaut is used. |
| Methods inherited from class | Name |
|---|---|
class java.lang.Object |
java.lang.Object#equals(java.lang.Object), java.lang.Object#getClass(), java.lang.Object#hashCode(), java.lang.Object#notify(), java.lang.Object#notifyAll(), java.lang.Object#toString(), java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int) |
Applies a single Grails BOM as a Gradle platform and enables property-based
version overrides via the standalone
org.apache.grails.gradle.bom-property-overrides plugin.
This replaces the Spring Dependency Management plugin with two orthogonal pieces:
grails.bom
(default grails-bom) is added as a Gradle platform()
dependency - or an enforcedPlatform() for the Micronaut variants -
on every declarable configuration, mirroring the global behaviour Spring
DM provided via configurations.all() + resolutionStrategy.eachDependency().
Exactly one Grails BOM is ever applied; the BOMs are split by integration
(default / hibernate5 / micronaut), so the plugin never layers two of them.<properties> block and applies any project-level
overrides via Gradle's
ResolutionStrategy.eachDependency().Set grails { bom = null } (or the deprecated
grails { springDependencyManagement = false }) to suppress the automatic BOM
application entirely and declare the platform()/enforcedPlatform() by hand.
Usage: to override a version managed by the Grails or Spring Boot BOM, set the
corresponding property in gradle.properties or build.gradle:
// gradle.properties slf4j.version=1.7.36 // or build.gradle ext['slf4j.version'] = '1.7.36'
Generates the application's bean definitions for the environment it will be run in.
Generation reads the definitions to write them out as code, and an application declares different ones in different environments -- development declares reloadable beans, which cannot be expressed as generated code. Left at the default the definitions written out are development's, and an application built from them is not the application that was asked for.
Nothing here runs unless the application applies Spring Boot's AOT plugin, which is what asks for generated definitions in the first place.
Wires up the cache the JDK can write for an application, so the next start reads what a training run worked out rather than working it out again.
Three steps, because the cache is only usable against the layout it was trained on: the
archive is extracted, the extracted application is run and asked for its pages, and what the
run recorded is left beside it. An application asks for this with
grails.aotCache.enabled, and says which of its pages matter.
Records the message bundles this artifact ships into META-INF/grails/i18n.properties.
Spring Boot's message source is configured with an explicit base-name list, which nothing at
runtime can discover without scanning the classpath. Writing the answer here lets the runtime
read it back through an exact-name resource lookup instead — no classpath*:*.properties
scan, and therefore no wildcard resource metadata needed for a native image.
The task reads the bundle sources, not the processed resources: native2ascii
and EscapeUnicode rewrite bundle contents but never file names, so there is no need to
order this after them and no risk of a processResources dependency cycle.
Configures JVM arguments required for compatibility with Java 23+.
Java 24 introduced restrictions on native access (JEP 472) that cause
warnings from libraries such as hawtjni (used by JLine) and Netty that call
System.loadLibrary or declare native methods. The
--enable-native-access=ALL-UNNAMED flag suppresses these warnings and
will become mandatory in a future JDK release when the default changes to deny.
Java 23 began terminal deprecation of sun.misc.Unsafe memory-access
methods (JEP 471/498). Netty 4.1.x uses Unsafe.allocateMemory
for off-heap buffers. The --sun-misc-unsafe-memory-access=allow flag
suppresses the resulting warnings until Netty migrates to MemorySegment
APIs (Netty 4.2+).
Both flags are only added when the target JVM version (from the configured
toolchain, or the JVM running Gradle if no toolchain is set) is high enough to
recognize them, avoiding Unrecognized option errors on older JDKs.
project - the Gradle projectWhat a Grails application needs of a native image that an image cannot work out for itself.
Applications resolve calls through invokedynamic here, because the classic call site defines a class as it runs and an image has no way to define one. The framework has to be built the same way. This is a convention, so an application that has said otherwise keeps what it said.
Nothing here runs unless the application applies GraalVM's plugin, which is what asks for an image in the first place. An application that never builds one is untouched.
Records the application's own classes and pages so a native image keeps them usable. The build output already names both, so an application does not have to be traced to be buildable.
Records the reflection a running application does, which is the half of an image's metadata that reading the build output cannot supply.
generateNativeMetadata writes down the application's own artefacts without running
anything. What it cannot see is the framework reflecting along a request path -- a controller
method reached through Groovy's dispatch, a conversion asked for while binding a form -- and an
image built without those starts, serves its home page, and fails on the first request that
needs one.
Run deliberately rather than as part of a build: it starts the application, and what it writes belongs in the sources beside the code, where the next person can see which paths an image was built to cover.
Packages src/main/templates into the main resources as META-INF/templates.
Grails plugins override this: they stage templates through the copyTemplates task
into a directory of their own so that a plugin's templates are not subject to the resource
filters processResources applies to grails-app resource directories.
Configures JavaExec tasks to inherit the project's Java toolchain.
Gradle's JavaPlugin already sets toolchain conventions on
JavaCompile, Javadoc, and Test tasks, but does
not set them on JavaExec tasks. This means forked
JVM processes (dbm-* migration tasks, console, shell, and application
context commands) use the JDK running Gradle instead of the project's
configured toolchain. When the project targets a different JDK version
than the one running Gradle, this causes UnsupportedClassVersionError
or silent runtime failures.
This method only acts when the user has explicitly configured a toolchain
via java.toolchain.languageVersion. When no toolchain is configured,
behavior is unchanged - tasks use the JDK running Gradle as before.
Uses convention() so that individual tasks can still override
the launcher via javaLauncher.set(...) if needed.
project - the Gradle projectEnables native2ascii processing of resource bundles
The artifact.name recorded in the i18n descriptor. For an application this is only
diagnostic; GrailsPluginGradlePlugin overrides it with the Grails plugin name, which
both namespaces the plugin's base names and links the descriptor to the plugin the runtime
discovers.
The artifact.type recorded in the i18n descriptor. Applications and plugins are
distinguished so that message precedence can put the application's own bundles ahead of every
plugin's, which classloader enumeration order can never express.
Validates that a Micronaut-compatible BOM is applied as an enforcedPlatform when micronaut is used. The grails-micronaut-bom (and its hibernate-specific variants) layers Micronaut-specific overrides (e.g. javaparser-core) on top of grails-base-bom; without enforcedPlatform, Micronaut's platform would override these versions via Gradle's conflict resolution. Regular Grails projects (without Micronaut) should continue to use the spring-managed versions via plain platform(:grails-bom).