I have tracked the error and it happens on this li...
# questions
p
I have tracked the error and it happens on this line https://github.com/grails/grails-database-migration/blob/4.2.x/src/main/groovy/org[…]lugins/databasemigration/liquibase/GroovyChangeLogParser.groovy I can't make it work to run the migrations on start
t
I don't recall personally ever seeing that error before. Do you have a file at
grails-app/migrations/changelog.groovy
? Also, what version of Grails are you using and what version of the DBM plugin?
👍 1
w
You are getting that because physicalChangeLogLocation did not return anything so .first() throws an exception when there are no elements. Potential Workarounds Since the library code itself is making this “unsafe” call, you’ll need to address the root cause (the missing file) rather than patching the code: 1. Verify the Location: Double-check your
grails.database.migration.changelog
setting in
application.yml
or
Config.groovy
. 2. Check Resource Loading: Ensure that if you are using a
.groovy
changelog, it is located in a directory that is being compiled/copied to your classpath (usually
grails-app/conf/migrations/
or
src/main/resources/
). 3. Liquibase Verbose Logging: Increase logging for
liquibase
and
org.grails.plugins.databasemigration
to
DEBUG
to see exactly what path
physicalChangeLogLocation
is trying to resolve right before it fails.
p
yes, the file is there
grails-app/migrations/changelog.groovy
"You are getting that because physicalChangeLogLocation did not return anything so .first() throws an exception when there are no elements" I know that, that's why I pointed to the exact line in the code.
w
Did you look at the source code for SpringLiquibase.java: for your version?
p
I'm using these in Grails 5.x: implementation 'org.liquibaseliquibase core4.19.0' implementation 'org.grails.pluginsdatabase migration4.2.1'
w
Its throwing the exception in the Spring library
p
Didn't look at that class since the exception I saw seems to come from GroovyChangeLogParser.groovy, but that might also come from elsewhere, the issue is that I'm following the docs and getting an error, I don't know if looking at the code would help a lot.
I already did all the tries with ChatGPT with all the options it provided but nothing worked.
w
You should be able to check the version of the spring library, dl the source jar and debug with your IDE.
The groovy code is a wrapper for almost everything except for The ChangeLog
and some other calls
p
sure, but I can't fix that code, because config wise it seems I have it like the docs say, though ChatGPT mentioned that my changelog.groovy might not be in the classpath Liquibase looks for and suggested to change the migrations to another directory under src.
w
Sure, but you need to figure out if it is a bug in liquibase hibernate code, the spring library, the groovy code or a misconfiguration
p
sure, but I don't have time to debug 4 different libs, I already spend almost two hours trying stuff with chatGPT, asking here was my last try
w
If fed your situation to Grok: It has some suggestions: The root cause is almost certainly that Liquibase (via the database-migration plugin) cannot locate or load the changelog file you specified. The exact
NoSuchElementException: Cannot access first() element from an empty Iterable
is what the Grails database-migration plugin + Liquibase throws internally when
updateOnStartFileName
points to a file that does not exist, is not on the classpath at runtime, or results in an empty/ unparseable changelog (no
databaseChangeLog = { ... }
block or no changesets). This matches known behavior reported in the plugin’s GitHub issues (e.g., the same error appears instantly if you give a wrong filename). ### Quick checks/fixes (in order of likelihood) 1. Does the file actually exist? It must be at:
grails-app/migrations/changelog.groovy
(this is the default
changelogLocation
+ your
updateOnStartFileName
). It should start with something like:
Copy code
groovy
   databaseChangeLog = {
       // your changesets or includeFile statements here
   }
If the file is missing, empty, or just
databaseChangeLog = {}
, you get exactly this error. 2. Production/WAR deployment issue (very common in Grails 6/7) In
grails run-app
(dev) the file is read from disk, so it often works. In a WAR deployed to Tomcat/JBoss/etc. the
grails-app/migrations
folder is not automatically on the classpath unless you tell Gradle about it. Add this to
build.gradle
before the
dependencies
block:
Copy code
groovy
   sourceSets {
       main {
           resources {
               srcDir ‘grails-app/migrations’
           }
       }
   }
Then rebuild the WAR (
grails war
or
./gradlew war
) and redeploy. 3. Grails 7 + plugin version The old
grails-database-migration
plugin was moved into the GORM Hibernate ecosystem for Grails 7. Make sure you are on a Grails-7-compatible version (5.x series):
Copy code
groovy
   dependencies {
       implementation ‘org.grails.plugins:database-migration:5.0.0’  // or latest from releases
       // Strongly recommended – Spring Boot pulls in an older Liquibase
       implementation ‘org.liquibase:liquibase-core:4.27.0’  // or whatever the 5.x plugin recommends
   }
Also exclude the old Spring Boot CLI dependency if you see conflicts:
Copy code
groovy
   implementation(‘org.grails.plugins:database-migration:5.0.0’) {
       exclude module: ‘spring-boot-cli’
   }
4. Configuration location Your YAML looks correct, but just to be sure it ends up in
application.yml
(or
application-prod.yml
) as:
Copy code
yaml
   grails:
     plugin:
       databasemigration:
         updateOnStart: true
         updateOnStartFileName: changelog.groovy
         # optionally:
         # changelogLocation: grails-app/migrations   # default
Do not use the old
grails.plugin.databasemigration.
property style in YAML – the nested form you have is fine. ### Other quick things to rule out - Run
grails dbm-validate
or
grails dbm-update
manually – if that also fails with a file-not-found, the file is definitely the problem. - If you are using contexts, make sure
updateOnStartContexts
is not filtering everything out. - Clean and rebuild:
grails clean && grails war
(or
./gradlew clean bootWar
). After fixing the file location/packaging, the startup migration should run without the
first()
exception. This exact stack trace has been reported on Grails 6 + Tomcat and is the classic symptom of “changelog file not found at runtime.” Let me know what you see after checking the file existence and the
sourceSets
addition!
I agree with its troubleshooting