diff --git a/coursier.bzl b/coursier.bzl index 4ae4578ab..a048aceb8 100644 --- a/coursier.bzl +++ b/coursier.bzl @@ -565,6 +565,7 @@ def make_coursier_dep_tree( version_conflict_policy, fail_on_missing_checksum, fetch_sources, + fetch_javadoc, use_unsafe_shared_cache, timeout, report_progress_prefix="", @@ -593,7 +594,7 @@ def make_coursier_dep_tree( for coord in artifact_coordinates: # Undo any `,classifier=` suffix from `utils.artifact_coordinate`. cmd.extend(["--force-version", coord.split(",classifier=")[0]]) - cmd.extend(["--artifact-type", ",".join(SUPPORTED_PACKAGING_TYPES + ["src"])]) + cmd.extend(["--artifact-type", ",".join(SUPPORTED_PACKAGING_TYPES + ["src", "doc"])]) cmd.append("--verbose" if _is_verbose(repository_ctx) else "--quiet") cmd.append("--no-default") cmd.extend(["--json-output-file", "dep-tree.json"]) @@ -613,8 +614,11 @@ def make_coursier_dep_tree( for a in excluded_artifacts: cmd.extend(["--exclude", ":".join([a["group"], a["artifact"]])]) - if fetch_sources: - cmd.append("--sources") + if fetch_sources or fetch_javadoc: + if fetch_sources: + cmd.append("--sources") + if fetch_javadoc: + cmd.append("--javadoc") cmd.append("--default=true") environment = {} @@ -634,6 +638,7 @@ def make_coursier_dep_tree( repository_ctx.report_progress( "%sResolving and fetching the transitive closure of %s artifact(s).." % ( report_progress_prefix, len(artifact_coordinates))) + exec_result = repository_ctx.execute( cmd, timeout = timeout, @@ -709,6 +714,7 @@ def _coursier_fetch_impl(repository_ctx): repository_ctx.attr.version_conflict_policy, repository_ctx.attr.fail_on_missing_checksum, repository_ctx.attr.fetch_sources, + repository_ctx.attr.fetch_javadoc, repository_ctx.attr.use_unsafe_shared_cache, repository_ctx.attr.resolve_timeout, ) @@ -739,6 +745,7 @@ def _coursier_fetch_impl(repository_ctx): repository_ctx.attr.version_conflict_policy, repository_ctx.attr.fail_on_missing_checksum, repository_ctx.attr.fetch_sources, + repository_ctx.attr.fetch_javadoc, repository_ctx.attr.use_unsafe_shared_cache, repository_ctx.attr.resolve_timeout, report_progress_prefix = "Second pass for Jetified Artifacts: ", @@ -979,6 +986,7 @@ pinned_coursier_fetch = repository_rule( "repositories": attr.string_list(), # list of repository objects, each as json "artifacts": attr.string_list(), # list of artifact objects, each as json "fetch_sources": attr.bool(default = False), + "fetch_javadoc": attr.bool(default = False), "generate_compat_repositories": attr.bool(default = False), # generate a compatible layer with repositories for each artifact "maven_install_json": attr.label(allow_single_file = True), "override_targets": attr.string_dict(default = {}), @@ -1007,6 +1015,7 @@ coursier_fetch = repository_rule( "artifacts": attr.string_list(), # list of artifact objects, each as json "fail_on_missing_checksum": attr.bool(default = True), "fetch_sources": attr.bool(default = False), + "fetch_javadoc": attr.bool(default = False), "use_unsafe_shared_cache": attr.bool(default = False), "excluded_artifacts": attr.string_list(default = []), # list of artifacts to exclude "generate_compat_repositories": attr.bool(default = False), # generate a compatible layer with repositories for each artifact diff --git a/defs.bzl b/defs.bzl index b0f7dac28..153406711 100644 --- a/defs.bzl +++ b/defs.bzl @@ -28,6 +28,7 @@ def maven_install( artifacts = [], fail_on_missing_checksum = True, fetch_sources = False, + fetch_javadoc = False, use_unsafe_shared_cache = False, excluded_artifacts = [], generate_compat_repositories = False, @@ -51,6 +52,7 @@ def maven_install( Supports URLs with HTTP Basic Authentication, e.g. "https://username:password@example.com". artifacts: A list of Maven artifact coordinates in the form of `group:artifact:version`. fetch_sources: Additionally fetch source JARs. + fetch_javadoc: Additionally fetch javadoc JARs. use_unsafe_shared_cache: Download artifacts into a persistent shared cache on disk. Unsafe as Bazel is currently unable to detect modifications to the cache. excluded_artifacts: A list of Maven artifact coordinates in the form of `group:artifact` to be @@ -110,6 +112,7 @@ def maven_install( artifacts = artifacts_json_strings, fail_on_missing_checksum = fail_on_missing_checksum, fetch_sources = fetch_sources, + fetch_javadoc = fetch_javadoc, use_unsafe_shared_cache = use_unsafe_shared_cache, excluded_artifacts = excluded_artifacts_json_strings, generate_compat_repositories = generate_compat_repositories, @@ -130,6 +133,7 @@ def maven_install( artifacts = artifacts_json_strings, maven_install_json = maven_install_json, fetch_sources = fetch_sources, + fetch_javadoc = fetch_javadoc, generate_compat_repositories = generate_compat_repositories, override_targets = override_targets, strict_visibility = strict_visibility, diff --git a/private/dependency_tree_parser.bzl b/private/dependency_tree_parser.bzl index 65f5f1bac..87a8776d1 100644 --- a/private/dependency_tree_parser.bzl +++ b/private/dependency_tree_parser.bzl @@ -100,6 +100,10 @@ def _generate_imports(repository_ctx, dep_tree, explicit_artifacts, neverlink_ar elif repository_ctx.attr.fetch_sources and get_classifier(artifact["coord"]) == "sources": # We already processed the sources above, so skip them here. pass + elif repository_ctx.attr.fetch_javadoc and get_classifier(artifact["coord"]) == "javadoc": + seen_imports[target_label] = True + all_imports.append( + "filegroup(\n\tname = \"%s\",\n\tsrcs = [\"%s\"],\n\ttags = [\"javadoc\"],\n)" % (target_label, artifact_path)) elif get_packaging(artifact["coord"]) == "json": seen_imports[target_label] = True versioned_target_alias_label = "%s_extension" % escape(artifact["coord"])