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

Modernize build and fix deprecated gradle API usages #1476

Merged
merged 23 commits into from
Aug 15, 2019

Conversation

ZacSweers
Copy link
Contributor

@ZacSweers ZacSweers commented Aug 6, 2019

This fixes a number of deprecated API usages found in my own project, and also brings the project up to speed with modern gradle and AGP versions

@@ -19,7 +19,7 @@ ext.androidConfig = [
]

ext.dep = [
androidPlugin : 'com.android.tools.build:gradle:3.3.0',
androidPlugin : 'com.android.tools.build:gradle:3.4.1',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3.4.2?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix 👍

@@ -46,7 +46,7 @@ class ApolloExtension {
outputPackageName = project.objects.property(String.class)
outputPackageName.set("")

customTypeMapping = project.objects.property(Map.class)
customTypeMapping = project.objects.mapProperty(String.class, String.class)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe these were included in Gradle 4.x. Readme says 4.3 is required. Would be good to double check if 4.3 is fine or need to update the requirement in the Readme.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can check, but also feel like only supporting current major version should be fine too. Gradle is already on 5.5, and these APIs are also not stable yet

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My Sample changes is merged. If you update your branch then you will have the sample. Sample now uses a separate project with composite builds. We can quickly try with different set of Gradle versions there. By changing the wrapper on the sample.

@ZacSweers
Copy link
Contributor Author

So the minimum supported gradle version for current AGP (3.4.2) is 5.1.1. I think that should settle it?

@tasomaniac
Copy link
Contributor

Hmm, think this as minSdk vs compileSdk on Android. This plugin depends on AGP 3.4.2 but works fine with older versions. In fact it work with java/Kotlin only projects where there is no AGP dependency at all.

It's just that we need to figure out which versions we support at minimum and document that in README

@ZacSweers
Copy link
Contributor Author

So I'm personally a big proponent of just supporting the current major version. For AGP that's 3.4.0, and for gradle that's 5.x. We can even actually easily set up tests for this on travis (example), but it's much harder to test this regularly if it requires lowering both AGP and gradle versions every time

@tasomaniac
Copy link
Contributor

Gradle testing APIs support integration testing the plugin across different versions. Testing against different version of AGP is also possible. Of course that is out of scope here.

@tasomaniac
Copy link
Contributor

Looks like there are some changes which affects the integration module

Failed to apply plugin [id 'com.apollographql.android']
Could not get unknown property 'SourceDirectorySet' for source set android test of type com.android.build.gradle.internal.api.DefaultAndroidSourceSet.

@ZacSweers
Copy link
Contributor Author

Fixed the source directory set bit, just accidentally lost an import in a rebase.

As for testing gradle 4.3, even if I lower back down to AGP 3.3.0, the min gradle version is still 4.10.1. This does fail on one new source directory set API

3.2.1 requires gradle 4.6 (feb 2018). This also fails on the new source directory set API

4.3 was October 2017. Not sure

So in short - this would require gradle 5.x effectively. I think this is reasonable as it matches the current "major" AGP version as well

@ZacSweers
Copy link
Contributor Author

Note the test failures appear unrelated, and I think just a change in how the gradle test kit works now. Will investigate

@ZacSweers
Copy link
Contributor Author

I've partially addressed the new test requirements, but now I don't know what to do to fix all the tasks seeing themselves as up to date every test. I suspect it's something wrong with the incremental tasks logic in apollo itself

@tasomaniac
Copy link
Contributor

In another Gradle plugin, we've had similar issues while trying to update to Gradle 5.x. Another problem was that it would use much more memory which results in ~5x slower CI builds. novoda/gradle-static-analysis-plugin#169

What about reverting the Gradle update. Or update to latest 4.10 but just fix depreciations. Then, that can be merged fast and then a PR updating Gradle can be open.

@ZacSweers
Copy link
Contributor Author

I don't quite understand, as 4.10 is what we started with and per my last comment, some of these deprecation fixes require 5.x. Would prefer to fix here rather than backtrack

@tasomaniac
Copy link
Contributor

I was just suggesting to take smaller steps so that this can be merged faster. Its just a suggestion. If it can be fixed here, that's better

Also requires putting AGP in classpath for android subprojects
Per recommendation from the plugin itself:

The Kotlin Gradle plugin was loaded multiple times in different subprojects, which is not supported and may break the build.
This might happen in subprojects that apply the Kotlin plugins with the Gradle 'plugins { ... }' DSL if they specify explicit versions, even if the versions are equal.
Please add the Kotlin plugin to the common parent project or the root project, then remove the versions in the subprojects.
If the parent project does not need the plugin, add 'apply false' to the plugin line.
Using DefaultSourceDirectorySet directly is deprecated
@ZacSweers
Copy link
Contributor Author

Finally figured out the issue and resolved with 57f829c. Should be good to go now 🤞

Would like to get resolution for the gradle versioning bit. I think supporting the latest gradle (5.x) and AGP (3.4.x, which requires gradle 5.1+) is a very sane baseline support strategy.

@@ -73,8 +73,7 @@ class ApolloAndroidPluginSpec extends Specification {

then:
project.android.sourceSets.all { sourceSet ->
assert (sourceSet.extensions.findByName("graphql")) != null
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really small comment. I find having hard coded graphql in tests is better in terms of quality assurance.

Imagine a case where somebody changes GraphQLSourceDirectorySet.NAME parameter, that will be a breaking change. The previous version of these tests will catch it whereas the new one will just accept them.

Copy link
Contributor

@tasomaniac tasomaniac left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Amazing maintenance work. Thanks @ZacSweers

@tasomaniac
Copy link
Contributor

tasomaniac commented Aug 14, 2019

@ZacSweers can you also update the README mentioning the minimum Gradle requirement. I checked it with your branch, everything works as expected when a client uses Gradle 5.1.1 (which is also what is required by the latest stable Android plugin)

@ZacSweers
Copy link
Contributor Author

@tasomaniac done and also opportunistically updated to gradle 5.6

@sav007
Copy link
Contributor

sav007 commented Aug 15, 2019

Is it ready to merge?

@tasomaniac
Copy link
Contributor

I think so.

@sav007 sav007 merged commit 97ec9c5 into apollographql:master Aug 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants