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

Cannot load migration SQL scripts from the root of the classpath in a jarfile #1498

Closed
albertmatyi opened this issue Dec 28, 2016 · 3 comments
Closed

Comments

@albertmatyi
Copy link

@albertmatyi albertmatyi commented Dec 28, 2016

What version of Flyway are you using?

4.0.1

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

JAVA API

What database are you using (type & version)?

mariadb 10.1.7
mysql client 5.5

What operating system are you using?

linux x64
4.8.13-1-ARCH #1 SMP PREEMPT Fri Dec 9 07:24:34 CET 2016 x86_64 GNU/Linux

What did you do?

Created a FlywayMigrator class file with public static main method ( code in groovy)

package com.wewash.backend

import org.flywaydb.core.Flyway

class FlywayMigrator {
    static void main(String[] args) {
        Flyway flyway = new Flyway()
        flyway.setLocations(".", "/", "classpath:.", "classpath:/", "classpath:*.sql")
        print(flyway.getLocations())
        flyway.setDataSource(
            "jdbc:mysql://localhost:3310/wewash",
            "root",
            "")
        flyway.migrate()
    }

}

and compiled it into a jar with the migration scripts, which can be found at the root of the jar

What did you expect to see?

I exepected that java -jar app.jar runs the migrations

What did you see instead?

Flyway cannot scan the root of the classpath.

The whole thing only works if i put the scripts in a subfolder.

What I've tried

I've tried debugging the code, and it seems that ClassPathScanner:201/2 is the culprit

} else { 
            Enumeration<URL> urls = classLoader.getResources(location.getPath()); // 201
            if (!urls.hasMoreElements()) { //202
                LOG.warn("Unable to resolve location " + location); // 203
            }

because it evaluates to a failing location interpretation, it treats it as if the root of the classpath could not be resolved.

@albertmatyi albertmatyi changed the title fa Cannot load migration SQL scripts from the root of the classpath in a jarfile Dec 28, 2016
@axelfontaine axelfontaine added this to the Flyway 5.0 milestone Feb 7, 2017
@kopax
Copy link

@kopax kopax commented Nov 5, 2017

I have this issue.
I have a root project that configure sub project.
I am trying to run migration command from gradle and it can't find any classpath.
How did you solved it for flyway 4.2.0 and when is flyway 5.0 scheduled?

Also is it possible to run the migration using the java api and how can I do it?

@axelfontaine axelfontaine removed this from the Flyway 5.0.0 milestone Nov 29, 2017
@axelfontaine axelfontaine added this to the Flyway 5.1.0 milestone Nov 29, 2017
@axelfontaine axelfontaine removed this from the Flyway 5.1.0 milestone Dec 18, 2017
@axelfontaine axelfontaine added this to the Flyway 5.0.3 milestone Dec 18, 2017
@axelfontaine
Copy link
Contributor

@axelfontaine axelfontaine commented Dec 18, 2017

The correct syntax is classpath:. We'll make changes to fail fast on the other variants.

@axelfontaine axelfontaine removed this from the Flyway 5.0.3 milestone Dec 20, 2017
@axelfontaine axelfontaine added this to the Flyway 5.1.0 milestone Dec 20, 2017
@axelfontaine axelfontaine removed this from the Flyway 5.1.0 milestone Dec 20, 2017
@axelfontaine axelfontaine added this to the Flyway 5.0.4 milestone Dec 20, 2017
@axelfontaine
Copy link
Contributor

@axelfontaine axelfontaine commented Dec 28, 2017

This has now been fixed.

axelfontaine added a commit to flyway/flywaydb.org that referenced this issue Dec 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants