Skip to content

Commit

Permalink
Shade kotlinx metadata in Dagger's artifacts.
Browse files Browse the repository at this point in the history
This CL also removes an extra version of auto-common that we jarjared and shaded into the Hilt compiler artifacts. In particular, since Hilt's compiler artifacts depend transitively on the dagger-spi artifact, we can shade our auto-common references to use the version of auto-common shaded into dagger-spi instead of creating another version of the shaded classes in the hilt compiler artifacts.

I've also updated the `gen_maven_artifact` macro to exclude are shaded dependencies from the `artifact_target_maven_deps` since that list is supposed to mimic our pom file dependencies.

RELNOTES=Fixes #3701: Shade kotlinx metadata in Dagger's artifacts.
PiperOrigin-RevId: 530982700
  • Loading branch information
bcorso authored and Dagger Team committed May 10, 2023
1 parent d128ca2 commit d593e01
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 24 deletions.
6 changes: 0 additions & 6 deletions java/dagger/hilt/android/processor/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ gen_maven_artifact(
"//java/dagger/hilt/processor/internal/uninstallmodules:aggregated_uninstall_modules_metadata",
],
artifact_target_maven_deps = [
"com.google.auto:auto-common",
"com.google.code.findbugs:jsr305",
"com.google.dagger:dagger-compiler",
"com.google.dagger:dagger",
Expand All @@ -91,7 +90,6 @@ gen_maven_artifact(
"javax.inject:javax.inject",
"net.ltgt.gradle.incap:incap",
"org.jetbrains.kotlin:kotlin-stdlib",
"org.jetbrains.kotlinx:kotlinx-metadata-jvm",
],
javadoc_android_api_level = 32,
javadoc_root_packages = [
Expand All @@ -102,10 +100,6 @@ gen_maven_artifact(
javadoc_srcs = [
"//java/dagger/hilt:hilt_processing_filegroup",
],
# The shaded deps are added using jarjar, but they won't be shaded until later
# due to: https://github.com/google/dagger/issues/2765. For the shaded rules see
# util/deploy-hilt.sh
shaded_deps = ["//third_party/java/auto:common"],
)

filegroup(
Expand Down
6 changes: 0 additions & 6 deletions java/dagger/hilt/processor/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ gen_maven_artifact(
"//java/dagger/hilt/processor/internal/uninstallmodules:aggregated_uninstall_modules_metadata",
],
artifact_target_maven_deps = [
"com.google.auto:auto-common",
"com.google.code.findbugs:jsr305",
"com.google.dagger:dagger-compiler",
"com.google.dagger:dagger",
Expand All @@ -113,7 +112,6 @@ gen_maven_artifact(
"javax.inject:javax.inject",
"net.ltgt.gradle.incap:incap",
"org.jetbrains.kotlin:kotlin-stdlib",
"org.jetbrains.kotlinx:kotlinx-metadata-jvm",
],
javadoc_android_api_level = 32,
javadoc_root_packages = [
Expand All @@ -124,10 +122,6 @@ gen_maven_artifact(
javadoc_srcs = [
"//java/dagger/hilt:hilt_processing_filegroup",
],
# The shaded deps are added using jarjar, but they won't be shaded until later
# due to: https://github.com/google/dagger/issues/2765. For the shaded rules see
# util/deploy-hilt.sh
shaded_deps = ["//third_party/java/auto:common"],
)

filegroup(
Expand Down
2 changes: 0 additions & 2 deletions java/dagger/internal/codegen/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ gen_maven_artifact(
"//java/dagger/internal/codegen/xprocessing",
],
artifact_target_maven_deps = [
"com.google.auto:auto-common",
"com.google.code.findbugs:jsr305",
"com.google.dagger:dagger-producers",
"com.google.dagger:dagger-spi",
Expand All @@ -103,7 +102,6 @@ gen_maven_artifact(
"net.ltgt.gradle.incap:incap",
"org.checkerframework:checker-compat-qual",
"org.jetbrains.kotlin:kotlin-stdlib",
"org.jetbrains.kotlinx:kotlinx-metadata-jvm",
],
javadoc_root_packages = ["dagger.internal.codegen"],
# The javadocs should only include ComponentProcessor.java, since that is the only class used
Expand Down
2 changes: 1 addition & 1 deletion java/dagger/spi/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ gen_maven_artifact(
"//java/dagger/spi/model",
],
artifact_target_maven_deps = [
"com.google.auto:auto-common",
"com.google.code.findbugs:jsr305",
"com.google.dagger:dagger-producers",
"com.google.dagger:dagger",
Expand All @@ -82,6 +81,7 @@ gen_maven_artifact(
# util/deploy-dagger.sh
shaded_deps = [
"//third_party/java/auto:common",
"@maven//:org_jetbrains_kotlinx_kotlinx_metadata_jvm",
"//java/dagger/internal/codegen/xprocessing:xprocessing-jar",
],
)
16 changes: 13 additions & 3 deletions tools/maven.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ load(":maven_info.bzl", "MavenInfo", "collect_maven_info")
load("@google_bazel_common//tools/javadoc:javadoc.bzl", "javadoc_library")
load("@google_bazel_common//tools/jarjar:jarjar.bzl", "jarjar_library")

SHADED_MAVEN_DEPS = [
"com.google.auto:auto-common",
"org.jetbrains.kotlinx:kotlinx-metadata-jvm",
]

def pom_file(name, targets, artifact_name, artifact_id, packaging = None, **kwargs):
default_pom_file(
name = name,
Expand All @@ -34,7 +39,12 @@ def pom_file(name, targets, artifact_name, artifact_id, packaging = None, **kwar
"{artifact_id}": artifact_id,
"{packaging}": packaging or "jar",
},
excluded_artifacts = ["com.google.auto:auto-common"],
# NOTE: The shaded maven dependencies are excluded from every Dagger pom file.
# Thus, if a Dagger artifact needs the dependencies it must jarjar the dependency
# into the artifact itself using the gen_maven_artifact.shaded_deps or get it from
# a transitive Dagger artifact as a dependency. In addition, the artifact must add
# the shade rules in the deploy scripts, e.g. deploy-dagger.sh.
excluded_artifacts = SHADED_MAVEN_DEPS,
**kwargs
)

Expand All @@ -54,7 +64,6 @@ def gen_maven_artifact(
javadoc_exclude_packages = None,
javadoc_android_api_level = None,
shaded_deps = None,
shaded_rules = None,
manifest = None,
lint_deps = None,
proguard_specs = None):
Expand Down Expand Up @@ -282,7 +291,8 @@ def _validate_maven_deps_impl(ctx):
actual_maven_deps = [_strip_artifact_version(artifact) for artifact in maven_nearest_artifacts]
_validate_list(
"artifact_target_maven_deps",
actual_maven_deps,
# Exclude shaded maven deps from this list since they're not actual dependencies.
[dep for dep in actual_maven_deps if dep not in SHADED_MAVEN_DEPS],
expected_maven_deps,
ctx.attr.banned_maven_deps,
)
Expand Down
3 changes: 3 additions & 0 deletions tools/shader/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ configurations {
}

shadowJar {
// This transform is needed so that services get relocated/shaded as well.
mergeServiceFiles()

archiveClassifier = "" // postfix for output jar
configurations = [project.configurations.shaded]
transform(ManifestMerger.class)
Expand Down
6 changes: 2 additions & 4 deletions util/deploy-dagger.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ _deploy \
gwt/libgwt.jar \
""

# This artifact uses the shaded classes from dagger-spi, so we use the same
# shading rules so that our references to those classes are shaded the same way.
_deploy \
"com.google.auto.common,dagger.spi.shaded.auto.common;androidx.room.compiler,dagger.spi.shaded.androidx.room.compiler" \
"com.google.auto.common,dagger.spi.shaded.auto.common;androidx.room.compiler,dagger.spi.shaded.androidx.room.compiler;kotlinx.metadata,dagger.spi.shaded.kotlinx.metadata" \
java/dagger/internal/codegen/artifact.jar \
java/dagger/internal/codegen/pom.xml \
java/dagger/internal/codegen/artifact-src.jar \
Expand All @@ -70,7 +68,7 @@ _deploy \
""

_deploy \
"com.google.auto.common,dagger.spi.shaded.auto.common;androidx.room.compiler,dagger.spi.shaded.androidx.room.compiler" \
"com.google.auto.common,dagger.spi.shaded.auto.common;androidx.room.compiler,dagger.spi.shaded.androidx.room.compiler;kotlinx.metadata,dagger.spi.shaded.kotlinx.metadata" \
java/dagger/spi/artifact.jar \
java/dagger/spi/pom.xml \
java/dagger/spi/artifact-src.jar \
Expand Down
4 changes: 2 additions & 2 deletions util/deploy-hilt.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ _deploy \
""

_deploy \
"com.google.auto.common,dagger.hilt.android.shaded.auto.common;androidx.room.compiler,dagger.spi.shaded.androidx.room.compiler" \
"com.google.auto.common,dagger.spi.shaded.auto.common;androidx.room.compiler,dagger.spi.shaded.androidx.room.compiler;kotlinx.metadata,dagger.spi.shaded.kotlinx.metadata" \
java/dagger/hilt/processor/artifact.jar \
java/dagger/hilt/processor/pom.xml \
java/dagger/hilt/processor/artifact-src.jar \
java/dagger/hilt/processor/artifact-javadoc.jar \
""

_deploy \
"com.google.auto.common,dagger.hilt.android.shaded.auto.common;androidx.room.compiler,dagger.spi.shaded.androidx.room.compiler" \
"com.google.auto.common,dagger.spi.shaded.auto.common;androidx.room.compiler,dagger.spi.shaded.androidx.room.compiler;kotlinx.metadata,dagger.spi.shaded.kotlinx.metadata" \
java/dagger/hilt/android/processor/artifact.jar \
java/dagger/hilt/android/processor/pom.xml \
java/dagger/hilt/android/processor/artifact-src.jar \
Expand Down

0 comments on commit d593e01

Please sign in to comment.