jdaugherty commented on code in PR #14768: URL: https://github.com/apache/grails-core/pull/14768#discussion_r2103716672
########## 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 { Review Comment: After evaluate is the wrong solution here. it should be only used if you can't configure the other tasks. It's better to grab the tasks lazily and then configure them to depend on your task. project.tasks.named('prepareKotlinBuildScriptModel').configure { it.dependsOn(verifyGrailsProjectDirectoriesTask) } -- 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