bazel-contrib / rules_jvm_external

Bazel rules to resolve, fetch and export Maven artifacts
Apache License 2.0
332 stars 255 forks source link

Relocated dependencies doesn't resolve #250

Open mandrean opened 5 years ago

mandrean commented 5 years ago

While trying to build a project I run into this error:

ERROR: /private/var/tmp/_bazel_smandrean/5f7e17baa0f0d8192b57baed7ff78f69/external/alchemist/BUILD:4840:9: in deps attribute of jvm_import rule @alchemist//:org_mock_server_mockserver_core: rule '@alchemist//:org_apache_commons_commons_io' does not exist
WARNING: errors encountered while analyzing target '//alchemist:alchemist': it will not be built

Even if I manually add org.apache.commons:commons-io:1.3.2 to the maven_install it still doesn't build.

While inspecting https://mvnrepository.com/artifact/org.apache.commons/commons-io & https://repo1.maven.org/maven2/org/apache/commons/commons-io/1.3.2/commons-io-1.3.2.pom, I notice:

image

and

image

So, to me it seems like rules_jvm_external and/or Coursier can't resolve relocated dependencies?

jin commented 5 years ago

Can you provide the maven_install snippet please?

mandrean commented 5 years ago

@jin Here you go:

https://github.com/mandrean/rules-jvm-relocated-deps/blob/master/WORKSPACE#L19

and

https://github.com/mandrean/rules-jvm-relocated-deps/blob/master/src/test/java/se/mandrean/rulesjvmrelocateddeps/BUILD#L8

Note that if you comment out: org.apache.commons:commons-io:1.3.2/@maven//:org_apache_commons_commons_io

and use: commons-io:commons-io:1.3.2/@maven//:commons_io_commons_io instead, it all works!

So to me it seems that something isn't resolving relocated artifacts.

cheister commented 4 years ago

I'm seeing the same thing with org.hibernate:hibernate-validator:6.0.18.Final which is relocated to org.hibernate.validator:hibernate-validator:6.0.18.Final.

It looks like the problem is coursier fetch doesn't return any information about the dependency rename e.g.

> coursier fetch --json-output-file dep-tree.json org.apache.commons:commons-io:1.3.2
/Users/cheister/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/commons-io/commons-io/1.3.2/commons-io-1.3.2.jar

> cat dep-tree.json | python -m json.tool
{
    "conflict_resolution": {},
    "dependencies": [
        {
            "coord": "commons-io:commons-io:1.3.2",
            "dependencies": [],
            "directDependencies": [],
            "file": "/Users/cheister/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/commons-io/commons-io/1.3.2/commons-io-1.3.2.jar"
        }
    ],
    "version": "0.1.0"
}

Since rules_jvm_external only creates jvm_import rules for dependencies returned in the fetch json output it does not add a jvm_import rule for org.apache.commons:commons-io.

I wonder if coursier would accept a feature request to add a renames field to the json they return?

Alternatively, if you only want resolution to work and don't need to refer to the artifact directly ( @maven//:org_apache_commons_commons_io) it looks you can work around it with override_targets in maven_install

    override_targets = {
        "org.apache.commons:commons-io": ":commons_io_commons_io",
    },
fzakaria commented 9 hours ago

I just hit this with https://mvnrepository.com/artifact/org.slf4j/slf4j-reload4j and https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12