jdaugherty commented on code in PR #16094:
URL: https://github.com/apache/grails-core/pull/16094#discussion_r3776026654
##########
grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy:
##########
@@ -836,6 +869,39 @@ ${importStatements}
it.destinationDirectory =
project.layout.buildDirectory.dir('assetCompile/assets')
}
}
+ configureAssetsOnTheClasspath(project)
+ }
+
+ /**
+ * Packages the compiled assets where an executable jar can read them.
+ *
+ * <p>The asset pipeline plugin puts them at the root of whatever archive
is built, which is
+ * where a war serves its web content from and is therefore right for a
war. An executable jar
+ * has no web content: it serves assets by reading them off the classpath,
and its classpath is
+ * {@code BOOT-INF/classes} -- so the same assets, at the same place, in a
jar rather than a war,
+ * are packaged but unreachable, and every asset a page asks for is a 404
while the page itself
+ * renders. Adding them under the classpath directory is what makes them
found.</p>
+ *
+ * <p>Only for {@code bootJar}. A war already serves them from the root,
and putting them on its
+ * classpath as well would ship the same bytes twice.</p>
+ */
+ private void configureAssetsOnTheClasspath(Project project) {
+ project.pluginManager.withPlugin(SPRING_BOOT_PLUGIN) {
+ // Read after the build script has run, and by the task the
pipeline registers rather
+ // than by the plugin that registers it: the asset pipeline's
plugin id has changed
+ // once already, and the task name has not.
+ project.afterEvaluate {
Review Comment:
`afterEvaluate` + `findByName` is the pattern this build has been trying to
move away from. `project.tasks.withType(...)`/`named(...).configure { }` on the
`assetCompile` task name, guarded by `pluginManager.withPlugin`, gets the same
laziness without an ordering-sensitive callback.
--
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]