Using Flyway with the aws-mysql-jdbc driver - how to set custom driver?
skagedal
Posts: 4 New member
Hello! I'm trying to set up Flyway to use AWS own jdbc driver for MySQL, see https://github.com/awslabs/aws-mysql-jdbc. These connection URL:s start with `jdbc:mysql:aws:`. If I use flyway-core 9.16.1 together with flyway-mysql, this works in that it will accept the URL:s and run migrations. However, it will still use the MySQL Connector/J driver. I would prefer to not have that on the classpath at all. If I don't, it fails:
org.flywaydb.core.api.FlywayException: Unable to instantiate JDBC driver: com.mysql.cj.jdbc.Driver => Check whether the jar file is present
So I've been trying to set the driver to the aws-jdbc-sql one, using the method described here: https://documentation.red-gate.com/fd/driver-184127498.html
However, there exists no method "driver" on the FluentConfiguration object returned by Flyway.configure(). It also doesn't seem to respect if try to set it through Java properties.
Is there a way to make this work?
Regards, Simon
org.flywaydb.core.api.FlywayException: Unable to instantiate JDBC driver: com.mysql.cj.jdbc.Driver => Check whether the jar file is present
So I've been trying to set the driver to the aws-jdbc-sql one, using the method described here: https://documentation.red-gate.com/fd/driver-184127498.html
However, there exists no method "driver" on the FluentConfiguration object returned by Flyway.configure(). It also doesn't seem to respect if try to set it through Java properties.
Is there a way to make this work?
Regards, Simon
Tagged:
Best Answer
-
Peter_Laws Posts: 289 Silver 2Thanks for bearing with me Simon,
This does appear to be an oversight on our part, I've raised a request to get it looked at, as it presently stands our documentation is misleading.
As a work around, you could address the underlying object via ClassicConfiguration the same way the FluentConfiguration typically would, it lacks some of the nicety, but should allow you to progress.E.G
ClassicConfiguration config = new ClassicConfiguration(); config.setUrl("jdbc:h2:mem:db"); config.setUser("sa"); config.setDriver("org.amazon.aura.Driver"); Flyway flyway = new Flyway(config);
Answers
Your approach is what I'd expect, the driver configuration is the appropriate way to define this and once established there should be no need to remove the default driver as it won't be used.
Thought evidently there's some configuration complication, does yours look roughly like this?
$ ./gradlew build > Task :app:compileJava FAILED /Users/simon/code/flyway-driver/app/src/main/java/tech/skagedal/flywaydriver/App.java:10: error: cannot find symbol Flyway.configure().driver("com.mysql.cj.jdbc.Driver"); ^ symbol: method driver(String) location: class FluentConfiguration 1 error FAILURE: Build failed with an exception.
It can also be seen by looking at the code: https://github.com/flyway/flyway/blob/main/flyway-core/src/main/java/org/flywaydb/core/api/configuration/FluentConfiguration.java – there is no `driver` method here.
I've tested this with `flyway-core` version 9.16.3 from Maven Central, and it also matches what I see in code: https://github.com/flyway/flyway/blob/main/flyway-core/src/main/java/org/flywaydb/core/api/configuration/FluentConfiguration.java
Apologies, I've caught up now. While the gradle plugin would need slightly different config, since you linked the page that references such earlier I'm going to assume you allowed for that. Regardless, I'd have expected the flyway core part to work.
I'll dig into it and come back to you.