Skip to content

Commit

Permalink
Add kotlin-stdlib to EntryPointAccessors dependencies.
Browse files Browse the repository at this point in the history
Otherwise, this breaks java-only projects (#3119)

RELNOTES=N/A
PiperOrigin-RevId: 417157672
  • Loading branch information
bcorso authored and Dagger Team committed Dec 19, 2021
1 parent 66750f1 commit b6701f5
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 17 deletions.
19 changes: 2 additions & 17 deletions java/dagger/hilt/android/BUILD
Expand Up @@ -16,7 +16,6 @@
# A library based on Hilt that provides standard components and automated injection for Android.
load("//:build_defs.bzl", "POM_VERSION")
load("//tools:maven.bzl", "gen_maven_artifact")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")

package(default_visibility = ["//:src"])

Expand Down Expand Up @@ -207,6 +206,7 @@ gen_maven_artifact(
"com.google.dagger:dagger",
"com.google.dagger:hilt-core",
"javax.inject:javax.inject",
"org.jetbrains.kotlin:kotlin-stdlib",
],
artifact_target_maven_deps_banned = [
"com.google.guava:guava",
Expand All @@ -233,7 +233,7 @@ gen_maven_artifact(
)

kt_android_library(
name = "entry_point_accessors_internal",
name = "entry_point_accessors",
srcs = ["EntryPointAccessors.kt"],
deps = [
"//java/dagger/hilt:entry_point",
Expand All @@ -246,21 +246,6 @@ kt_android_library(
],
)

alias(
name = "entry_point_accessors",
actual = ":entry_point_accessors_internal_kt",
)

alias(
name = "libentry_point_accessors.jar",
actual = ":entry_point_accessors_internal_kt.jar",
)

alias(
name = "libentry_point_accessors-src.jar",
actual = ":entry_point_accessors_internal_kt-sources.jar",
)

filegroup(
name = "srcs_filegroup",
srcs = glob(["*"]),
Expand Down
1 change: 1 addition & 0 deletions java/dagger/hilt/android/testing/BUILD
Expand Up @@ -231,6 +231,7 @@ gen_maven_artifact(
"com.google.dagger:hilt-android",
"javax.inject:javax.inject",
"junit:junit",
"org.jetbrains.kotlin:kotlin-stdlib",
],
artifact_target_maven_deps_banned = [
"com.google.guava:guava",
Expand Down
59 changes: 59 additions & 0 deletions tools/bazel_compat.bzl
@@ -0,0 +1,59 @@
# Copyright (C) 202 The Dagger Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""Macros for building with Bazel.
"""

def compat_kt_android_library(name, **kwargs):
bazel_kt_android_library(name, kwargs)

def bazel_kt_android_library(name, **kwargs):
"""A macro that wraps Bazel's kt_android_library.
This macro wraps Bazel's kt_android_library to output the jars files
in the expected locations.
Args:
name: the name of the library.
**kwargs: Additional arguments of the library.
"""

# Export the kotlin_stdlib, otherwise it will be missing from java-only projects.
# See https://github.com/google/dagger/issues/3119
kwargs["exports"] = kwargs.get("exports", []) + [
"@maven//:org_jetbrains_kotlin_kotlin_stdlib",
]

# TODO(b/203519416): Bazel's kt_android_library outputs its jars under a target
# suffixed with "_kt". Thus, we have to do a bit of name aliasing to ensure that
# the jars exist at the expected targets.
kt_android_library(
name = name + "_internal",
**kwargs
)

alias(
name = name,
actual = ":{}_internal_kt" % name,
)

alias(
name = "lib{}.jar" % name,
actual = ":{}_internal_kt.jar" % name,
)

alias(
name = "lib{}-src.jar",
actual = ":{}_internal_kt-sources.jar",
)

0 comments on commit b6701f5

Please sign in to comment.