简体   繁体   English

Flyway Gradle插件 - 循环依赖

[英]Flyway Gradle plugin - Circular dependency

I have a project that uses gradle, flyway gradle plugin, mybatis generator and postgres. 我有一个项目,使用gradle,flyway gradle插件,mybatis生成器和postgres。 In my build.gradle, I have: 在我的build.gradle中,我有:

  compileJava.dependsOn('myBatisGenerator')

I would like to run the flywayMigrate task before myBatisGenerator runs. 我想在myBatisGenerator运行之前运行flywayMigrate任务。 So I did the following: 所以我做了以下事情:

        myBatisGenerator.dependsOn('flywayMigrate')

And when I try to run the build using gradle test, I get the following error: 当我尝试使用gradle测试运行构建时,我收到以下错误:

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. 我不确定为什么要从flywayMigrate插件中调用compileTestJava。 Any ideas how to work around the issue and still have the flyway plugin run before mybatis generator? 任何想法如何解决这个问题,并仍然在mybatis生成器之前运行flyway插件?

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. 我看了一下flyway gradle插件代码( https://github.com/flyway/flyway/tree/master/flyway-gradle-plugin ),我的猜测是,flyway任务依赖于编译任务以便支持使用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. flyway插件似乎假设如果项目是一个java项目,那么你正在使用Java api。

Reading between the lines, it seems that flyway expects you to have a separate gradle sub-project for your migrations. 在各行之间阅读,似乎flyway希望您为迁移创建一个单独的gradle子项目。

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) 和':migrations:flywayMigrate'将仅依赖于':migrations:compileTestJava'而不是你的主':compileTestJava'(即使那时只有'migrations'是一个java项目)

Alternate workaround: https://github.com/flyway/flyway/issues/775 替代解决方法: https//github.com/flyway/flyway/issues/775

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM