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 warning after migrating to Gradle 4.0 #1686

Closed
czyzby opened this issue Jun 30, 2017 · 4 comments
Closed

Gradle plugin warning after migrating to Gradle 4.0 #1686

czyzby opened this issue Jun 30, 2017 · 4 comments

Comments

@czyzby
Copy link

@czyzby czyzby commented Jun 30, 2017

Flyway 4.2.0, Gradle 4.0, Postgres 9.6.

All Flyway tasks work as expected from what I can tell, but they generate the following warning on each run:

> Task :db:flywayMigrate
Gradle now uses separate output directories for each JVM language, but this build assumes a single directory for all classes from a source set. This behaviour has been deprecated and is scheduled to be removed in Gradle 5.0

This seems to be an issue with current Gradle plugin implementation.

@sgrimm-sg
Copy link

@sgrimm-sg sgrimm-sg commented Aug 18, 2017

I believe the issue is that Gradle 4 wants plugins to call SourceSetOutput.getClassesDirs() instead of getClassesDir(), since a source set can now have multiple classes dirs.

A naive "fix" is probably as simple as

--- a/flyway-gradle-plugin/src/main/java/org/flywaydb/gradle/task/AbstractFlywayTask.java
+++ b/flyway-gradle-plugin/src/main/java/org/flywaydb/gradle/task/AbstractFlywayTask.java
@@ -303,9 +303,11 @@ public abstract class AbstractFlywayTask extends DefaultTask {
                 JavaPluginConvention plugin = getProject().getConvention().getPlugin(JavaPluginConvention.class);
 
                 for (SourceSet sourceSet : plugin.getSourceSets()) {
-                    URL classesUrl = sourceSet.getOutput().getClassesDir().toURI().toURL();
-                    getLogger().debug("Adding directory to Classpath: " + classesUrl);
-                    extraURLs.add(classesUrl);
+                    for (File classesDir : sourceSet.getOutput().getClassesDirs().getFiles()) {
+                        URL classesUrl = classesDir.toURI().toURL();
+                        getLogger().debug("Adding directory to Classpath: " + classesUrl);
+                        extraURLs.add(classesUrl);
+                    }
 
                     URL resourcesUrl = sourceSet.getOutput().getResourcesDir().toURI().toURL();
                     getLogger().debug("Adding directory to Classpath: " + resourcesUrl);

but this would cause the plugin to stop working with pre-4.0 Gradle versions, and would require the plugin to be built against Gradle 4.x libraries. You could get around that by trying to dynamically invoke the method via reflection; I'm not sure if that's the approach Flyway's maintainers would want to take here.

@axelfontaine axelfontaine added this to the Flyway 5.0.0 milestone Aug 18, 2017
@type11
Copy link

@type11 type11 commented Sep 2, 2017

I have gone in and modified things to be ready for gradle 5 but as mentioned then this breaks everything on pre gradle 4.x. Unfortunately we still need to use gradle 3.x for some things. I get I can use different wrappers for different projects but individual developers are also a consideration not just the build system. Is there no good way to change this for gradle 5 and have it work in gradle 3.x?

@axelfontaine
Copy link
Contributor

@axelfontaine axelfontaine commented Nov 30, 2017

With Flyway 5.0.0 the new minimum supported Gradle version is 3.0. We can't move to 4.0 yet as it is still too recent. If someone wants to contribute a pull request (probably using some reflection) to bridge the gap between Gradle 3.0 and 4.0+, I would be more than glad to merge it.

smoothreggae added a commit to smoothreggae/flyway that referenced this issue Dec 2, 2017
In Gradle 4.x, the method getClassesDir() in SourceSetOutput has been
deprecated in favor of a new method getClassesDirs().

Use reflection to invoke this method, if it is available, so that
consumers using Gradle 4.x are spared the deprecation warning. Fall back
to the original method for consumers using Gradle 3.x.

Fixes flyway#1686
@smoothreggae
Copy link
Contributor

@smoothreggae smoothreggae commented Dec 2, 2017

@axelfontaine, I believe I have something that might work for both Gradle 3.x and Gradle 4.x. I was able to test these changes locally with simple projects using Gradle 3.x/4.x based on https://flywaydb.org/getstarted/firststeps/gradle.

axelfontaine added a commit that referenced this issue Dec 4, 2017
Tackle deprecation warning generated by Gradle 4.x
axelfontaine added a commit to flyway/flywaydb.org that referenced this issue Dec 4, 2017
selliera pushed a commit to selliera/flyway that referenced this issue Dec 7, 2017
Tackle deprecation warning generated by Gradle 4.x
dohrayme pushed a commit to dohrayme/flyway that referenced this issue Feb 3, 2020
In Gradle 4.x, the method getClassesDir() in SourceSetOutput has been
deprecated in favor of a new method getClassesDirs().

Use reflection to invoke this method, if it is available, so that
consumers using Gradle 4.x are spared the deprecation warning. Fall back
to the original method for consumers using Gradle 3.x.

Fixes flyway#1686
dohrayme pushed a commit to dohrayme/flyway that referenced this issue Feb 3, 2020
Tackle deprecation warning generated by Gradle 4.x
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
5 participants
You can’t perform that action at this time.