You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

IDEA中Flyway.migrate失效:无法扫描指定路径SQL迁移文件

Fixing Flyway Migration Scan Error After Running 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 select Refresh 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 to File > Project Structure > Modules, select your main module, then switch to the Resources tab. Make sure src/main/resources is marked as a Resources Root (it should show a blue folder icon). Since db/migration lives 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 to File > Invalidate Caches..., check the box for Clear file system cache and local history, then click Invalidate 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 via gradle idea anymore. Just open your project directly in IDEA by selecting the build.gradle or settings.gradle file. 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 (in application.properties, application.yml, or code) is explicitly pointing to classpath:db/migration. Since your JAR works, this is probably fine, but it never hurts to double-check.


内容的提问来源于stack exchange,提问作者Julian Zhou

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 06:44:36