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

maven_export support for bundling AARs #1049

Open
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

sugarmanz
Copy link

@sugarmanz sugarmanz commented Jan 25, 2024

This PR adds (limited) support for bundling AARs for distribution with maven_publish. It optimistically uses an .aar from AndroidLibraryAarInfo as the basis for bundling and then merges the transitive closure with the nested classes.jar using the existing logic.

Usage of AndroidLibraryAarInfo requires an --experimental_google_legacy_api flag, which is pretty undesirable given it would require consumers to configure the same flag, even if not using for publishing Android artifacts. As such, I understand this PR probably isn't acceptable from a generic standpoint, but I wanted to open it up for feedback, ideas, and inspiration. This is what we'll be using to publish our Android targets until we can find a better alternative.

Example usages:

kt_jvm_library(
    name = "kt-lib",
    srcs = glob(["src/main/java/**/*.kt"]),
    resources = glob(["src/main/resources/**"]),
    exports = main_exports,
    deps = main_deps,
)

android_library(
    name = "android-lib",
    manifest = ":src/main/AndroidManifest.xml",
    resource_files = glob(["src/main/res/**"]),
    tags = ["maven_coordinates=group:artifact:aar:%s" % VERSION],
    exports = main_exports + [
        ":kt-lib",
    ],
)

maven_export(
    name = "export",
    lib_name = "android-lib",
    maven_coordinates = "group:artifact:aar:%s" % VERSION,
)

External example (we're using an Android databinding wrapper which does work to create a base .aar instead of android_library):
https://github.com/player-ui/player/blob/78345ac70c5bb34fcd58147ab49e38f22d3524fd/android/player/BUILD#L10-L27

Semi-relevant:
bazelbuild/bazel#348


if (mainArtifact != null) {
String ext =
com.google.common.io.Files.getFileExtension(mainArtifact.getFileName().toString());
futures.add(upload(repo, credentials, coords, "." + ext, mainArtifact, gpgSign));
}

futures.add(upload(repo, credentials, coords, ".pom", pom, gpgSign));
Copy link
Author

Choose a reason for hiding this comment

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

Relevant discussion for this change:
typedb/bazel-distribution#318

Might break this out into a separate contribution since this is unrelated, yet necessary for publishing support for Artifactory repositories.

@jin
Copy link
Collaborator

jin commented Jan 26, 2024

@ahumesky could you advise on the use of --experimental_google_legacy_api and AndroidLibraryAarInfo for this?

Or are there alternative upstream mechanisms that tackles bazelbuild/bazel#348?

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.

2 participants