3

Running the Maven flyway-plugin

mvn flyway:migrate

with this configuration:

    <plugin>
      <groupId>org.flywaydb</groupId>
      <artifactId>flyway-maven-plugin</artifactId>
      <version>4.0.3</version>
      <configuration>
        <driver>com.mysql.jdbc</driver>
        <url>jdbc:mysql://localhost:3306/schema2?createDatabaseIfNotExist=true</url>
        <user>root</user>
        <password>root</password>
      </configuration>
    </plugin>

I try to create number of executions like in this solution: How to use Flyway configuration to handle multiple databases

Start from one execution:

    <plugin>
      <groupId>org.flywaydb</groupId>
      <artifactId>flyway-maven-plugin</artifactId>
      <version>4.0.3</version>
      <executions>
        <execution>
          <id>migrate-database</id>
          <phase>compile</phase>
          <goals>
            <goal>migrate</goal>
          </goals>
          <configuration>
            <driver>com.mysql.jdbc</driver>
            <url>jdbc:mysql://localhost:3306/schema2?createDatabaseIfNotExist=true</url>
            <user>root</user>
            <password>root</password>
          </configuration>
        </execution>
      </executions>
    </plugin>

See exception:

[ERROR] Failed to execute goal org.flywaydb:flyway-maven-plugin:4.0.3:migrate (default-cli) on project UrbanLife: org.flywaydb.core.api.FlywayException: Unable to connect to the database. Configure the url, user and password! -> [Help 1]

Looks like flyway can't see configuration inside (Interesting that, in link, I mentioned before, it works)

Please help to create flyway multyDB integration via maven.

Community
  • 1
  • 1
JavaDev1987
  • 103
  • 9
  • Two answers below helped me. Now I use next command: mvn flyway:migrate@migrate-MAINdatabase flyway:migrate@migrate-TESTdatabase – JavaDev1987 Oct 04 '16 at 11:33
  • @markdsievers why you removed phrases about console from my question? It's more understandable for novice. – JavaDev1987 Oct 04 '16 at 11:36

2 Answers2

3

When you have multiple (or just one) <execution> in your maven plugin configuration and are attempting to run a specific execution from the command line you need to specify the execution by the execution id like so in your case

mvn flyway:migrate@migrate-database

see also: How to execute maven plugin execution directly from command line?

Lastly, if you want a specific execution to be the default, you can give it the execution id of default-cli as explained in these maven docs. Then you can simply run mvn flyway:migrate.

Community
  • 1
  • 1
Phil
  • 1,226
  • 10
  • 20
1

The FQN of the driver is incorrect, it should be com.mysql.jdbc.Driver or you could also simply remove it as it will be auto-detected from the URL.

You will also need to add the driver as dependency of your plugin by adding

<plugin>
    ...
    <dependencies>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.39</version>
        </dependency>
    </dependencies>
</plugin>
Nicolas Filotto
  • 43,537
  • 11
  • 94
  • 122