diff options
author | 2017-11-14 10:20:45 -0800 | |
---|---|---|
committer | 2017-11-14 10:22:58 -0800 | |
commit | 431b6436373c9feb5d03e488ff72f822bbe55b2d (patch) | |
tree | a433709dba855e2f32696309c798246462f8086a /tools/build_defs/repo | |
parent | c47c13fd0c489232c8d1d801cbcbd35efb251cbf (diff) |
Add deps attributes to the Skylark maven_{a,j}ar rules.
The deps are passed through into the generated java_import and aar_import rules. This is necessary for AARs with resource dependencies since maven_aar ignores transitive dependencies. It's less significant for the Java rules, since typically JARs on Maven are compiled class files and as such only have runtime dependencies.
Example usage:
```
# WORKSPACE
load("@bazel_tools//tools/build_defs/repo:maven_rules.bzl", "maven_aar")
maven_aar(
name = "android_image_cropper",
artifact = "com.theartofdev.edmodo:android-image-cropper:2.3.1",
deps = [
"@androidsdk//com.android.support:appcompat-v7-24.1.1",
],
)
```
Fixes https://github.com/bazelbuild/bazel/issues/2863.
Fixes https://github.com/bazelbuild/bazel/issues/3980.
Also, cleans up some broken stuff in the tests (sadly, they don't run on jenkins, so nothing caught that they were broken). test_maven_jar_with_classifier_skylark still does not work, so I disabled.
RELNOTES: Add deps attribute to Skylark maven_aar and maven_jar workspace rules.
PiperOrigin-RevId: 175698282
Diffstat (limited to 'tools/build_defs/repo')
-rw-r--r-- | tools/build_defs/repo/maven_rules.bzl | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/tools/build_defs/repo/maven_rules.bzl b/tools/build_defs/repo/maven_rules.bzl index 9a15166df2..a27431cf97 100644 --- a/tools/build_defs/repo/maven_rules.bzl +++ b/tools/build_defs/repo/maven_rules.bzl @@ -146,6 +146,9 @@ _maven_jar_build_file_template = """ java_import( name = 'jar', jars = ['{artifact_filename}'], + deps = [ +{deps_string} + ], visibility = ['//visibility:public'] ) @@ -161,6 +164,9 @@ _maven_aar_build_file_template = """ aar_import( name = 'aar', aar = '{artifact_filename}', + deps = [ +{deps_string} + ], visibility = ['//visibility:public'], ) @@ -172,8 +178,11 @@ filegroup( # Provides the syntax "@jar_name//jar" for dependencies def _generate_build_file(ctx, template, paths): + deps_string = "\n".join(["'%s'," % dep for dep in ctx.attr.deps]) contents = template.format( - rule_name = ctx.name, artifact_filename = paths.artifact_filename) + rule_name = ctx.name, + artifact_filename = paths.artifact_filename, + deps_string = deps_string) ctx.file('%s/BUILD' % paths.symlink_dir, contents, False) @@ -268,7 +277,11 @@ _common_maven_rule_attrs = { mandatory = True, ), "sha1": attr.string(default = ""), - "settings": attr.label(default = None) + "settings": attr.label(default = None), + # Allow the user to specify deps for the generated java_import or aar_import + # since maven_jar and maven_aar do not automatically pull in transitive + # dependencies. + "deps": attr.label_list(), } def _maven_jar_impl(ctx): |