diff options
author | 2016-12-02 17:58:03 +0000 | |
---|---|---|
committer | 2016-12-02 19:09:05 +0000 | |
commit | a110ac400190c90a45856f15482c8d0952c542f5 (patch) | |
tree | 3e0f4e69a2dab1c4d539c84dbae6e6223c783534 /src/test | |
parent | 432e83ed4a282d152cfd2bff1c6dfe7542194e3b (diff) |
Make the settings attribute of Skylark maven_jar and maven_aar a label.
Fixes https://github.com/bazelbuild/bazel/issues/2117.
The settings attribute allows you to optional specify a custom Maven
settings.xml file as a label. Previously, this attribute was an absolute path.
As an absolute path it cannot really be used to specify a file in the workspace
because each developer may install the workspace in a different location.
And if the settings.xml cannot be included in the workspace, the developers may
as well use one of Maven's default locations for settings.xml.
Now the attribute is a label. An example use case is:
$ cat WORKSPACE
load("@bazel_tools//tools/build_defs/repo:maven_rules.bzl")
maven_jar(
name = "guava",
artifact = "com.google.guava:guava:19.0",
settings = "//:my_custom_settings.xml",
)
$ cat BUILD
java_library(
srcs = glob(["**/*.java"]),
deps = ["@guava//jar"],
)
$ cat my_custom_settings.xml
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>planetmirror.com</id>
<name>PlanetMirror Australia</name>
<url>http://downloads.planetmirror.com/pub/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
</settings>
Note that `settings = "my_custom_settings.xml"` will not work as the workspace
rule will not know to look in the main workspace.
RELNOTES[INC]: Skylark maven_jar and maven_aar settings attribute is now a label so
it can be checked into your workspace.
--
PiperOrigin-RevId: 140861633
MOS_MIGRATED_REVID=140861633
Diffstat (limited to 'src/test')
-rwxr-xr-x | src/test/shell/bazel/maven_skylark_test.sh | 19 |
1 files changed, 11 insertions, 8 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') |