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

Gradle plugin does not resolve `implementation`-scoped artifacts, only `compile` #2272

Closed
o-nix opened this issue Jan 23, 2019 · 13 comments

Comments

@o-nix
Copy link

commented Jan 23, 2019

Which version and edition of Flyway are you using?

5.2.4 latest release

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

Gradle plugin

Which database are you using (type & version)?

MariaDB 10.1.37

Which operating system are you using?

macOS High Sierra 10.13.6

What did you do?

(Please include the content causing the issue, any relevant configuration settings, the SQL statement that failed (if relevant) and the command you ran.)

When I run ./gradlew flywayMigrate against an artifact with migration files attached in implementation project(':migrations') the plugin cannot find migration resources.
In the other hand when I change the scope to compile it works.
Migration files are found in the production-ready artifact because Gradle itself is able to include every implementation dependency.

What did you expect to see?

I expect that my project's artifact dependencies are resolved correctly in runtime.

What did you see instead?

An error related to not resolved or missing migrations.

@axelfontaine

This comment has been minimized.

Copy link
Member

commented Jan 23, 2019

Could you post a small example build.gradle file that reproduces this?

@o-nix

This comment has been minimized.

@zhogov

This comment has been minimized.

Copy link

commented Apr 3, 2019

"compile" configuration is deprecated per Gradle docs:

The compile configuration still exists but should not be used as it will not offer the guarantees that the api and implementation configurations provide.

But still used per Flyway docs:

By default the Flyway Gradle plugin uses a classpath consisting of the compile, runtime, testCompile and testRuntime Gradle configurations for loading drivers, migrations, resolvers, callbacks, etc.

Example build.gradle:

plugins {
    id "org.flywaydb.flyway" version "5.2.4"
    id "java"
}

repositories { mavenCentral() }

dependencies {
    implementation group: 'postgresql', name: 'postgresql', version: '9.0-801.jdbc4'
}

flyway {
    url = 'jdbc:postgresql://localhost:5432/mydb'
}

I get following error:

$ ./gradlew flywayMigrate
> Task :flywayMigrate FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':flywayMigrate'.
> Error occurred while executing flywayMigrate
  Unable to instantiate JDBC driver: org.postgresql.Driver => Check whether the jar file is present
  Unable to instantiate class org.postgresql.Driver : org.postgresql.Driver
  org.postgresql.Driver

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 0s
1 actionable task: 1 executed

Works if I replace implementation with compile:

$ ./gradlew flywayMigrate
> Task :flywayMigrate FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':flywayMigrate'.
> Error occurred while executing flywayMigrate

  Unable to obtain connection from database (jdbc:postgresql://localhost:5432/mydb) for user 'null': The server requested password-based authentication, but no password was provided.
  ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  SQL State  : 08004
  Error Code : 0
  Message    : The server requested password-based authentication, but no password was provided.

  The server requested password-based authentication, but no password was provided.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 1s
1 actionable task: 1 executed
@zhogov

This comment has been minimized.

Copy link

commented Apr 3, 2019

So as per @o-nix this can be fixed by changing AbstractFlywayTask.java

@sdwarwick

This comment has been minimized.

Copy link

commented Apr 14, 2019

ran into this as well - need to add Implementation and runtimeOnly!

@johannesloher

This comment has been minimized.

Copy link

commented Jun 18, 2019

I also just ran into this. Is what @o-nix and @zhogov suggested really all that is required to fix this issue?

@axelfontaine

This comment has been minimized.

Copy link
Member

commented Jun 18, 2019

This is configurable as described in the docs: https://flywaydb.org/documentation/gradle/#extending-the-default-classpath

@o-nix

This comment has been minimized.

Copy link
Author

commented Jun 18, 2019

@axelfontaine why do you still think this is a documentation problem? It's a default configuration one.

@johannesloher

This comment has been minimized.

Copy link

commented Jun 18, 2019

@axelfontaine I tried adding "implementation" as a configuration as described in the docs which you linked to. This does not seem to work however, I get the following error message:

Resolving configuration 'implementation' directly is not allowed [...]

Also I think that it should work out of the box with "implementation" and "api" because "compile" has been deprecated and is supposed to be replaced by "implementation" or "api" depending on the context.

@axelfontaine

This comment has been minimized.

Copy link
Member

commented Jun 18, 2019

@johannesloher The new set of configurations is available here: https://docs.gradle.org/current/userguide/java_plugin.html#sec:java_plugin_and_dependency_management

It's interesting that the Gradle team decided to make some of them non-resolvable. Would you like to dig into the plugin code to see how this could be fixed?

@sdwarwick

This comment has been minimized.

Copy link

commented Jun 21, 2019

@axelfontaine this is a blocking bug for using the gradle plugin on the current version of gradle.

@axelfontaine

This comment has been minimized.

Copy link
Member

commented Jun 21, 2019

@sdwarwick Would you like to dig in and look how this could be resolved?

axelfontaine pushed a commit to flyway/flywaydb.org that referenced this issue Jun 21, 2019

@axelfontaine axelfontaine added this to the Flyway 6.0.0 milestone Jun 21, 2019

@axelfontaine

This comment has been minimized.

Copy link
Member

commented Jun 21, 2019

Made defaults vary based on Gradle version. New default configuration names for Gradle 4.x and newer are now compileClasspath, runtimeClasspath, testCompileClasspath, testRuntimeClasspath and can already be configured in existing versions of the plugin as described in the docs: https://flywaydb.org/documentation/gradle/#extending-the-default-classpath

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants
You can’t perform that action at this time.