Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Use the maven-publish plugin to publish AAR files. #101276

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

Merged
merged 9 commits into from
Apr 13, 2022

Conversation

AesSedai101
Copy link
Contributor

@AesSedai101 AesSedai101 commented Apr 4, 2022

This PR changes flutter build aar to make use of the maven-publish plugin, removing the maven plugin which as been previously deprecated and removed in Gradle 7.

Fixes #101083

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Apr 4, 2022
@flutter-dashboard
Copy link

It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@AesSedai101 AesSedai101 closed this Apr 4, 2022
@AesSedai101 AesSedai101 reopened this Apr 4, 2022
@AesSedai101 AesSedai101 force-pushed the maven_publish_plugin branch from 388499c to 391ed84 Compare April 4, 2022 10:33
@AesSedai101
Copy link
Contributor Author

AesSedai101 commented Apr 4, 2022

Builds are currently failing because maven-publish creates different Android variants as classifiers (io.flutter.devicelab.hello:flutter:1.0:debug) while the old publish plugin created them as different artefacts with the variant appended to the artifactId (io.flutter.devicelab.hello:flutter_debug:1.0).

In this case, the new behaviour would be considered more "correct" from a grade perspective, but it might cause other issues in the ecosystem.

It looks like it's possible to adapt project.components.all to mimic the old behaviour - I'll see what I can do.

@blasten
Copy link

blasten commented Apr 4, 2022

you may also need to change:

// TODO(egarciad): Gradle 7 breaks AARs builds: https://github.com/flutter/flutter/issues/101083
const String templateAndroidGradlePluginVersionForModule = '4.1.0';

Maybe, remove templateAndroidGradlePluginVersionForModule and replace with templateDefaultGradleVersion.

@blasten
Copy link

blasten commented Apr 4, 2022

Based on gradle/gradle#12324 (comment), I think the issue appears to be that we can't configure multiple publications at once. I wonder if it could just configure the task that was currently requested from Dart, and this way, just configure a single publication.

@AesSedai101
Copy link
Contributor Author

AesSedai101 commented Apr 5, 2022

Based on gradle/gradle#12324 (comment), I think the issue appears to be that we can't configure multiple publications at once. I wonder if it could just configure the task that was currently requested from Dart, and this way, just configure a single publication.

So that is kind of what I'm trying to do with project.components.forEach { component ->, which does the trick - it produces _debug, _profile and _release artifactId's. The next step is to convince gradle to resolve those correctly where Flutter plugins are direct dependencies of each other:

> Publishing is not able to resolve a dependency on a project with multiple publications that have different coordinates.
Found the following publications in project ':plugin_with_android':
- Maven publication 'debug' with coordinates io.flutter.devicelab.plugin_with_android:plugin_with_android_debug:1.0
- Maven publication 'profile' with coordinates io.flutter.devicelab.plugin_with_android:plugin_with_android_profile:1.0
- Maven publication 'release' with coordinates io.flutter.devicelab.plugin_with_android:plugin_with_android_release:1.0

@AesSedai101 AesSedai101 requested a review from keyonghan as a code owner April 5, 2022 08:44
@AesSedai101 AesSedai101 force-pushed the maven_publish_plugin branch from 850481c to c210b0c Compare April 5, 2022 08:58
@AesSedai101
Copy link
Contributor Author

AesSedai101 commented Apr 6, 2022

Ok, I'm not finding a way to get the maven-publish plugin to resolve these dependencies correctly. What I would like to propose is to put a relocation pom at the old coordinates and then publish the actual artefacts as per the new gradle way (one artefact with classifiers). This way, we keep backward compatibility, but still publish in the "default" way.

For reference, this is what the repo structure would then look like:

repo/
  com/
     example/
        plugin1/                                         <-- new way with classifiers
             1.0/
                 plugin1-1.0.pom
                 plugin1-1.0-debug.aar
                 plugin1-1.0-profile.aar
                 plugin1-1.0-release.aar
        plugin1_debug/                            <-- Maintain backward compatibility             
             1.0/
                 plugin1_debug-1.0.pom
                 plugin1_debug-1.0.aar
        plugin1_profile/
             1.0/
                 plugin1_profile-1.0.pom
                 plugin1_profile-1.0.aar
        plugin1_release/
             1.0/
                 plugin1_release-1.0.pom
                 plugin1_release-1.0.aar

The _{variant} POM files would then look the same as they do now, with the addition of a <relocation> section

  <distributionManagement>
    <relocation>
      <groupId>com.example</groupId>
      <artifactId>plugin1<artifactId>
      <version>1.0</version>
      <message>Use classifiers rather than _variant for new publish plugin</message>
    </relocation>
  </distributionManagement>

For now, we can also publish the AARs in the old location, but change the documentation to point to the new location.

Thoughts?

@blasten
Copy link

blasten commented Apr 7, 2022

@AesSedai101 makes sense :) Thank you for doing all the research!

@AesSedai101
Copy link
Contributor Author

AesSedai101 commented Apr 8, 2022

@AesSedai101 makes sense :) Thank you for doing all the research!

perfect! I'll make the changes and update the tests sometime today 🙂

@AesSedai101 AesSedai101 force-pushed the maven_publish_plugin branch 2 times, most recently from 77d8bc6 to ca61493 Compare April 8, 2022 08:29
@AesSedai101 AesSedai101 force-pushed the maven_publish_plugin branch from 6207101 to 1f5bea2 Compare April 8, 2022 08:39
@flutter-dashboard flutter-dashboard bot added the c: contributor-productivity Team-specific productivity, code health, technical debt. label Apr 8, 2022
@AesSedai101 AesSedai101 force-pushed the maven_publish_plugin branch 4 times, most recently from 67f9fbc to a4399eb Compare April 8, 2022 11:16
@AesSedai101 AesSedai101 closed this Apr 8, 2022
@AesSedai101 AesSedai101 reopened this Apr 8, 2022
@AesSedai101 AesSedai101 closed this Apr 8, 2022
@AesSedai101 AesSedai101 reopened this Apr 8, 2022
@AesSedai101 AesSedai101 force-pushed the maven_publish_plugin branch from a4399eb to cdf8fb5 Compare April 11, 2022 10:27
.ci.yaml Outdated
@@ -188,13 +188,13 @@ targets:
caches: >-
[
{"name":"gradle","path":"gradle"},
{"name": "openjdk", "path": "java"}
{"name": "openjdk", "path": "java11"}
Copy link
Contributor

Choose a reason for hiding this comment

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

Name is the one that needs to change, path should be kept as java.

Copy link

Choose a reason for hiding this comment

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

there are many caches in this file that have this entry: {"name": "openjdk", "path": "java11"}. Are those set incorrectly?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes the are all incorrect, the modules will add cache/java to the path and this cache won't have any effect.

Copy link

Choose a reason for hiding this comment

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

got it. can the name be any arbitrary string?

Copy link
Contributor

Choose a reason for hiding this comment

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

we are usually using dependency_ for named caches.

Copy link

Choose a reason for hiding this comment

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

Done

Copy link

@blasten blasten left a comment

Choose a reason for hiding this comment

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

Nicely done, thank you! LGTM

@blasten
Copy link

blasten commented Apr 12, 2022

btw, we are hiring https://docs.flutter.dev/jobs :)

@AesSedai101 AesSedai101 requested a review from godofredoc April 12, 2022 06:47
@blasten blasten added the platform-android Android applications specifically label Apr 12, 2022
@fluttergithubbot fluttergithubbot merged commit 2b0255f into flutter:master Apr 13, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Apr 13, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Apr 13, 2022
@AesSedai101 AesSedai101 deleted the maven_publish_plugin branch April 13, 2022 08:14
zanderso added a commit that referenced this pull request Apr 13, 2022
AesSedai101 added a commit to AesSedai101/flutter that referenced this pull request Apr 14, 2022
@JunhuaLin
Copy link
Contributor

#111643

@AesSedai101

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: contributor-productivity Team-specific productivity, code health, technical debt. platform-android Android applications specifically tool Affects the "flutter" command-line tool. See also t: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Build AARs with Gradle 7.0
5 participants