IDEA中Flyway.migrate失效:无法扫描指定路径SQL迁移文件
gradle idea in IntelliJ IDEA I’ve dealt with this exact headache before—let’s break down what’s going on and how to get your project running in IDEA again:
Why This Happens
When you run gradle idea, Gradle generates fresh IntelliJ project files (like .iml and .ipr). More often than not, this process overrides IDEA’s default classpath configuration, making it lose track of the db/migration resources Flyway needs. Since your JAR runs perfectly, the resources are correctly packaged—this is purely an IDE configuration glitch, not a problem with your code or Flyway setup.
Step-by-Step Fixes
Refresh Gradle Project in IDEA
Open the Gradle tool window (usually on the right sidebar), right-click your project, and selectRefresh Gradle Project. This forces IDEA to sync its settings with Gradle’s actual resource mappings, which usually fixes the classpath mismatch immediately.Check Module Resource Markers
Head toFile > Project Structure > Modules, select your main module, then switch to theResourcestab. Make suresrc/main/resourcesis marked as a Resources Root (it should show a blue folder icon). Sincedb/migrationlives inside this directory, IDEA will include it in the runtime classpath once this setting is correct.Wipe IDEA Caches
Stale cached data can cause weird, unexplained issues. Go toFile > Invalidate Caches..., check the box forClear file system cache and local history, then clickInvalidate and Restart. This clears out any old configuration that might be blocking Flyway from finding your migration files.Ditch
gradle idea(Long-Term Solution)
IntelliJ IDEA has native, reliable Gradle support—you don’t need to generate project files viagradle ideaanymore. Just open your project directly in IDEA by selecting thebuild.gradleorsettings.gradlefile. IDEA will auto-configure itself correctly, and you’ll avoid these classpath headaches entirely.Quick Flyway Config Sanity Check
Just to be thorough: confirm your Flyway configuration (inapplication.properties,application.yml, or code) is explicitly pointing toclasspath:db/migration. Since your JAR works, this is probably fine, but it never hurts to double-check.
内容的提问来源于stack exchange,提问作者Julian Zhou

