Flyway Gradle插件 - 循环依赖 [英] Flyway Gradle plugin - Circular dependency

查看:1206
本文介绍了Flyway Gradle插件 - 循环依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用gradle,flyway gradle插件,mybatis generator和postgres的项目。在我的build.gradle中,我有:

  compileJava.dependsOn('myBatisGenerator')

我想在运行myBatisGenerator之前运行flywayMigrate任务。所以我做了以下工作:

  myBatisGenerator.dependsOn('flywayMigrate')

当我尝试使用gradle测试运行构建时,出现以下错误:

 失败:生成失败并出现异常。 

*出错:
以下任务之间的循环依赖关系:
:classes
+ ---:compileGroovy
| \ ---:compileJava
| \ ---:myBatisGenerator
| \ ---:flywayMigrate
| \ ---:testClasses
| + ---:compileTestGroovy
| | + ---:类(*)
| | \ ---:compileTestJava
| | \ ---:类(*)
| \ ---:compileTestJava(*)
\ ---:compileJava(*)
$ b $(*) - 细节省略(以前列出)

我不确定为什么compileTestJava是从flywayMigrate插件中调用的。任何想法如何解决这个问题,并仍然有flyway插件之前运行mybatis生成器?

解决方案

我看了一下flyway gradle插件代码( https://github.com/flyway/flyway/ tree / master / flyway-gradle-plugin ),我的猜测是flyway任务取决于编译任务,以便支持使用flyway Java API进行迁移。



flyway插件似乎假设如果项目是一个Java项目,那么您正在使用Java api。



在行之间读取,似乎是flyway希望你有一个单独的Gradle子项目用于你的迁移。所以,把你的迁移移动到一个名为'migrations'的子项目中。然后你可以做

$ p $ c $ myBatisGenerator.dependsOn(':migrations:flywayMigrate')

和':migrations:flywayMigrate'只取决于':migrations:compileTestJava'而不是你的主':compileTestJava' migrations'是一个java项目)


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?

解决方案

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)

这篇关于Flyway Gradle插件 - 循环依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆