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

Fix support with Gradle 5.x/Android 2.5+; add Gradle 5.1 and drop Gradle 3.0 in tests. #287

Merged
merged 16 commits into from
Jan 10, 2019

Conversation

zhangkun83
Copy link
Collaborator

@zhangkun83 zhangkun83 commented Jan 4, 2019

  • gradle/wrapper/gradle-wrapper.properties: the Protobuf plugin is now built with Gradle 5.1
  • ProtobufPlugin.groovy: fixed a bug where GenerateProtoTask may "include" the wrong directory when running with Android plugin >= 2.5.
    • The bug: addGenerateProtoTask() always use the directory per sourceSet as input (original line 328), but with Android plugin >= 2.5, the extract task writes to the directory per variant (original line 272), thus they don't match. The GenerateProtoTask ends up using a nonexistent directory as an input. We didn't catch it in tests because the integration tests were only run with Android plugin up to 2.3. However, Gradle produced a warning about missing input directory, which becomes an error on Gradle 5.0 (Gradle 5.0 Depreciated API features #253). Adding Gradle 5.1 and Android 3.1.0 to the test reproduces this bug.
    • The fix refactored the file and moved the assigning of inputs closer to where the extract task is created. This makes sure the input of the generate task matches the output of the extract task.
  • Updated tests

 - Fixed missing Gradle version specifications in two tests.

 - Added missing settings.gradle in the test projects because Gradle
   5.0 starts to complain about it.
After upgrading to Gradle 5.0, a few new codenarc failures emerged.
Don't know why, but fixed them anyway.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
WIP: Still trying to fix tests. There are multiple issues:

1. extracted-include-protos as input of GenerateProtoTask, when
doesn't exist, will fail the validation of GenerateProtoTask.  Tried
to always mkdir for them, but doesn't work.  (TODO: Currently
suppressed by removing the "input" setting.  Should be fixed).

2. MethodDefNotFoundError from Kotlin plugin calling into Gradle API.
This is supposedly fixed by upgrading the kotlin plugin version in the
build file of the protouf plugin.

3. Could not find lint-gradle:26.1.0 in Android projects.  Probably
missing repo definition.

4. AndroidProjectDetectionTest fails due to class path issues.

Thought: currently the whole classpath of the protobuf plugin as it's
built is injected into the test projects (through
plugin-classpath.txt).  The plugin is built with Gradle 5.0 and a
certain Android and kotlin plugin versions, but the tests can be run
in different versions.  They may not necessarily be compatible.
Additionally, the current test harness is done in a way that's hard to
track, run and debug.  The whole thing needs to be revisited.
This resolves missing dependencies for lint-gradle:26.1.0
Support for Android plugin 2.5+ was added in google#121. While it made
extractIncludeProtosTask to copy the protos to a different destination
with Android plugin 2.5+ than with older verisons, it didn't make
generateProtoTask to "include" the new location.  This causes Android
tests to fail with Gradle 5.0 and Android plugin 3.1.0.

The bug has remained undetected because test was never run with
Android 2.5+.
TODO: Couldn't expand to the fourth (oldest) version because of
OverlappingFileLockException when Gradle trying to resolve
dependencies.
Refactored the codepath to make it less prone to such mistake.
…tionTest.

This case fails with
java.lang.NoSuchMethodException: com.android.build.gradle.internal.BuildSessionImpl.initialize(org.gradle.api.invocation.Gradle)

The (Gradle(3.0) Android(2.2.0)) also fails with OverlappingFileLockException seen in ProtobufAndroidPluginTest.
Gradle 3.0 / Android 2.2.0 is commented out due to gradle/gradle#8158
@zhangkun83 zhangkun83 requested a review from ejona86 January 4, 2019 18:28
@zhangkun83 zhangkun83 changed the title Fix support with Gradle 5.x; add 5.1 and drop 3.0 in tests. Fix support with Gradle 5.x/Android 2.5+; add Gradle 5.1 and drop 3.0 in tests. Jan 4, 2019
@zhangkun83 zhangkun83 changed the title Fix support with Gradle 5.x/Android 2.5+; add Gradle 5.1 and drop 3.0 in tests. Fix support with Gradle 5.x/Android 2.5+; add Gradle 5.1 and drop Gradle 3.0 in tests. Jan 4, 2019
@bubenheimer
Copy link

This fixes #253 for me

@zhangkun83 zhangkun83 merged commit 8d0b8db into google:master Jan 10, 2019
@zhangkun83 zhangkun83 deleted the gradle5 branch January 10, 2019 01:09
@SzasznikaJanos
Copy link

Still have the same issue with Gradle wrapper 5.1 and android plugin 3.4.0 - alpha 10

@zhangkun83
Copy link
Collaborator Author

@SzasznikaJanos were you running with a locally built protobuf-gradle-plugin? If not, you are probably using the snapshot in repo which is not up-to-date. I just pushed a new one and you can try again.

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.

None yet

4 participants