diff options
author | 2017-01-19 17:44:54 +0000 | |
---|---|---|
committer | 2017-01-19 18:05:24 +0000 | |
commit | 7d5b31f9cb33dd86542cd2cd0fea63954010fc00 (patch) | |
tree | 32ff0afd606c224ecd9dbb932ebfc53b06e19dcc /tools/build_defs/repo | |
parent | fc346a9814d6ee9de4fc0df45ee7ec20dcdce886 (diff) |
maven_rules.bzl: Fix maven coordinates order mismatch
Classifier should be provided in the form:
"groupId:artifactId:version[:packaging][:classifier]"
because that's what maven-dependency-plugin expects and not in the form:
"groupId:artifactId[:packaging][:classifier]:version"
as documented here: [1]. Also it was missed to reflect the classifier in
the output artifact name.
TEST PLAN:
WORKSPACE:
load("//tools:maven_rules.bzl", "maven_jar",
"maven_dependency_plugin")
maven_dependency_plugin()
maven_jar(
name = "jetty_server_sources",
artifact = "org.eclipse.jetty:jetty-server:9.3.11.v20160721:jar:sources",
sha1 = "b23cac190808baed928260b2c9beca3b1ed232b4",
)
BUILD:
java_library(
name = "jetty-server-sources",
exports = ["@jetty_server_sources//jar"],
)
$ bazel build :jetty-server-sources
[...]
Target //:jetty-server-sources up-to-date:
bazel-bin/libjetty-server-sources.jar
[1] https://maven.apache.org/pom.html#Maven_Coordinates
Fixes #2049.
--
Change-Id: I3297fb3676324cc6b4bb6ff6b2b6e18ce33f633c
Reviewed-on: https://cr.bazel.build/7213
PiperOrigin-RevId: 144972944
MOS_MIGRATED_REVID=144972944
Diffstat (limited to 'tools/build_defs/repo')
-rw-r--r-- | tools/build_defs/repo/maven_rules.bzl | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/tools/build_defs/repo/maven_rules.bzl b/tools/build_defs/repo/maven_rules.bzl index 90b1e3716f..9a15166df2 100644 --- a/tools/build_defs/repo/maven_rules.bzl +++ b/tools/build_defs/repo/maven_rules.bzl @@ -24,7 +24,10 @@ # 3) maven_dependency_plugin() # This rule downloads the maven-dependency-plugin used internally # for testing and the implementation for the fetching of artifacts. - +# +# Maven coordinates are expected to be in this form: +# groupId:artifactId:version[:packaging][:classifier] +# # Installation requirements prior to using this rule: # 1) Maven binary: `mvn` # 2) Maven plugin: `maven-dependency-plugin:2.10` @@ -78,9 +81,9 @@ def _create_coordinates(fully_qualified_name, packaging="jar"): # downloads the correct artifact. fully_qualified_name = "%s:%s" % (fully_qualified_name, packaging) elif len(parts) == 4: - group_id, artifact_id, packaging, version = parts + group_id, artifact_id, version, packaging = parts elif len(parts) == 5: - group_id, artifact_id, packaging, classifier, version = parts + group_id, artifact_id, version, packaging, classifier = parts else: fail("Invalid fully qualified name for artifact: %s" % fully_qualified_name) @@ -102,9 +105,11 @@ def _create_paths(ctx, coordinates): """Creates a struct that contains the paths to create the cache WORKSPACE""" # e.g. guava-18.0.jar - artifact_filename = "%s-%s.%s" % (coordinates.artifact_id, - coordinates.version, - coordinates.packaging) + artifact_filename = "%s-%s" % (coordinates.artifact_id, + coordinates.version) + if coordinates.classifier: + artifact_filename += "-" + coordinates.classifier + artifact_filename += "." + coordinates.packaging sha1_filename = "%s.sha1" % artifact_filename # e.g. com/google/guava/guava/18.0 |