Skip to content

Commit

Permalink
Fixed #1923: Flyway Maven Plugin can't find JDBC driver if the driver…
Browse files Browse the repository at this point in the history
… is a dependency with scope provided
  • Loading branch information
Axel Fontaine committed Feb 13, 2018
1 parent 583c9a8 commit 1e5ad1f
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 11 deletions.
2 changes: 1 addition & 1 deletion flyway-core/pom.xml
Expand Up @@ -242,7 +242,7 @@
<plugins>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.9.1</version>
<version>3.0.0</version>
<configuration>
<encoding>UTF-8</encoding>
<sourceFileIncludes>
Expand Down
Expand Up @@ -22,7 +22,9 @@
import org.flywaydb.core.internal.util.logging.slf4j.Slf4jLogCreator;

/**
* Factory for loggers.
* Factory for loggers. Custom MigrationResolver, MigrationExecutor, FlywayCallback, ErrorHandler and JdbcMigration
* implementations should use this to obtain a logger that will work with any logging framework across all environments
* (API, Maven, Gradle, CLI, etc).
*/
public class LogFactory {
/**
Expand Down
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/
/**
* Interfaces for Flyway's log abstraction.
* Interfaces for Flyway's log abstraction. Custom MigrationResolver, MigrationExecutor, FlywayCallback, ErrorHandler and JdbcMigration
* implementations should use this to obtain a logger that will work with any logging framework across all environments
* (API, Maven, Gradle, CLI, etc).
*/
package org.flywaydb.core.api.logging;
43 changes: 43 additions & 0 deletions flyway-maven-plugin/pom.xml
Expand Up @@ -69,6 +69,21 @@





















Expand Down Expand Up @@ -129,6 +144,34 @@































</plugins>
</build>
</project>
Expand Up @@ -17,7 +17,6 @@

import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
Expand All @@ -41,8 +40,10 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static org.flywaydb.core.internal.configuration.ConfigUtils.putArrayIfSet;
import static org.flywaydb.core.internal.configuration.ConfigUtils.putIfSet;
Expand Down Expand Up @@ -214,6 +215,7 @@ abstract class AbstractFlywayMojo extends AbstractMojo {
* <p>
* <p>Sql migrations have the following file name structure: prefixVERSIONseparatorDESCRIPTIONsuffix ,
* which using the defaults translates to V1_1__My_description.sql</p>
*
* @deprecated Use {@link AbstractFlywayMojo#sqlMigrationSuffixes} instead. Will be removed in Flyway 6.0.0.
*/
@Parameter(property = ConfigUtils.SQL_MIGRATION_SUFFIX)
Expand Down Expand Up @@ -505,7 +507,7 @@ private void loadCredentialsFromSettings() throws FlywayException {
return mavenPropertyValue;
}

public final void execute() throws MojoExecutionException, MojoFailureException {
public final void execute() throws MojoExecutionException {
LogFactory.setLogCreator(new MavenLogCreator(this));
log = LogFactory.getLog(getClass());

Expand All @@ -515,9 +517,14 @@ public final void execute() throws MojoExecutionException, MojoFailureException
}

try {
Set<String> classpathElements = new HashSet<>();
classpathElements.addAll(mavenProject.getCompileClasspathElements());
classpathElements.addAll(mavenProject.getRuntimeClasspathElements());
System.out.println("CPE: " + classpathElements);

This comment has been minimized.

Copy link
@NicoTexas

NicoTexas Feb 18, 2018

Will be a long list printed on some projects! :)


ClassRealm classLoader = (ClassRealm) Thread.currentThread().getContextClassLoader();
for (String runtimeClasspathElement : mavenProject.getRuntimeClasspathElements()) {
classLoader.addURL(new File(runtimeClasspathElement).toURI().toURL());
for (String classpathElement : classpathElements) {
classLoader.addURL(new File(classpathElement).toURI().toURL());
}

if (locations != null) {
Expand Down
26 changes: 22 additions & 4 deletions pom.xml
Expand Up @@ -77,7 +77,6 @@




</modules>

<distributionManagement>
Expand Down Expand Up @@ -419,7 +418,7 @@
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.1</version>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
Expand Down Expand Up @@ -459,7 +458,7 @@
</plugin>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.1</version>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
Expand Down Expand Up @@ -620,6 +619,25 @@

























Expand Down Expand Up @@ -653,7 +671,7 @@
<plugins>
<plugin>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.10.1</version>
<version>3.0.0</version>
<configuration>
<encoding>UTF-8</encoding>
<failOnError>false</failOnError>
Expand Down

0 comments on commit 1e5ad1f

Please sign in to comment.