pubref / rules_maven

Transitive maven dependencies with Bazel.
Other
33 stars 7 forks source link

Is it possible to target a pom.xml in the project? #17

Open dhalperi opened 6 years ago

dhalperi commented 6 years ago

I.e., if I have a folder //third_party/foo that has pom.xml, foo.jar, foo-sources.jar, etc, can I use it and still get the transitive dependency resolution?

Or can I only depend on artifacts from Maven central?

pcj commented 6 years ago

It would be a new feature, but basically anything you can do with gradle, you can theoretically do with rules_maven (and you definitely can use other maven servers than central).

(However, if your pom.xml file is using other local filesystem resources (like ~/.m2), then it could present problems (or require running bazel in non-sandboxed mode)).

If you have an example test repo that would help.

dhalperi commented 6 years ago

Here's what we're doing:

The question is, what's the easiest way to get the HEAD version?

What we did using Maven was just build the jar ourselves with a custom version and ship the jar, sources, and pom.xml in our source tree. Then we mvn install:install-file the jar during the build process. The pom.xml still has the normal JsonPath transitive deps, which we did not need to modify.

So what's the right thing to do with bazel? Ideally, we'd reuse that project's maven machinery as much as possible until they release a new version.

pcj commented 6 years ago

So JsonPath uses gradle for it's build, so that is convenient here. I could imagine we could have a gradle_java_import rule that (1) takes a build.gradle file as input, (2) runs a gradle build, (3) takes the jar output and imports it into bazel. Then you could do something like:

new_git_repository(
    name = "jsonpath",
    url = "github.com/janeway/jsonpath",
    build_file_content = """
load("@org_pubref_rules_maven", "gradle_jar_import")
"""
gradle_java_import(
    name = "jar",
    build = "build.gradle",
    srcs = glob(["src/main/java/**"]),
)

and then use it as

java_library(
   ...
   deps = ["@jsonpath//:jar"],
)

WDYT?

dhalperi commented 6 years ago

I can't quite tell from that proposal -- would it integrate into the maven ecosystem, such that

pcj commented 6 years ago

The way I proposed it:

  1. Gradle itself, alone, would be used to build a jsonpath.jar. No other jars from the WORKSPACE would be used at this step.
  2. The output jar (built by gradle) would become available to the WORKSPACE via a java_import rule. Other java_library targets would refer to that jar
dhalperi commented 6 years ago

Sorry for the delay, was on a ski trip :)

My questions for your proposal:

Aka, if jsonpath depends on jsonpath-core and a maven module foo depends on jsonpath-core, I want to make sure they're the same version, that depending on both jsonpath and foo gets only single copy of jsonpath core, and that depending on jsonpath does invoke a transitive dependency on @jsonpath_core//:compile for example.