Flyway Gradle plugin - Circular dependency

我的梦境 提交于 2019-12-10 21:23:22

问题


I have a project that uses gradle, flyway gradle plugin, mybatis generator and postgres. In my build.gradle, I have:

  compileJava.dependsOn('myBatisGenerator')

I would like to run the flywayMigrate task before myBatisGenerator runs. So I did the following:

        myBatisGenerator.dependsOn('flywayMigrate')

And when I try to run the build using gradle test, I get the following error:

FAILURE: Build failed with an exception.

* What went wrong:
Circular dependency between the following tasks:
:classes
+--- :compileGroovy
|    \--- :compileJava
|         \--- :myBatisGenerator
|              \--- :flywayMigrate
|                   \--- :testClasses
|                        +--- :compileTestGroovy
|                        |    +--- :classes (*)
|                        |    \--- :compileTestJava
|                        |         \--- :classes (*)
|                        \--- :compileTestJava (*)
\--- :compileJava (*)

(*) - details omitted (listed previously)

I am not sure why compileTestJava is being called from within the flywayMigrate plugin. Any ideas how to work around the issue and still have the flyway plugin run before mybatis generator?


回答1:


I took a look at the flyway gradle plugin code (https://github.com/flyway/flyway/tree/master/flyway-gradle-plugin) and my guess is that the flyway tasks depend on the compile tasks in order to support migrations written using the flyway Java api.

The flyway plugin seems to assume that that if the project is a java project then you are using the Java api.

Reading between the lines, it seems that flyway expects you to have a separate gradle sub-project for your migrations.

So, move your migrations to a sub-project called, say, 'migrations'. Then you can do

myBatisGenerator.dependsOn(':migrations:flywayMigrate')

and ':migrations:flywayMigrate' will only depend on ':migrations:compileTestJava' rather than your main ':compileTestJava' (and even then only if 'migrations' is a java project)




回答2:


Alternate workaround: https://github.com/flyway/flyway/issues/775

project.afterEvaluate {
    flywayClean.dependsOn -= testClasses
    flywayMigrate.dependsOn = [processResources, processTestResources]
}


来源:https://stackoverflow.com/questions/22129694/flyway-gradle-plugin-circular-dependency

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!