@org.gradle.api.tasks.CacheableTask @groovy.transform.CompileStatic abstract class GenerateScaffoldedViewsTask extends DefaultTask
Writes the views a scaffolded controller would otherwise generate on its first request.
Scaffolding expands a template into GSP source and compiles the result, and until now it did both when the view was first asked for. That costs the first request on the JVM, and a native image cannot do it at all: defining a class at runtime is exactly what an ahead-of-time image gives up. Expanding the templates here instead lets the ordinary GSP compiler precompile the result, so at runtime the views are found rather than produced.
Only naming is substituted -- the templates read className, propertyName,
fullName and packageName, and defer everything else about the domain class to the
field tag libraries at render time. That is why this needs no GORM, no application context and no
loading of application classes: the controllers are read with ASM and the domain class name is
enough. The qualified name is bound too, so that a template can declare the type of its model in a
form that resolves from the generated page.
A view the application already declares is never overwritten, which keeps the existing
precedence: a hand-written grails-app/views page wins over a scaffolded one.
| Constructor and description |
|---|
GenerateScaffoldedViewsTask() |
| Type Params | Return Type | Name and description |
|---|---|---|
|
void |
generate() |
|
abstract ConfigurableFileCollection |
getApplicationViews()The application's own views; anything declared here is left alone. |
|
abstract ConfigurableFileCollection |
getClassesDirs()Compiled application classes, searched for scaffolded controllers. |
|
abstract DirectoryProperty |
getOutputDirectory()Where the generated views are written. |
|
abstract ConfigurableFileCollection |
getTemplateClasspath()The classpath the scaffolding templates are read from. |
|
abstract ConfigurableFileCollection |
getTemplateOverrides()Application template overrides, normally src/main/templates/scaffolding. |
The application's own views; anything declared here is left alone.
Compiled application classes, searched for scaffolded controllers.
Where the generated views are written.
The classpath the scaffolding templates are read from. The application's own
src/main/templates/scaffolding takes precedence, matching the runtime lookup.
Application template overrides, normally src/main/templates/scaffolding.