bazel-contrib / rules_jvm_external

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

Should there be an error for missing classified Jars? #443

Open kigero opened 4 years ago

kigero commented 4 years ago

I recently used a maven_install call that looked like this:

def load_deps():
    maven_install(
        name = "parser_maven",
        artifacts = [
            "org.apache.commons:commons-lang3:3.4",
            "junit:junit:4.13",
            "org.slf4j:slf4j-simple:1.7.30",
            "com.company:client:3.0.0-SNAPSHOT",
        ],
        repositories = [
            "https://artifacts/archiva/repository/snapshots/",
        ],
    )

Looks good, but my compile didn't seem to work, complaining about missing classes from a transitive dependency of the com.company:client artifact. So I tried adding that artifact directly, adding this to the artifacts property:

maven.artifact(
    group = "com.company.utils",
    artifact = "util",
    version = "2.1.2-SNAPSHOT",
    classifier = "java",
),

This is the correct coordinate for this artifact, but I was still having the same issues. So after some troubleshooting, I found three things:

  1. For the com.company.utils:util artifact the pom had been uploaded, but the classified version of the jar had not been (this was the root cause of the problem).
  2. In the BUILD file for the parser_maven repo the definition for this artifact was:
    java_library(
    name = "com_company_utils_util_java",
    exports = [
    ],
    tags = ["maven_coordinates=com.company.utils:util:jar:java2:2.1.2-SNAPSHOT"],
    )

    (notice the missing "jars" property)

  3. In the external/parser_maven/v1/.../2.1.2-SNAPSHOT directory for the artifact, I had this set of files:
    1. .util-java.pom (along with the .md5 and .sha1 versions)
    2. .util-java.jar.err (along with the .md5 and .sha1 versions)

So what it looked like is the pom was able to be retrieved but the classified jar was not, since it didn't exist at the time. Given that this was the case should an error have been thrown during the retrieval stage, instead of at the compile stage when the classes were missing? I wouldn't have expected the "@parser_maven//:com_company_utils_util" label to resolve properly if the requested artifact wasn't found.

jin commented 4 years ago

Can you try to use Coursier CLI directly resolve the artifact, and see if it downloads the classified jar successfully? rules_jvm_external simply parses the dependency tree output of Coursier CLI, so it doesn't know if there's should have been an error there.

We can definitely make RJE throw or fail, if we can come up with a general heuristic from your repro (existence of jar.err?).

kigero commented 4 years ago

I tried the following with coursier 2.0.0-RC6-24 running on Windows:

> coursier.bat fetch -r https://artifacts/archiva/repository/snapshots/ --no-default --cache . com.company:client:3.0.0-SNAPSHOT,classifier=badclassifier
Error fetching artifacts:
https://artifacts/archiva/repository/snapshots/com/company/client/3.0.0-SNAPSHOT/client-3.0.0-SNAPSHOT-badclassifier.jar: not found: https://artifacts/archiva/repository/snapshots/com/company/client/3.0.0-SNAPSHOT/client-3.0.0-SNAPSHOT-badclassifier.jar

> echo %ERRORLEVEL%
1

>find|grep client
./https/artifacts/archiva/repository/snapshots/com/company/client
./https/artifacts/archiva/repository/snapshots/com/company/client/3.0.0-SNAPSHOT
./https/artifacts/archiva/repository/snapshots/com/company/client/3.0.0-SNAPSHOT/.client-3.0.0-SNAPSHOT-badclassifier.jar.error
./https/artifacts/archiva/repository/snapshots/com/company/client/3.0.0-SNAPSHOT/.client-3.0.0-SNAPSHOT-badclassifier.jar.sha1.error
./https/artifacts/archiva/repository/snapshots/com/company/client/3.0.0-SNAPSHOT/.client-3.0.0-SNAPSHOT.pom.checked
./https/artifacts/archiva/repository/snapshots/com/company/client/3.0.0-SNAPSHOT/.client-3.0.0-SNAPSHOT.pom.sha1.checked
./https/artifacts/archiva/repository/snapshots/com/company/client/3.0.0-SNAPSHOT/client-3.0.0-SNAPSHOT.pom
./https/artifacts/archiva/repository/snapshots/com/company/client/3.0.0-SNAPSHOT/client-3.0.0-SNAPSHOT.pom.sha1

Using a valid classifier instead of "badclassifier" worked as expected. It does looks like there is an error from coursier though along with the .err files.