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

Document how workspace rules should interface with pom_file #15

Open
deadmoose opened this issue Apr 20, 2018 · 6 comments
Open

Document how workspace rules should interface with pom_file #15

deadmoose opened this issue Apr 20, 2018 · 6 comments
Labels
enhancement New feature or request P4

Comments

@deadmoose
Copy link

My skylark's pretty rusty after a year on the outside, but if I'm following correctly:

The pom_file rule crawls the targets' dependencies, using the maven_coordinates=[XXX] tag to identify things that came from maven & can/should be included in {generated_bzl_deps}

That works fine for the deps coming from here since workspace_defs.bzl is turning maven artifact strings into java_import_external rules w/ that tag added.

But anything defined as a native maven_jar is missed; it's got that artifactid directly on it, but not as that particular tag. And despite the claim here that all rules support tags, maven_jar doesn't appear to support them, so I can't even just tack it on.

I'm using bazel-deps to generate all the rules, so it looks like I could potentially hack that to stick the tags on the java_library rules it tosses under third_party, but it feels like if I knew what I was doing, it shouldn't be too bad to automagically get that off the underlying maven_jar rule.

@ronshapiro
Copy link
Contributor

Unfortuantely, I haven't seen any mechanism by which pom_file could read information from maven_jar as it currently stands. Patching maven_jar to include a tags attribute sounds like a great option, and then bazel-deps can use that. Or maybe even maven_jar should just specify the tag automagically.

Alternatively/additionally, bazel-deps could probably use java_import_external which has better reliability during builds /cc: @jart @johnynek

@deadmoose
Copy link
Author

Or maybe even maven_jar should just specify the tag automagically.

Other than the red tape involved to nail down the officially supported tag, yes. Otherwise future people are going to have the same confusion I had where I added this into an existing project & then stared blankly when it didn't do anything. (I should probably file another bug/just make a PR with a bit more documentation around that requirement, but it'd still be better for the obvious things to Just Work[tm])

Alternatively/additionally, bazel-deps could probably use java_import_external which has better reliability during builds

Skimming the docs, it looks like that's inadequate for private use: maven_jar is maven aware and can hit my settings.xml to figure out about credentials to hit our internal repository, but java_import_external seems to want URLs that are expected to just work.

I might be able to get bazel to interpolate in something pulled in from elsewhere, but I'd also be nervous that something somewhere would naively dump https://blah:[email protected]/ to a log.

deadmoose added a commit to deadmoose/bazel-deps that referenced this issue Apr 23, 2018
Over in bazel-common, there's a rule for generating poms for shipping
bazel targets:
https://github.com/google/bazel-common/blob/master/tools/maven/pom_file.bzl

That figures out its dependencies via the 'maven_coordinates' tag on
build rules, and unfortunately it's easier said than done to just infer
that from a maven_jar rule (see also:
google/bazel-common#15 )

In the mean time, I've hacked bazel_deps to explicitly write that tag,
though it's on the 3rdparty java_library rule, rather than the maven_jar
one because the latter doesn't support tags :/

I've done very minimal playing with this, but it sure LOOKS like this is
correctly letting me have bazel-deps manage the song and dance going
from maven -> bazel, and then generate poms so I can publish artifacts
for everyone else to consume.
@deadmoose
Copy link
Author

Looks like I'm unblocked for the moment with minimal pain by hacking bazel-deps to add the tag to the java_library wrappers it generates around the maven_jars.

🤞

@ronshapiro
Copy link
Contributor

I'm not sure what the best practice is (or if there is one) with regard to bazel+internal maven servers+credentials. That sounds like a way that builds become unreproducible?

Looks like I'm unblocked for the moment with minimal pain by hacking bazel-deps to add the tag to the java_library wrappers it generates around the maven_jars.

That also works :)

Shall we close this issue?

@deadmoose
Copy link
Author

I'm not sure what the best practice is (or if there is one) with regard to bazel+internal maven servers+credentials. That sounds like a way that builds become unreproducible?

Why? It's still a maven repository with immutable published artifacts and my WORKSPACE files can list expected checksums for them, etc. They just aren't publicly available and/or available by virtue of just being on. some private network. Try to hit it as some random person & it'll fail downloads and bazel will break just like if you hit a public repo and all your mirrors barfed at the same time.

Shall we close this issue?

I can open another issue/PR for documenting "Hey, if you want to use this, you need to do this extra legwork", but it's really unfortunate if that's the answer when maven_jar is a first-party rule in bazel and theoretically should let this all happen automagically.

@ronshapiro ronshapiro changed the title pom_file doesn't understand maven_jar rules Document how workspace rules should interface with pom_file Apr 23, 2018
@jart
Copy link

jart commented Apr 26, 2018

I would recommend using java_import_external which is in the bazel codebase and documents itself as the recommended practice. Please note it does not grab transitive dependencies automatically. You can use Bazel Maven Config Generator to crawl POM metadata and generate a WORKSPACE config that's fast, reliable, and mirrors artifacts to Google Drive. See demo video and best practices guide.

@cpovirk cpovirk added enhancement New feature or request P4 labels Jul 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P4
Projects
None yet
Development

No branches or pull requests

4 participants