Skip to content

Conversation

@jamesfredley
Copy link
Contributor

@jamesfredley jamesfredley commented Sep 18, 2025

The 'migrations' directory is now included in grailsAppResourceDirs, allowing it to be treated as a resource directory alongside 'views', 'i18n', and 'conf'.

resolves: #15078

The underlying issue, which also appears to be true for Grails 6, is that /grails-app/migrations/* are not added to /build/resources/main or the generated war/jar

Due to: #15077, the following is required to test on Windows

tasks.named('assetCompile').configure { enabled = false } 
The 'migrations' directory is now included in grailsAppResourceDirs, allowing it to be treated as a resource directory alongside 'views', 'i18n', and 'conf'.
@jamesfredley jamesfredley self-assigned this Sep 18, 2025
@jamesfredley jamesfredley moved this to In Progress in Apache Grails Sep 18, 2025
@jamesfredley jamesfredley added this to the grails:7.0.0 milestone Sep 18, 2025
@jamesfredley
Copy link
Contributor Author

This fixed bootRun, bootJar and bootWar, but causes a duplication issue with dbm-update

@jamesfredley
Copy link
Contributor Author

> Task :dbmUpdate . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v3.5.6) Grails application running at http://localhost:0 in environment: development ERROR: Exception Details ERROR: Exception Primary Class: IOException ERROR: Exception Primary Reason: Found 2 files with the path 'test-domain.groovy': - file:///C:/Users/james/Documents/IdeaProjects/database-migration-test/grails-app/migrations/test-domain.groovy - file:///C:/Users/james/Documents/IdeaProjects/database-migration-test/build/resources/main/test-domain.groovy Search Path: - C:\Users\james\Documents\IdeaProjects\database-migration-test\grails-app\migrations You can limit the search path to remove duplicates with the liquibase.searchPath setting. Or, if you KNOW these are the exact same file you can set liquibase.duplicateFileMode=WARN. ERROR: Exception Primary Source: H2 2.3.232 (2024-08-11) 
@jdaugherty
Copy link
Contributor

dbm-update has never worked for me in the past. It doesn't load the same context that bootRun does. I'd argue dbm-update should be replaceed by something that just starts the server & shuts down.

@jamesfredley
Copy link
Contributor Author

sourceSets { main { resources { srcDir 'grails-app/migrations' } } } 

which historically was added to build.gradle, but was not auto generated by forge, to accomplish adding /grails-app/migrations/* to /build/resources/main or the generated war/jar, also creates the duplicates issue, so I am moving forward with fixing that also as part of this PR too

Changed DatabaseMigrationCommand to use only ClassLoaderResourceAccessor, removing FileSystemResourceAccessor for changelog location. Updated upgrade guide to note that adding 'grails-app/migrations' to the main sourceSet is no longer necessary, as it is now handled automatically by the Gradle plugin.
Deleted instructions about configuring the migrations folder in Gradle, as this step is no longer necessary or relevant for Grails 4 and above.
@jamesfredley
Copy link
Contributor Author

Resolved duplicates issue and updated docs

Added clarification that manual sourceSet configuration for 'grails-app/migrations' is no longer needed and provided guidance to remove related code from 'build.gradle'.
Copy link
Contributor

@jdaugherty jdaugherty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks there are some code style issues and maybe test failures?

Deleted unused imports for CompositeResourceAccessor and FileSystemResourceAccessor from DatabaseMigrationCommand.groovy to clean up the code.
Updated createResourceAccessor to use CompositeResourceAccessor with either ClassLoaderResourceAccessor or FileSystemResourceAccessor based on the presence of the changelog file in the classpath. This avoids duplicate migrations when files are present in both the classpath and filesystem.
@jamesfredley jamesfredley changed the title Add 'migrations' to grailsAppResourceDirs Add 'migrations' to grailsAppResourceDirs resolve duplicates Sep 20, 2025
@jamesfredley jamesfredley merged commit 2f7330a into 7.0.x Sep 20, 2025
36 checks passed
@jamesfredley jamesfredley deleted the include-migrations-in-resources branch September 20, 2025 14:33
@github-project-automation github-project-automation bot moved this from In Progress to Done in Apache Grails Sep 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants