Skip to content

Commit

Permalink
Merge pull request #87 from menny/jvm_import
Browse files Browse the repository at this point in the history
Use jvm_import rule
  • Loading branch information
menny committed Jun 21, 2021
2 parents 0f282f9 + f1955f3 commit 89e6dbc
Show file tree
Hide file tree
Showing 27 changed files with 728 additions and 1,160 deletions.
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@ This WORKSPACE will provide `mabel_rule` rule and `artifact` macro which will au
* Automatically detects which rule-type to create for a given dependency:
* `aar_import` for Android artifacts.
* `java_plugin` + `java_library` for annotation-processors. More about this [here](#annotation-processors).
* `kt_jvm_library` for Kotlin modules. If you do not use Kotlin, you can omit this argument.
* `java_import` for anything else.
* Allow implementation replacement for `java_import` and `aar_import`. Those can be replaced with another rule or macro. See `examples/android/program/BUILD.bazel` for an example.
* [`jvm_import`](rules/jvm_import/jvm_import.bzl) for anything else.
* Allow implementation replacement for `jvm_import` and `aar_import`. Those can be replaced with another rule or macro. See `examples/android/program/BUILD.bazel` for an example.
* Support custom Maven repo URLs and locking dependency for a Maven repository.
* Adds `licenses` data to `java_import` rules, if license is declared in the artifact's POM file. Also, adds license metadata to the targets' `tags` attribute:
* Adds `licenses` data to `jvm_import` rules, if license is declared in the artifact's POM file. Also, adds license metadata to the targets' `tags` attribute:
* `mabel_license_name` - The name of the license, as appears in the `pom.xml` file.
* `mabel_license_url` - The URL to the license's file, as appears in the `pom.xml` file.
* `mabel_license_detected_type` - The type of the license (`Apache`, `MIT`, `GPL`, etc.) as detected by `mabel`.
Expand All @@ -27,7 +26,7 @@ This WORKSPACE will provide `mabel_rule` rule and `artifact` macro which will au
* Profiles and placeholders.
* Version-specification.
* Dependencies that do not have POM.
* Exports the Maven coordinate as a tag in the `java_import` rule. This can help with Bazel's [pom_file](https://github.com/google/bazel-common/blob/master/tools/maven/pom_file.bzl) rule.
* Exports the Maven coordinate as a tag in the `jvm_import` rule. This can help with Bazel's [pom_file](https://github.com/google/bazel-common/blob/master/tools/maven/pom_file.bzl) rule.
* Calculates `sha256` for each remote artifact.
* Produces a _lock_ file that describes the dependency graph. This file should be checked into your repo.

Expand Down Expand Up @@ -165,7 +164,7 @@ This rule declares a Maven dependency to be resolved and import into your WORKSP
Attributes:

* `coordinate`: Maven coordinate in the form of `group-id:artifact-id:version`.
* `type`: What is the type of target(s) to create for this artifact. Default `auto`. Can be `jar`, `aar`, `kotlin`, `kotlin_aar`, `naive`, `processor`, `auto`. For more details, see [here](resolver/src/main/java/net/evendanan/bazel/mvn/api/model/TargetType.java).
* `type`: What is the type of target(s) to create for this artifact. Default `auto`. Can be `jar`, `aar`, `naive`, `processor`, `auto`. For more details, see [here](resolver/src/main/java/net/evendanan/bazel/mvn/api/model/TargetType.java).
* `test_only`: Mark this dependency to be used in tests only.
* `maven_exclude_deps`: List of Maven dependencies which should not be resolved. You can omit the `version` or both `artifact-id:version`.
* `repositories`: List of URLs that point to Maven servers. The default list includes Maven-Central.
Expand Down
4 changes: 1 addition & 3 deletions examples/android-kotlin/program/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
load("@build_bazel_rules_android//android:rules.bzl", "aar_import", "android_binary")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library", "kt_jvm_import", "kt_jvm_library")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")
load("@mabel//rules/maven_deps:mabel.bzl", "artifact", "mabel_rule")
load("//program/main_deps:dependencies.bzl", "generate_transitive_dependency_targets")
load(":g_artifact.bzl", "g_artifact")

generate_transitive_dependency_targets(
aar_import = aar_import,
kt_android_library = kt_android_library,
kt_jvm_import = kt_jvm_import,
kt_jvm_library = kt_jvm_library,
)

mabel_rule(
Expand Down
91 changes: 11 additions & 80 deletions examples/android/program/main_deps/dependencies.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Auto-generated by https://github.com/menny/mabel

# Loading a drop-in replacement for native.http_file
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_file")
load("@mabel//rules/jvm_import:jvm_import.bzl", "jvm_import")

def generate_workspace_rules(name = "generate_workspace_rules"):
"""
Expand Down Expand Up @@ -248,78 +249,24 @@ def _no_op_missing_aar_impl(name, **kwargs):
.format(name),
)

def _no_op_missing_kt_jvm_impl(name, **kwargs):
"""
This is a help macro for missing concrete rule implementation.
This will be used in cases when some dependencies require Kotlin rule implementation.
Args:
name: A unique name for this target.
**kwargs: Anything else. Not used.
"""

fail(
"Unable to create target {} since it is a kt_jvm_import which was not provided. Add argument kt_jvm_import when calling generate_transitive_dependency_targets."
.format(name),
)

def _no_op_missing_kt_jvm_lib_impl(name, **kwargs):
"""
This is a help macro for missing concrete rule implementation.
This will be used in cases when some dependencies require Kotlin rule implementation.
Args:
name: A unique name for this target.
**kwargs: Anything else. Not used.
"""

fail(
"Unable to create target {} since it is a kt_jvm_library which was not provided. Add argument kt_jvm_library when calling generate_transitive_dependency_targets."
.format(name),
)

def _no_op_missing_kt_android_impl(name, **kwargs):
"""
This is a help macro for missing concrete rule implementation.
This will be used in cases when some dependencies require Kotlin rule implementation.
Args:
name: A unique name for this target.
**kwargs: Anything else. Not used.
"""

fail(
"Unable to create target {} since it is a kt_android_library which was not provided. Add argument kt_android_library when calling generate_transitive_dependency_targets."
.format(name),
)

def generate_transitive_dependency_targets(
name = "generate_transitive_dependency_targets",
java_library = native.java_library,
java_plugin = native.java_plugin,
java_import = native.java_import,
aar_import = _no_op_missing_aar_impl,
kt_jvm_import = _no_op_missing_kt_jvm_impl,
kt_jvm_library = _no_op_missing_kt_jvm_lib_impl,
kt_android_library = _no_op_missing_kt_android_impl):
jvm_import = jvm_import,
aar_import = _no_op_missing_aar_impl):
"""
Macro to set up the transitive rules.
You can provide your own implementation of java_import, aar_import, etc. This can be used
You can provide your own implementation of jvm_import, aar_import, etc. This can be used
in cases where you need to shade (or jar_jar or jetify) your jars.
Args:
name: a unique name for this macro. Not needed to specify.
java_library: rule implementation for java_library. Defaults to native.java_library.
java_plugin: rule implementation for java_plugin. Defaults to native.java_plugin.
java_import: rule implementation for java_import. Defaults to native.java_import.
jvm_import: rule implementation for jvm_import. Defaults to jvm_import.
aar_import: rule implementation for aar_import. Required only if you have Android dependencies.
kt_jvm_import: rule implementation for kt_jvm_import. Required only if you have Kotlin dependencies.
kt_jvm_library: rule implementation for kt_jvm_library. Required only if you have Kotlin dependencies.
kt_android_library: rule implementation for kt_android_library. Required only if you have Android-Kotlin dependencies.
"""

# from androidx.activity:activity:1.0.0-alpha02
Expand Down Expand Up @@ -410,7 +357,7 @@ def generate_transitive_dependency_targets(
# This is a dependency of 'androidx.vectordrawable:vectordrawable:1.0.1'.
# This is a dependency of 'androidx.versionedparcelable:versionedparcelable:1.1.0-alpha01'.
# This is a dependency of 'androidx.viewpager:viewpager:1.0.0'.
java_import(
jvm_import(
name = "androidx_annotation__annotation__1_0_0",
jars = ["@androidx_annotation__annotation__1_0_0//file"],
testonly = False,
Expand Down Expand Up @@ -451,16 +398,7 @@ def generate_transitive_dependency_targets(
":androidx_vectordrawable__vectordrawable",
":androidx_vectordrawable__vectordrawable_animated",
],
exports = [
":androidx_annotation__annotation",
":androidx_collection__collection",
":androidx_core__core",
":androidx_cursoradapter__cursoradapter",
":androidx_fragment__fragment",
":androidx_legacy__legacy_support_core_utils",
":androidx_vectordrawable__vectordrawable",
":androidx_vectordrawable__vectordrawable_animated",
],
exports = [],
)

# from androidx.arch.core:core-common:2.0.0
Expand All @@ -479,7 +417,7 @@ def generate_transitive_dependency_targets(
# This is a dependency of 'androidx.lifecycle:lifecycle-livedata-core:2.0.0'.
# This is a dependency of 'androidx.lifecycle:lifecycle-livedata:2.0.0'.
# This is a dependency of 'androidx.lifecycle:lifecycle-runtime:2.0.0'.
java_import(
jvm_import(
name = "androidx_arch_core__core_common__2_0_0",
jars = ["@androidx_arch_core__core_common__2_0_0//file"],
testonly = False,
Expand Down Expand Up @@ -555,7 +493,7 @@ def generate_transitive_dependency_targets(
# This is a dependency of 'androidx.appcompat:appcompat:1.0.2'.
# This is a dependency of 'androidx.core:core:1.1.0-alpha01'.
# This is a dependency of 'androidx.versionedparcelable:versionedparcelable:1.1.0-alpha01'.
java_import(
jvm_import(
name = "androidx_collection__collection__1_0_0",
jars = ["@androidx_collection__collection__1_0_0//file"],
testonly = False,
Expand Down Expand Up @@ -762,14 +700,7 @@ def generate_transitive_dependency_targets(
":androidx_loader__loader",
":androidx_viewpager__viewpager",
],
exports = [
":androidx_activity__activity",
":androidx_annotation__annotation",
":androidx_core__core",
":androidx_lifecycle__lifecycle_viewmodel",
":androidx_loader__loader",
":androidx_viewpager__viewpager",
],
exports = [],
)

# from androidx.interpolator:interpolator:1.0.0
Expand Down Expand Up @@ -865,7 +796,7 @@ def generate_transitive_dependency_targets(
# from androidx.lifecycle:lifecycle-common:2.0.0
# This is a dependency of 'androidx.lifecycle:lifecycle-livedata-core:2.0.0'.
# This is a dependency of 'androidx.lifecycle:lifecycle-runtime:2.0.0'.
java_import(
jvm_import(
name = "androidx_lifecycle__lifecycle_common__2_0_0",
jars = ["@androidx_lifecycle__lifecycle_common__2_0_0//file"],
testonly = False,
Expand Down
Loading

0 comments on commit 89e6dbc

Please sign in to comment.