-
-
Notifications
You must be signed in to change notification settings - Fork 286
Scala maven import external #473
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
Scala maven import external #473
Conversation
WORKSPACE
Outdated
java_import_external( | ||
name = "com_google_guava_guava_21_0", | ||
licenses = ["notice"], # Apache 2.0 | ||
jar_urls = [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are these alternative urls for the same sha?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can mirror files if you need it. Not sure I follow.
|
||
"""Rules for defining external Java dependencies. | ||
|
||
java_import_external() replaces `maven_jar` and `http_jar`. It is the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this just a temporary copy paste? can we not get this with a remote dependency?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can make the existing java_import_external serve your use case, if you'd prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes this is a temporary copy paste.
We're starting out this way to validate the differences are indeed small instead of iterating between this repository and bazel itself.
The general plan is to generalize with as few changes as possible and then port 80%-90% of the code back to bazel
@natansil I don't have time now to do a complete review but WDYT about sharing here a bit more detail on what problem we're trying to solve and what are the gains we're trying to achieve? Also maybe a bit on intermediate solution vs longer term |
@@ -4,7 +4,7 @@ load("//scala:scala_import.bzl", "scala_import") | |||
#Many jars | |||
scala_import( | |||
name = "guava_and_commons_lang", | |||
jars = ["@com_google_guava_guava_21_0//jar:file", "@org_apache_commons_commons_lang_3_5//jar:file"], | |||
jars = ["@com_google_guava_guava_21_0//:file", "@org_apache_commons_commons_lang_3_5//jar:file"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ittaiz re-posting my question right next to the example of the consumer:
currently java_import_external does not support depending on the jar file directly. in order to not do major changes to justine's code, I've had to change the usage label structure from @com_google_guava_guava_21_0//jar:file
to @com_google_guava_guava_21_0//:file
.
Is this legitimate or should I re-write the code to have the same folder structure as maven_jar
?
Alternatively, you've stated that scala_import
can depend on full jar files without needing the file
filegroup target.
so with the example above, I can just change it to
jars = ["@com_google_guava_guava_21_0//jar", "@org_apache_commons_commons_lang_3_5//jar"],
and that will solve the issue (and still not take ijars)?
…ed files directly. an issue will be open for scala_import to support direct file output
…ing to jvm_import_external/maven_import_external
We at Lucid are currently working on the external dependency issue and were just about to implement a I have a couple questions: The original It seems like using This approach also works well with strict deps and unused deps. By using How challenging would it be to create a generic If we create the |
Regarding 1. + 2. As I see it this is part of the modularity effort we want to achieve. In addition we are thinking about something like a Regarding 3. I think that Bazel's long-term goal is to have transitive deps resolution built-in, like explained here |
So there's good news and bad news. 👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there. 😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request. Note to project maintainer: This is a terminal state, meaning the |
I consent to my contributions going in |
…or 'scala_maven_import_external', 'maven_import_external', 'java_import_external'
extract common code to
|
def scala_maven_import_external(artifact, server_urls, **kwargs): | ||
jvm_maven_import_external( | ||
rule_name = "scala_import", | ||
rule_load = "load(\"@io_bazel_rules_scala//scala:scala_import.bzl\", \"scala_import\")", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should probably be an attribute with a default value since some organizations (like us) add these in prelude and also some organizations (stripe?) might have aliases or stuff so they load from a different place
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
WORKSPACE
Outdated
scala_maven_import_external( | ||
name = "com_google_guava_guava_21_0", | ||
licenses = ["notice"], # Apache 2.0 | ||
artifact = "com.google.guava:guava:21.0", | ||
server_urls = ["https://mirror.bazel.build/repo1.maven.org/maven2"], | ||
jar_sha256 = "972139718abc8a4893fa78cba8cf7b2c903f35c97aaf44fa3031b0669948b480", | ||
) | ||
|
||
# for regression testing purposes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't understand this (even with the comment sorry!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed a more detailed explanation. is this clear now?
Thanks for generalizing things into I ask because I imagine not everyone will want to rely on I'm currently modifying bazel-deps to use I'm happy to add the rule to this PR. I just wanted to get people's feedback. |
Did you see what kind of maven resolution the rule currently does? Why
would you rather work with full URLs and not coordinates?
…On Wed, 11 Apr 2018 at 18:59 James Judd ***@***.***> wrote:
Thanks for generalizing things into jvm_import_external. Can we add a
scala_import_external that looks likejava_import_external, i.e., it takes
jarl_urls, jar_sha256, srcjar_urls, and srcjar_sha256?
I ask because I imagine not everyone will want to rely on
scala_maven_import_external to do the maven resolution, especially
considering that the rule doesn't support transitive dependencies right now.
I'm currently modifying bazel-deps to use java_import_external and scala_import_external
(an internal version) instead ofjava_libraryandscala_import. bazel-deps
resolves the jars, finds all the information it needs, and then writes the
rule calls to a.bzl` file.
I'm happy to add the rule to this PR. I just wanted to get people's
feedback.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#473 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABUIF3VAiL4wiEWxyNKSEJc91aSVoBuKks5tnihpgaJpZM4TG3ig>
.
|
I have read through the code. I still see value in having a Maven resolution is a pretty active area in Bazel without an agreed on solution. I know of bazel-deps, You can implement
I'm suggesting that we have the same thing for Scala. |
I know the change is small, I just don’t understand the value.
I don’t consider simple translation from coordinates to url as maven
resolution but I don’t object if you plan to capitalize on it.
@natansil,
Can you add it?
…On Wed, 11 Apr 2018 at 21:08 James Judd ***@***.***> wrote:
I have read through the code. I still see value in having a
scala_import_external that is used in the same way as java_import_external.
I would like to separate Maven resolution from artifact downloading until
the Bazel community agrees on a Maven resolution solution.
Maven resolution is a pretty active area in Bazel without an agreed on
solution. I know of bazel-deps, transitive_maven_jar, native maven_jar,
skylark maven_jar, or rules_maven. This adds another option to that mix.
I would like to be able to use scala_import_external without subscribing
to a particular artifact resolution strategy.
You can implement scala_maven_import_external using scala_import_external
more easily than the other way around. The current commit does this for
jvm_maven_import_external and jvm_import_external:
def jvm_maven_import_external(artifact, server_urls, **kwargs):
jvm_import_external(
jar_urls = _convert_to_url(artifact, server_urls),
**kwargs
)
I'm suggesting that we have the same thing for Scala.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#473 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABUIF-rBJYzqMdiFAIkANJ6YwOyCT6Qoks5tnkZ1gaJpZM4TG3ig>
.
|
added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
@johnynek any objections to this being merged?
Next step will be to open an issue to bazel linking to this code and suggesting we send it upstream (without the scala macros obviously)
99d476b
to
e4472ea
Compare
@johnynek I'll merge in a couple of hours if you don't ping back |
This PR copies "upstream" a change made to java_import_external in`rules_scala` (see [PR](bazel-contrib/rules_scala#473)) This change was originally proposed by @dslomov [here](#3528) (search for 'jvm_import_external') java_import_external was changed to `jvm_import_external` 'template like' rule + `java_import_external` macro in order to allow for other jvm languages (e.g. scala and kotlin) to utilize the 'import_external' functionality without copying the boiler plate again and again. This has already been used in `rules_scala` with the introduction of `scala_import_external` and `scala_maven_import_external` In addition to the `import rule name`, `jvm_import_external` can also be called with custom attributes needed by the underlying import rules, as well as a custom load statement. `java_import_external` is used as a macro in rules_scala to make sure it's still functioning properly after the change. `jvm_maven_import_external` exposes maven artifact terminology. This will also allow to create a `maven_import_external` macro that will delegate to `jvm_maven_import_external` with a `maven_import` rule which will have `MavenCoordinates` Provider as discussed [here](#4654) Closes #5068. PiperOrigin-RevId: 198398621
* original jave_import_external * allow for direct jar file usage in dependencies * change java_import to scala_import * replace jar_urls with artifact + server_urls * remove filegroup target and use maven_jar for specific places that need files directly. an issue will be open for scala_import to support direct file output * rename to scala_maven_import_external. still need to decide on splitting to jvm_import_external/maven_import_external * _concat_with_needed_slash * fix typo * add 'return' in new method * extract common code to 'jvm_import_external' rule. introduce macros for 'scala_maven_import_external', 'maven_import_external', 'java_import_external' * CR changes * added documentation * moved license notice back to the top
Currently, there are limitations to using maven_jar + scala_import:
cross-repo
transitive dependencies there is the unintended consequences of trying to fetch the wrong transitive dependencies:Let's say we have
repo-a
andrepo-b
.repo-a
depends on targetfoo
fromrepo-b
foo
depends onbar-v1
repo-a
declares bar with v2bar-v1
bringsbaz
bar-v2
no longer depends onbaz
with the current design, when bazel builds
foo
forrepo-a
, it looks inrepo-a
’s workspace and fetchesbar-v2
but it will look in build file of
repo-b
for dependencies of bar and will try to fetchbaz
and will fail (becausebaz
is not declared in workspace ofrepo-a
)In order to solve these issues a new repository rule should be defined that will also declare the transitive dependencies. This way the dependencies will be fetched from the original repo and not from external repos.
The idea is to extend the work done by @jart for java imports
Optimally, in order to have as much code reuse as possible, we want to strive to have as much generic code as possible with a
jvm_import_external
(see original proposal here) template rule that will allow to use it with eitherjava_import
orscala_import
.For now, we will work on implementing
scala_maven_import_external
based off ofjava_import_external
rule and change it in such a manner as to enable easy migration tojvm_import_external
.jvm_import_external
will include params:rule_name
(e.g. java_import, scala_import)load
(load statement, e.g. load("//scala:scala_import.bzl", "scala_import"))use_ijar
(propagate args to underlying rules. This case scala_import )sha256
- make it optionalmaven
- allow translation from artifact to jar url ( maybe should actually reside inmaven_import_external
rule)