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 flywayMigrate failing on missing postgresql CopyManager #2355

Closed
sdwarwick opened this issue Apr 14, 2019 · 8 comments

Comments

@sdwarwick
Copy link

commented Apr 14, 2019

Which version and edition of Flyway are you using?

flyway plugin 5.2.4 community edition

If this is not the latest version, can you reproduce the issue with the latest one as well?

(Many bugs are fixed in newer releases and upgrading will often resolve the issue)

this has worked perfectly in a maven POM version for years - there is nothing wrong with the SQL.

Which client are you using? (Command-line, Java API, Maven plugin, Gradle plugin)

gradle plugin 5.2.4

Which database are you using (type & version)?

postgres 10

Which operating system are you using?

windows

What did you do?

(Please include the content causing the issue, any relevant configuration settings, the SQL statement that failed (if relevant) and the command you ran.)

gradle  -v

------------------------------------------------------------
Gradle 5.3.1
------------------------------------------------------------

Build time:   2019-03-28 09:09:23 UTC
Revision:     f2fae6ba563cfb772c8bc35d31e43c59a5b620c3

Kotlin:       1.3.21
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM:          11.0.1 (Oracle Corporation 11.0.1+13)
OS:           Windows 10 10.0 amd64
build.gradle:

plugins {
    id "org.springframework.boot" version "2.1.4.RELEASE"
    id "java"
    id "war"
    id "idea"
    id "io.spring.dependency-management" version "1.0.7.RELEASE"
    id "org.flywaydb.flyway" version "5.2.4"
}

dependencies {
    implementation "org.springframework.boot:spring-boot-starter-actuator"
    implementation "org.springframework.boot:spring-boot-starter-aop"
    implementation "org.springframework.boot:spring-boot-starter-cache"
    implementation "org.springframework.boot:spring-boot-starter-data-jpa"
    implementation "org.springframework.boot:spring-boot-starter-data-solr"
    implementation "org.springframework.boot:spring-boot-starter-freemarker"
    implementation "org.springframework.boot:spring-boot-starter-mail"
    implementation "org.springframework.boot:spring-boot-starter-security"
    implementation "org.springframework.boot:spring-boot-starter-validation"
    implementation "org.springframework.boot:spring-boot-starter-web"
    implementation "org.springframework.session:spring-session-core"
    
    implementation "org.flywaydb:flyway-core:5.2.4"

    compile "org.postgresql:postgresql"  // flyway requires compile , not implementation
.
.
.
excerpt from script

COPY public.condition_components (condition_id, component_id, id, grade) FROM stdin;
3	43	3	B
4	43	4	B
5	43	5	C
\.
What did you expect to see?

migration ok

What did you see instead?

18:30:26.115 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] FAILURE: Build failed with an exception.
18:30:26.115 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]
18:30:26.115 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] * What went wrong:
18:30:26.115 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Execution failed for task ':flywayMigrate'.
18:30:26.115 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] > org/postgresql/copy/CopyManager

18:30:26.120 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]   at org.gradle.execution.plan.DefaultPlanExecutor$ExecutorWorker.run(DefaultPlanExecutor.java:129)
18:30:26.120 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]   at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:63)
18:30:26.120 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]   at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:46)
18:30:26.120 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]   at org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:55)
18:30:26.120 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter] Caused by: java.lang.NoClassDefFoundError: org/postgresql/copy/CopyManager
18:30:26.120 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]   at org.flywaydb.core.internal.database.postgresql.PostgreSQLCopyStatement.execute(PostgreSQLCopyStatement.java:72)
18:30:26.120 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]   at org.flywaydb.core.internal.sqlscript.DefaultSqlScriptExecutor.executeStatement(DefaultSqlScriptExecutor.java:189)
18:30:26.120 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]   at org.flywaydb.core.internal.sqlscript.DefaultSqlScriptExecutor.execute(DefaultSqlScriptExecutor.java:125)
18:30:26.120 [ERROR] [org.gradle.internal.buildevents.BuildExceptionReporter]   at org.flywaydb.core.internal.resolver.sql.SqlMigrationExecutor.execute(SqlMigrationExecutor.java:77)

note the error:

 Caused by: java.lang.NoClassDefFoundError: org/postgresql/copy/CopyManager

not sure what to do!!

@gregkoganvmm

This comment has been minimized.

Copy link

commented Jun 21, 2019

buildscript {
    dependencies {
        classpath 'org.postgresql:postgresql:42.2.6'
    }
}

Seems to work for me

Looks like this is the culprit -

@sdwarwick

This comment has been minimized.

Copy link
Author

commented Jun 21, 2019

should this be the basis of a recommended fix? seems like we need a more general solution as it it tied to a revision number..

@gregkoganvmm

This comment has been minimized.

Copy link

commented Jun 21, 2019

Well, the way I see it, the issue is that the task is relying on the buildscript-scoped classloader to find the driver. I would assume this was affected by gradle 5.x upgrade and related api changes, but I am not too familiar with the gradle plugin api to state this with confidence. As I mentioned, this is a workaround and by no means a permanent solution, since I am sure this is not how it is supposed to work. Hopefully this will get fixed in 6.0 (at least it was tagged for 6).

@sdwarwick

This comment has been minimized.

Copy link
Author

commented Jun 21, 2019

one of two bugs preventing the use of flyway with gradle :-(

@axelfontaine

This comment has been minimized.

Copy link
Member

commented Jun 21, 2019

@gregkoganvmm Thanks for investigating. That makes sense. I must admit I am not 100% sure yet what the best way forward is. In the past we basically patched additional jar file URLs in the root URLClassLoader. Starting with Java 9, this is however no longer possible, hence the code you linked to. That approach works well, except for this one case where we make direct use of driver classes in the code, as opposed to simply loading the driver via reflection like we do for all other cases.

Suggestions welcome.

@sdwarwick

This comment has been minimized.

Copy link
Author

commented Jun 21, 2019

Anything useful in the answers below? Seems like there are solutions that work through java11.

https://stackoverflow.com/questions/60764/how-should-i-load-jars-dynamically-at-runtime

@axelfontaine

This comment has been minimized.

Copy link
Member

commented Jun 21, 2019

@sdwarwick That is exactly what we are already doing. Feel free to dig deeper in the code if you want to have an exact look.

@axelfontaine axelfontaine changed the title gradle flywayMigrate failing on missing postgresql Copymanager - 5.2.4 gradle flywayMigrate failing on missing postgresql CopyManager Jun 21, 2019

axelfontaine pushed a commit to flyway/flywaydb.org that referenced this issue Jun 21, 2019
@axelfontaine

This comment has been minimized.

Copy link
Member

commented Jun 21, 2019

Revisited this and reimplemented all accesses via reflection to fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.