-
Notifications
You must be signed in to change notification settings - Fork 237
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
Add generate_compat_repositories attribute to maven_install for top level repository aliases and cross-workspace dependencies #160
Conversation
(fyi @dslomov, this can help with maven_jar deprecation) |
@jin that is a little bit off-topic but I wonder if it makes sense to write some "best practices" on how to expose external dependencies to not always having to think how to import an external dep when switching language. I feel nearly every rule does it differently, e.g. rules_nodejs and rules_pip also expose a single repository like the default here but they expose it without the I personally like the function exposing way the least and I do not really have a preference on one repository or multiple repositories but I do prefer not having to write the I am also happy to move this conversation to an issue on bazel itself or on Slack to not sidetrack things any further here. |
@Globegitter thanks for raising this discussion. I personally haven't thought much about setting some kind of convention across these rules, and I think it's a good idea to do that in order to reduce cognitive load. This PR set ups the framework for Let's fork this discussion onto a new GitHub issue? |
This PR adds a new attribute,
generate_compat_repositories
, tomaven_install
. The default isFalse
. The motivation for this change is #85. (Fixes #85)With this, we can refer to
@maven//:junit_junit
as@junit_junit//jar
, where the latter is the most commonly used naming convention that is popularized by rules likemaven_jar
andjava_import_external
. This enables project maintainers to incrementall migrate frommaven_jar
torules_jvm_external
without a single change in their BUILD files. It also allows cross-external repository sharing of artifacts.If enabled,
maven_install
generates an additionalcompat.bzl
file in the@maven
(or your custom) external repository. This file exposes one symbol,compat_repositories
, to be loaded aftermaven_install
, like this:compat_repositories
expands into a list ofcompat_repository
declarations, one for eachJAR
artifact in the transitive closure of the resolved dependency tree. For example:Each
compat_repository
creates a new external repository inoutput_base/external
. In the case of junit, the directory isoutput_base/external/junit_junit
, and the contents are as follows:The
WORKSPACE
is an empty file. TheBUILD
file contains an alias to the@maven//:junit_junit
target:Using this, we can refer to the target as
@junit_junit//jar:jar
, or@junit_junit//jar
for short.TODO