Skip to content

coursier: ignore dependencies with classifier="sources" and no "file"#1479

Merged
shs96c merged 4 commits into
bazel-contrib:masterfrom
mattnworb:mattbrown/issue-1477
Nov 19, 2025
Merged

coursier: ignore dependencies with classifier="sources" and no "file"#1479
shs96c merged 4 commits into
bazel-contrib:masterfrom
mattnworb:mattbrown/issue-1477

Conversation

@mattnworb
Copy link
Copy Markdown
Contributor

@mattnworb mattnworb commented Nov 17, 2025

when coursier is asked to resolve an artifact that has a transitive dependency on org.apache.logging.log4j:log4j:3.0.0-beta3 (note the lack of packaging in the real-world example here) and fetch_sources=True is set, coursier will return this in the list of dependencies:

{
  "coord": "org.apache.logging.log4j:log4j:jar:sources:3.0.0-beta3",
  "file": null,
  "directDependencies": [],
  "dependencies": []
}

in rules_jvm_external 6.8 this will cause errors when building the external repo generated by RJE since RJE will end up handling this dependency by a) generating a http_file with an empty list of urls and b) emitting a copy_file rule in the external repo's BUILD file that refers to the non-existing http_file repo from A. See this comment for a breakdown of why this happens.

PR #1207 added pom to the list of SUPPORTED_PACKAGING_TYPES so that the dependencies of the pom could be aggregated (Maven interprets a dependency on an artifact with packaging=pom as depending on the <dependencies> in that pom), but that PR didn't test what happens with fetch_sources=True nor did it consider the case like with org.apache.logging.log4j:log4j:3.0.0-beta3 where the coordinates output by coursier don't mention the packaging at all.

fixes #1477

this was a request brought up in
bazel-contrib#1207 that was
not addressed before it was merged
when coursier is asked to resolve an artifact that has a transitive
dependency on `org.apache.logging.log4j:log4j:3.0.0-beta3` (note the
lack of packaging in the [real-world example here][0]) and
`fetch_sources=True` is set, coursier will return this in the list of
dependencies:

```
{
  "coord": "org.apache.logging.log4j:log4j:jar:sources:3.0.0-beta3",
  "file": null,
  "directDependencies": [],
  "dependencies": []
}
```

in rules_jvm_external 6.8 this will cause errors when building the
external repo generated by RJE since RJE will end up handling this
dependency by a) generating a `http_file` with an empty list of `urls`
and b) emitting a `copy_file` rule in the external repo's BUILD file
that refers to the non-existing `http_file` repo from A. See
[this comment][1] for a breakdown of why this happens.

PR bazel-contrib#1207 added `pom` to the list of `SUPPORTED_PACKAGING_TYPES` so that
the dependencies of the pom could be aggregated (Maven interprets a
dependency on an artifact with packaging=pom as depending on the
`<dependencies>` in that pom), but that PR didn't test what happens with
`fetch_sources=True` nor did it consider the case like with
`org.apache.logging.log4j:log4j:3.0.0-beta3` where the coordinates
output by coursier don't mention the packaging at all.

fixes bazel-contrib#1477

[0]: https://central.sonatype.com/artifact/org.opencadc/cadc-util/1.12.10
[1]: bazel-contrib#1477 (comment)
Comment thread MODULE.bazel
"org.opencadc:cadc-util:1.12.10",
],
fetch_sources = True,
lock_file = "//tests/custom_maven_install:transitive_dependency_with_type_of_pom.json",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


def rewrite_files_attribute_if_necessary(repository_ctx, dep_tree):
# There are cases where `coursier` will download both the pom and the
def filter_dependencies_if_necessary(repository_ctx, dep_tree):
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repurposed this existing function to filter out more cases rather than adding yet another function that iterates over dep_tree["dependencies"]

Copy link
Copy Markdown
Collaborator

@shs96c shs96c left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for handling this. One open question, and then I'll land with glee!

Comment thread MODULE.bazel

# Pinned repo
"transitive_dependency_with_type_of_pom",
"unpinned_transitive_dependency_with_type_of_pom",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: we no longer need the unpinned_ variant since //transitive_dependency_with_type_of_pom:pin will work

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you want it to be removed from here? I figured it made sense to follow the pattern for other test cases

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should go through and remove more, but I guess if we add this it'll be one more line :)

for dep in dep_tree["dependencies"]:
if not dep.get("file", None):
amended_deps.append(dep)
if get_classifier(dep["coord"]) == "sources":
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we also need to be concerned about the javadocs classifier too?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good question, and to be honest I am not sure - I suppose it would depend on if coursier could be made to return dependencies for packaging=jar classifier=javadoc with "file": null - I would think if an artifact with classifier=javadoc was requested and doesn't exist, it would return an error instead?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ask because the javadocs jars follow the same pattern as the source jars when we try and download them. I guess we can wait until someone files an issue....

Copy link
Copy Markdown
Collaborator

@shs96c shs96c left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Let's land this thing :)

for dep in dep_tree["dependencies"]:
if not dep.get("file", None):
amended_deps.append(dep)
if get_classifier(dep["coord"]) == "sources":
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ask because the javadocs jars follow the same pattern as the source jars when we try and download them. I guess we can wait until someone files an issue....

Comment thread MODULE.bazel

# Pinned repo
"transitive_dependency_with_type_of_pom",
"unpinned_transitive_dependency_with_type_of_pom",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should go through and remove more, but I guess if we add this it'll be one more line :)

@shs96c shs96c merged commit cc7ea60 into bazel-contrib:master Nov 19, 2025
6 checks passed
@tobyh-canva
Copy link
Copy Markdown

Hi @shs96c, do you know if this will be released soon? We're evaluating whether we should upgrade to 6.9 and add this patch, or wait for the 6.10 release. Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression in 6.8: Build failures with pom artifacts when fetch_sources = True and lockfile enabled

3 participants