diff options
-rwxr-xr-x | src/test/shell/bazel/maven_skylark_test.sh | 19 | ||||
-rw-r--r-- | tools/build_defs/repo/maven_rules.bzl | 7 |
2 files changed, 15 insertions, 11 deletions
diff --git a/src/test/shell/bazel/maven_skylark_test.sh b/src/test/shell/bazel/maven_skylark_test.sh index 914d619658..83676c0972 100755 --- a/src/test/shell/bazel/maven_skylark_test.sh +++ b/src/test/shell/bazel/maven_skylark_test.sh @@ -46,9 +46,12 @@ EOF } # This function takes an optional url argument: mirror. If one is passed, a -# mirror of maven central will be set for the url. +# mirror of maven central will be set for the url. It also creates a `BUILD` +# file in the same directory as $local_maven_settings so that it can be used as +# a label in WORKSPACE. function setup_local_maven_settings_xml() { - local_maven_settings_xml=$(pwd)/settings.xml + local_maven_settings_xml=settings.xml + touch $(pwd)/BUILD cat > $local_maven_settings_xml <<EOF <!-- # DO NOT EDIT: automatically generated settings.xml for maven_dependency_plugin --> <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" @@ -89,7 +92,7 @@ maven_jar( name = 'endangered', artifact = "com.example.carnivore:carnivore:$version", sha1 = '$sha1', - settings = '$local_maven_settings_xml', + settings = '//:$local_maven_settings_xml', ) bind(name = 'mongoose', actual = '@endangered//jar') @@ -132,7 +135,7 @@ maven_aar( name = "herbivore", artifact = "com.example.carnivore:herbivore:1.21", sha1 = "$sha1", - settings = "$local_maven_settings_xml", + settings = "//:$local_maven_settings_xml", ) EOF bazel build //java/com/app || fail "Expected build to succeed" @@ -155,7 +158,7 @@ load("@bazel_tools//tools/build_defs/repo:maven_rules.bzl", "maven_jar") maven_jar( name = 'endangered', artifact = "com.example.carnivore:carnivore:$version", - settings = '$local_maven_settings_xml', + settings = '//:$local_maven_settings_xml', ) bind(name = 'mongoose', actual = '@endangered//jar') @@ -176,7 +179,7 @@ load("@bazel_tools//tools/build_defs/repo:maven_rules.bzl", "maven_jar") maven_jar( name = 'endangered', artifact = "com.example.carnivore:carnivore:$version", - settings = '$local_maven_settings_xml', + settings = '//:$local_maven_settings_xml', ) bind(name = 'mongoose', actual = '@endangered//jar') @@ -202,7 +205,7 @@ maven_jar( name = 'endangered', artifact = "com.example.carnivore:carnivore:1.24", sha1 = '$wrong_sha1', - settings = '$local_maven_settings_xml', + settings = '//:$local_maven_settings_xml', ) bind(name = 'mongoose', actual = '@endangered//jar') @@ -225,7 +228,7 @@ maven_jar( name = 'endangered', artifact = "com.example.carnivore:carnivore:$version", server = "attr_not_implemented", - settings = "$local_maven_settings_xml", + settings = "//:$local_maven_settings_xml", ) bind(name = 'mongoose', actual = '@endangered//jar') diff --git a/tools/build_defs/repo/maven_rules.bzl b/tools/build_defs/repo/maven_rules.bzl index 1e05954ba0..90b1e3716f 100644 --- a/tools/build_defs/repo/maven_rules.bzl +++ b/tools/build_defs/repo/maven_rules.bzl @@ -181,8 +181,9 @@ def _file_exists(ctx, filename): def _mvn_download(ctx, paths, fully_qualified_name): # If a custom settings file exists, we'll use that. If not, Maven will use the default settings. mvn_flags = "" - if hasattr(ctx.attr, "settings") and ctx.attr.settings != "": - mvn_flags += "-s %s " % ctx.attr.settings + if hasattr(ctx.attr, "settings") and ctx.attr.settings != None: + ctx.symlink(ctx.attr.settings, "settings.xml") + mvn_flags += "-s %s " % "settings.xml" # dependency:get step. Downloads the artifact into the local repository. mvn_get = MVN_PLUGIN + ":get" @@ -262,7 +263,7 @@ _common_maven_rule_attrs = { mandatory = True, ), "sha1": attr.string(default = ""), - "settings": attr.string(default = "") + "settings": attr.label(default = None) } def _maven_jar_impl(ctx): |