Torsten Crass
Torsten Crass

Reputation: 1299

flyway-ant: No database found to handle jdbc:

I'm trying to set up an ant build calling some of the flyway-ant targets, but I always end up with build failures saying

Flyway Error: No database found to handle jdbc:mariadb://<some_host>:3306/<some_db>

or similar (different JDBC URLs, depending on configuration). In build.xml, I'm referencing a fat jar which definitely contains all classes from flyway-core, flyway-mysql, flyway-ant and various JDBC driver packages, including mariadb, mysql and others:

<path id="tools.lib.classpath" location="path/to/my/fat.jar" />

<path id="flyway.lib.path" refid="tools.lib.classpath" />
<path id="flyway.classpath" >
    <pathelement path="path/to/my/sql/migrations"/>
    <path refid="tools.lib.classpath"/>
</path>
<taskdef uri="antlib:org.flywaydb.ant" resource="org/flywaydb/ant/antlib.xml" classpathref="flyway.lib.path" />

<target name="db-info">
    <property name="flyway.url" value="jdbc:mariadb://<some_host>:3306/<some_db>" />
    <property name="flyway.user" value="some_user" />
    <property name="flyway.password" value="psst!" />
    <flyway:info/>
</target>

The exception has its origin in flyway's org.flywaydb.core.internal.database.DatabaseTypeRegister, where obviously no DatabaseType can be found for MariaDB URLs. (Same problem when using a MySQL URL instead.)

The same flyway setup (same maven packages used like in the fat jar, same jdbc URL) works fine, though, when used from within the actual application under development.

I'm on flyway 8.5.13 (as version-managed by Spring Boot) and flyway-ant 2.19.3.

Any ideas?

Upvotes: 1

Views: 2562

Answers (3)

Torsten Crass
Torsten Crass

Reputation: 11

Don't have enough reputation yet to to comment a comment, hence another top-level post: Thanks, @fungtional, using something along the lines of

<plugin>
    <artifactId>maven-shade-plugin</artifactId>
    <version>...</version>
    <executions>
        <execution>
            <configuration>
                <transformers combine.children="append">
                    <transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
                        <resource>
                            META-INF/services/org.flywaydb.core.extensibility.Plugin</resource>
                    </transformer>
                    ...
                </transformers>
                ...
            </configuration>
        </execution>
    </executions>
</plugin>

works like a charm! Would have loved to flag your comment as working solution...

Upvotes: 0

onlyme
onlyme

Reputation: 4052

I had the same issue and got it resolved with

You should add flyway-mysql dependency.

Maven :

<dependency>
    <groupId>org.flywaydb</groupId>
    <artifactId>flyway-mysql</artifactId>
</dependency>

Gradel:

dependencies {
    compile "org.flywaydb:flyway-mysql"
}

For more detail: flyway-database-mysql

Upvotes: 1

Torsten Crass
Torsten Crass

Reputation: 1299

OK, got it: Flyway's database adapters are provided and loaded as "services" in org.flywaydb.core.internal.plugin.PluginRegister through a call to ServiceLoader.load(Plugin.class, CLASS_LOADER). In both the flyway-core and the flyway-mysql packag, the services are defined in a file called META-INF\services\org.flywaydb.core.extensibility.Plugin, and since my fat jar contained only the former, the MariaDB adapter was not detected. Since it is virtually impossible for a jar to contain two files sharing the same path, I guess I'll have to reconsider my project's packaging... But anyway, mystery solved! :)

Upvotes: 3

Related Questions