Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gradle plugin depends on testClasses #775

Closed
hovinen opened this issue Jun 13, 2014 · 7 comments
Closed

Gradle plugin depends on testClasses #775

hovinen opened this issue Jun 13, 2014 · 7 comments
Milestone

Comments

@hovinen
Copy link

hovinen commented Jun 13, 2014

Currently the Gradle-plugin adds in Java-projects a dependency on testClasses:

flyway-gradle-plugin/src/main/groovy/org/flywaydb/gradle/task/AbstractFlywayTask.groovy:
AbstractFlywayTask() {
    group = 'Flyway'
    project.afterEvaluate {
        if (isJavaProject()) {
            this.dependsOn(project.tasks.testClasses)
        }
    }
    extension = project.flyway
}

In my application, I migrate the schema with Flyway and then, based on the up-to-date schema, generate Java-code which is then compiled. This however results in a circular dependency:

> gradle compileJava
FAILURE: Build failed with an exception.

* What went wrong:
Circular dependency between the following tasks:
:classes
\--- :compileJava
     \--- :generateJooq
          \--- :flywayMigrate
               \--- :testClasses
                    \--- :compileTestJava
                         \--- :classes (*)

BUILD FAILED

I have tried everything of which I can think to fix this, from manually removing the dependency to putting the Flyway-migrations into a subproject. I have come to the conclusion that the only feasible solution is to alter the plugin itself to remove the added dependency. Could you please therefore do so? Thank you.

Best regards

@axelfontaine
Copy link
Contributor

The reason for this chicken and egg situation is the support for Java migrations. You can work around this, by moving the DB migration to a separate module. Your main module then depends on this one and can then generate your classes based on a fully migrated schema.

@hovinen
Copy link
Author

hovinen commented Jun 16, 2014

Thanks for your answer.

I assume that by "module" you mean "project". Please correct me if I am mistaken.

I had tried what you suggested but had one problem: one of my requirements is that the code-generation only be executed when the Flyway-plugin actually performs some migration. I had implemented that feature thus in build.gradle:

generateJooq {
    outputs.upToDateWhen {
        !flywayMigrate.didWork
    }
}

This does not work as given when the Flyway-migrations are in a separate project. It is not clear to me how to do this in that case. My knowledge of Gradle does not cover this case. I would appreciate any tips you might have to fix this. Thank you.

@axelfontaine axelfontaine added this to the Flyway 3.1 milestone Oct 7, 2014
@axelfontaine
Copy link
Contributor

Deferring this change until 4.0 as it breaks existing configurations

@axelfontaine axelfontaine modified the milestones: Flyway 4.0, Flyway 3.1 Oct 16, 2014
@konrad-garus
Copy link

For a workaround you can put this in your buildfile:

project.afterEvaluate {
    project.tasks.each {
        if(it.name.startsWith("flyway")) {
            it.dependsOn -= testClasses
        }
    }
}

@axelfontaine For now how about a property like hasJavaMigrations that would be on by default for backwards compatibility, but that we could toggle off?

@konrad-garus
Copy link

Actually, it appears to be more subtle. Perhaps flywayClean should have no dependencies at all, and flywayMigrate should depend on [processResources, processTestResources]?

In my project I ended up with the following, because I do happen to have the migration scripts in src/main/resources/db/migration:

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

@hovinen
Copy link
Author

hovinen commented Nov 20, 2014

Your workaround worked like a charm. Thanks @konrad-garus !

@axelfontaine
Copy link
Contributor

Fixed as part of #979

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants