jdaugherty commented on code in PR #14768:
URL: https://github.com/apache/grails-core/pull/14768#discussion_r2103717124


##########
grails-gradle/plugins/src/main/groovy/org/grails/gradle/plugin/core/GrailsGradlePlugin.groovy:
##########
@@ -768,4 +770,49 @@ class GrailsGradlePlugin extends GroovyPlugin {
         }
         fileCollection
     }
+
+    /**
+     * Configures a task to verify that essential Grails project directories 
exist and creates them if missing.
+     *
+     * This method registers a task named 'verifyGrailsProjectDirectories' 
that creates the following
+     * directories if they do not already exist:
+     * - grails-app/services
+     * - grails-app/domain
+     * - grails-app/taglib
+     * - grails-app/migrations
+     *
+     * Additionally, it sets up dependencies for tasks 
'prepareKotlinBuildScriptModel' and
+     * 'cleanGroovyCompilerConfig' to ensure that the directories are verified 
before these tasks run.
+     *
+     * @param project The Gradle project for which the directories are 
verified and tasks are configured.
+     */
+    private void verifyGrailsProjectDirectories(Project project) {
+        TaskProvider<Task> verifyGrailsProjectDirectoriesTask = 
project.tasks.register('verifyGrailsProjectDirectories')
+
+        def grailsProjectDirectories = ['grails-app/services', 
'grails-app/domain',
+                                 'grails-app/taglib', 'grails-app/migrations']
+
+        verifyGrailsProjectDirectoriesTask.configure { Task task ->
+            task.group = 'build'
+            task.description = 'Ensures essential Grails project directories 
exist and creates them if missing.'
+            task.doFirst {
+                grailsProjectDirectories.each { String dir ->
+                    Directory directory = 
project.layout.projectDirectory.dir(dir)
+                    if (!directory.asFile.exists()) {
+                        directory.asFile.mkdirs()
+                    }
+                }
+            }
+        }
+
+        project.afterEvaluate {
+            // prepareKotlinBuildScriptModel runs when a project is created or 
synced in IntelliJ
+            // cleanGroovyCompilerConfig is run by most other tasks
+            it.tasks.matching { Task task ->

Review Comment:
   This is extremely bad.  It will unwrap every task and initialize them.  
https://docs.gradle.org/current/userguide/task_configuration_avoidance.html 
covers that this shouldn't be used.  Use the .named() approach I mention 
previously.



-- 
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: commits-unsubscr...@grails.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to