jdaugherty commented on code in PR #16398:
URL: https://github.com/apache/grails-core/pull/16398#discussion_r4101938323
##########
grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/views/gsp/GroovyPageForkCompileTask.groovy:
##########
@@ -155,7 +179,7 @@ abstract class GroovyPageForkCompileTask extends
AbstractCompile {
@Override
@PathSensitive(PathSensitivity.RELATIVE)
FileTree getSource() {
- return super.getSource()
+ return super.getSource().plus(generatedViews.asFileTree)
Review Comment:
The problem is the `srcDir` property above rather than this line: it is
still `@InputDirectory`, so the task now fails validation when
`grails-app/views` doesn't exist but there are generated pages to compile.
Before this commit, a scaffolding project compiled from the staged copy,
which always existed. A project with no views had no source, so it was skipped
as NO-SOURCE before validation ran. Now the generated pages make the source
non-empty, and Gradle checks `srcDir` first. I reproduced it with a TestKit
project based on `gsp-compile-classpath`: a `@Scaffold(Integer)` controller, a
template in `src/main/templates/scaffolding`, and no `grails-app/views`.
`compileGroovyPages` fails with:
```
Type 'org.grails.gradle.plugin.views.gsp.GroovyPageForkCompileTask' property
'srcDir' specifies directory '.../grails-app/views' which doesn't exist
```
The same project compiles at 8c955bede4. It also fails for the case this
commit is for, an application whose only scaffolded controllers come from a
plugin, when that application has no views directory. The likeliest way to hit
it is a plugin project that scaffolds controllers but has no views of its own.
`getSource()` already fingerprints the pages, so `srcDir` could be
`@Internal`, or `@InputFiles`, which accepts a missing directory. The forked
compiler already skips a directory that doesn't exist. Could the new test "a
plugin's scaffolded controllers have their pages generated in an application
that scaffolds none of its own" also run `compileGroovyPages` with no
`grails-app/views`? Right now it stops at `generateScaffoldedViews`, which is
why it didn't catch this.
##########
grails-doc/src/en/guide/scaffolding.adoc:
##########
@@ -59,9 +59,15 @@ With this configured, when you start your application the
actions and views will
A CRUD interface will also be generated. To access this open
`http://localhost:8080/book` in a browser.
-The Gradle plugin expands scaffold templates into
`build/generated/scaffolded-views` with `generateScaffoldedViews`. Then
`stageGroovyPages` combines them with application views in
`build/generated/views`, and `compileGroovyPages` compiles them so packaged
applications and native images do not need to generate them on the first
request. Running `compileGroovyPages` runs these prerequisite tasks
automatically. Handwritten views in the application or supplied by a plugin
still take precedence over generated scaffold views.
+When the application is built, the Gradle plugin's `generateScaffoldedViews`
task expands the scaffolding templates for every domain class a controller
scaffolds with `@Scaffold`, the application's or a plugin's, and
`compileGroovyPages` compiles the resulting pages in the same compilation as
the application's views. The templates are expanded by the application's own
scaffolding library and Groovy, in a JVM on its runtime classpath, exactly as
they would be expanded when the view is requested. That library has to match
the Grails Gradle plugin: with a `grails-scaffolding` of another version, the
build warns and compiles no scaffolded page, and the views are expanded on
their first use. A packaged application then renders a scaffolded view without
generating it on the first request, and a native image, which cannot compile a
page at runtime, can render it at all.
Review Comment:
Nit: the task compares the version of the exchange the generator declares,
not the library's version, so a `grails-scaffolding` from another release still
has its pages compiled as long as that exchange hasn't changed. "Of another
version" reads as though any mismatch, a patch release included, turns
compilation off. Maybe: "with a `grails-scaffolding` the plugin cannot work
with, the build warns and compiles no scaffolded page".
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]