Skip to content

Commit

Permalink
Fix part of #59: Update Dagger structure & version from 2.28.1 to 2.41 (
Browse files Browse the repository at this point in the history
#4931)

## Explanation
Fix part of #59

This PR introduces a simplification to Dagger setup throughout the Bazel
build graph by defining a single top-level ``dagger_rules()`` invocation
rather than introducing up to one per directory. The new approach
actually matches Dagger documentation for how it should be setup:
https://github.com/google/dagger/blob/f41033cc448eb7bdb83af2356c8802f1208d1824/examples/bazel/BUILD#L20.

Semantically, this mainly serves to centralize the exported Dagger
dependencies to a single library. Depending on this new top-level
``//:dagger`` library will still enable Dagger annotation processing and
code generation for the library depending on it, so it's not expected to
result in any significant performance improvements for the build graph.

Note that this PR also makes some attempt at removing cases when Dagger
isn't needed as a dependency at all (though this will be done in much
more significant detail in downstream PRs), and in some cases Dagger was
added just for implicitly depending on javax annotations (which can be
depended on directly).

There are also a number of version upgrades happening in this PR in
preparation for upgrading to Kotlin 1.6 (in #4937) since older Dagger
has some compatibility issues with newer Kotlin:
- Dagger is being upgraded to 2.41 from the current 2.28.1.
- The implicit Kotlin stdlib-jdk8 dependency is being bumped from 1.4.10
to 1.5.32 (this could be significant, but note that we are already using
the 1.5.0 base Kotlin SDK). Note that this resulted in some additional
Proguard exemptions for production builds. These *should* be okay to
ignore, but they will be reevaluated in #4937.
- Guava is being specially handled to force the Android version of Guava
(and specifically 31.0.1 which is needed by the newer version of
Dagger). Without this override the JRE version would be used which would
cause Desugaring and runtime problems in production builds.
- Other dependencies were updated or explicitly listed, as needed, for
the Dagger & Guava changes:
  - com.google.errorprone:error_prone_annotations: 2.9.0 -> 2.11.0
  - com.google.guava:failureaccess: 1.0.1 (currently used version)
  - com.google.j2objc:j2objc-annotations: 1.3 (currently used version)
- org.checkerframework:checker-compat-qual: 2.5.5 (currently used
version)
  - org.checkerframework:checker-qual: 3.13.0 -> 3.21.3

It was noticed that the tracking for Guava's third-party license was
removed. This is due to Guava now being explicitly depended on rather
than being managed by rules_jvm_external. #5397 was filed to track
properly including all third-party licenses, not just those from Maven.
Addressing that issue will result in Guava's license being included
again in production builds.

Finally, a ``ExplorationProgressListener`` binding was removed from
``ExplorationProgressModuleTest`` because it was noticed during
development that it isn't actually used.

## Essential Checklist
- [x] The PR title and explanation each start with "Fix #bugnum: " (If
this PR fixes part of an issue, prefix the title with "Fix part of
#bugnum: ...".)
- [x] Any changes to
[scripts/assets](https://github.com/oppia/oppia-android/tree/develop/scripts/assets)
files have their rationale included in the PR explanation.
- [x] The PR follows the [style
guide](https://github.com/oppia/oppia-android/wiki/Coding-style-guide).
- [x] The PR does not contain any unnecessary code changes from Android
Studio
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#undo-unnecessary-changes)).
- [x] The PR is made from a branch that's **not** called "develop" and
is up-to-date with "develop".
- [x] The PR is **assigned** to the appropriate reviewers
([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#clarification-regarding-assignees-and-reviewers-section)).

## For UI-specific PRs only
N/A -- build infrastructure-only change.

---------

Co-authored-by: Adhiambo Peres <[email protected]>
Co-authored-by: Sean Lip <[email protected]>
  • Loading branch information
3 people authored May 27, 2024
1 parent e57643b commit 6b724ac
Show file tree
Hide file tree
Showing 149 changed files with 631 additions and 790 deletions.
3 changes: 3 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# TODO(#1532): Rename file to 'BUILD' post-Gradle.

load("@dagger//:workspace_defs.bzl", "dagger_rules")
load("//:build_flavors.bzl", "AVAILABLE_FLAVORS", "define_oppia_aab_binary_flavor", "transform_android_manifest")
load("//:version.bzl", "MAJOR_VERSION", "MINOR_VERSION", "OPPIA_DEV_KITKAT_VERSION_CODE", "OPPIA_DEV_VERSION_CODE")

Expand Down Expand Up @@ -137,3 +138,5 @@ package_group(
define_oppia_aab_binary_flavor(flavor = flavor)
for flavor in AVAILABLE_FLAVORS
]

dagger_rules()
23 changes: 17 additions & 6 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ This file lists and imports all external dependencies needed to build Oppia Andr

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_jar")
load("//third_party:versions.bzl", "HTTP_DEPENDENCY_VERSIONS", "get_maven_dependencies")
load("//third_party:versions.bzl", "HTTP_DEPENDENCY_VERSIONS", "MAVEN_REPOSITORIES", "get_maven_dependencies")

# Android SDK configuration. For more details, see:
# https://docs.bazel.build/versions/master/be/android.html#android_sdk_repository
Expand Down Expand Up @@ -184,14 +184,25 @@ maven_install(
duplicate_version_warning = "error",
fail_if_repin_required = True,
maven_install_json = "//third_party:maven_install.json",
repositories = DAGGER_REPOSITORIES + [
"https://maven.fabric.io/public",
"https://maven.google.com",
"https://repo1.maven.org/maven2",
],
override_targets = {
"com.google.guava:guava": "@//third_party:com_google_guava_guava",
},
repositories = DAGGER_REPOSITORIES + MAVEN_REPOSITORIES,
strict_visibility = True,
)

load("@maven//:defs.bzl", "pinned_maven_install")

pinned_maven_install()

http_jar(
name = "guava_android",
sha256 = HTTP_DEPENDENCY_VERSIONS["guava_android"]["sha"],
urls = [
"{0}/com/google/guava/guava/{1}-android/guava-{1}-android.jar".format(
url_base,
HTTP_DEPENDENCY_VERSIONS["guava_android"]["version"],
)
for url_base in DAGGER_REPOSITORIES + MAVEN_REPOSITORIES
],
)
11 changes: 2 additions & 9 deletions app/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ order to build with Bazel.
- All binding adapters must be written in Java.
"""

load("@dagger//:workspace_defs.bzl", "dagger_rules")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")
load("@tools_android//tools/crashlytics:defs.bzl", "crashlytics_android_library")
load("@tools_android//tools/googleservices:defs.bzl", "google_services_xml")
Expand Down Expand Up @@ -627,7 +626,6 @@ kt_android_library(
srcs = LISTENERS,
custom_package = "org.oppia.android.app",
deps = [
":dagger",
"//domain/src/main/java/org/oppia/android/domain/audio:cellular_audio_dialog_controller",
"//model/src/main/proto:arguments_java_proto_lite",
"//model/src/main/proto:question_java_proto_lite",
Expand Down Expand Up @@ -672,7 +670,6 @@ kt_android_library(
srcs = ANNOTATIONS,
custom_package = "org.oppia.android.app",
deps = [
":dagger",
"//app/src/main/java/org/oppia/android/app/activity:activity_scope",
"//app/src/main/java/org/oppia/android/app/fragment:fragment_scope",
],
Expand All @@ -690,7 +687,6 @@ kt_android_library(
],
deps = [
":annotations",
":dagger",
":listeners",
":resources",
"//app/src/main/java/org/oppia/android/app/shim:intent_factory_shim",
Expand Down Expand Up @@ -734,7 +730,6 @@ android_library(
enable_data_binding = True,
manifest = "src/main/DatabindingAdaptersManifest.xml",
deps = [
":dagger",
":resources",
":view_models",
"//app/src/main/java/org/oppia/android/app/translation:app_language_activity_injector_provider",
Expand Down Expand Up @@ -771,11 +766,11 @@ kt_android_library(
visibility = ["//visibility:public"],
deps = [
":binding_adapters",
":dagger",
":databinding_resources",
":resources",
":view_models",
":views",
"//:dagger",
"//app/src/main/java/org/oppia/android/app/activity:activity_intent_factories_shim",
"//app/src/main/java/org/oppia/android/app/activity:injectable_auto_localized_app_compat_activity",
"//app/src/main/java/org/oppia/android/app/activity:injectable_system_localized_app_compat_activity",
Expand Down Expand Up @@ -851,9 +846,9 @@ kt_android_library(
# keep sorted
TEST_DEPS = [
":app",
":dagger",
":resources",
":test_deps",
"//:dagger",
"//app/src/main/java/org/oppia/android/app/application:application_component",
"//app/src/main/java/org/oppia/android/app/application:application_injector",
"//app/src/main/java/org/oppia/android/app/application:application_injector_provider",
Expand Down Expand Up @@ -1023,5 +1018,3 @@ android_library(
"//third_party:org_checkerframework_checker-qual",
],
)

dagger_rules()
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Constructs for setting up activity routing support in the Dagger graph.
"""

load("@dagger//:workspace_defs.bzl", "dagger_rules")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")

# TODO(#59): Define these exported files as separate libraries from top-level targets.
Expand All @@ -19,11 +18,9 @@ kt_android_library(
],
visibility = ["//:oppia_api_visibility"],
deps = [
":dagger",
"//:dagger",
"//model/src/main/proto:arguments_java_proto_lite",
"//third_party:androidx_appcompat_appcompat",
"//utility/src/main/java/org/oppia/android/util/logging:console_logger",
],
)

dagger_rules()
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Dagger graph.
Specific application implementations can be found in subpackages.
"""

load("@dagger//:workspace_defs.bzl", "dagger_rules")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")

kt_android_library(
Expand Down Expand Up @@ -82,7 +81,6 @@ kt_android_library(
"ApplicationStartupListenerModule.kt",
],
deps = [
":dagger",
"//app",
"//domain/src/main/java/org/oppia/android/domain/oppialogger:startup_listener",
],
Expand Down Expand Up @@ -134,5 +132,3 @@ android_library(
"//utility/src/main/java/org/oppia/android/util/parser/image:repository_glide_module",
],
)

dagger_rules()
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
This package contains the root application definitions for alpha builds of the app.
"""

load("@dagger//:workspace_defs.bzl", "dagger_rules")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")

kt_android_library(
Expand All @@ -14,7 +13,7 @@ kt_android_library(
visibility = ["//:oppia_binary_visibility"],
deps = [
":alpha_build_flavor_module",
":dagger",
"//:dagger",
"//app",
"//app/src/main/java/org/oppia/android/app/application:abstract_application",
"//app/src/main/java/org/oppia/android/app/application:application_component",
Expand All @@ -36,9 +35,7 @@ kt_android_library(
"//app/src/test/java/org/oppia/android/app/application/alpha:__pkg__",
],
deps = [
":dagger",
"//:dagger",
"//model/src/main/proto:version_java_proto_lite",
],
)

dagger_rules()
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ This package contains the root application definitions for a Kenya user study sp
of the app.
"""

load("@dagger//:workspace_defs.bzl", "dagger_rules")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")

kt_android_library(
Expand All @@ -14,7 +13,7 @@ kt_android_library(
],
visibility = ["//:oppia_binary_visibility"],
deps = [
":dagger",
"//:dagger",
"//app",
"//app/src/main/java/org/oppia/android/app/application:abstract_application",
"//app/src/main/java/org/oppia/android/app/application:application_component",
Expand All @@ -26,5 +25,3 @@ kt_android_library(
"//utility/src/main/java/org/oppia/android/util/networking:prod_module",
],
)

dagger_rules()
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
This package contains the root application definitions for beta builds of the app.
"""

load("@dagger//:workspace_defs.bzl", "dagger_rules")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")

kt_android_library(
Expand All @@ -17,7 +16,7 @@ kt_android_library(
"//app/src/test/java/org/oppia/android/app/application/beta:__pkg__",
],
deps = [
":dagger",
"//:dagger",
"//app",
"//app/src/main/java/org/oppia/android/app/application:abstract_application",
"//app/src/main/java/org/oppia/android/app/application:application_component",
Expand All @@ -28,5 +27,3 @@ kt_android_library(
"//utility/src/main/java/org/oppia/android/util/networking:prod_module",
],
)

dagger_rules()
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ there are specially defined top-level build flavors which will select their corr
application configuration.
"""

load("@dagger//:workspace_defs.bzl", "dagger_rules")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")

kt_android_library(
Expand All @@ -21,7 +20,7 @@ kt_android_library(
"//app/src/test/java/org/oppia/android/app/application/dev:__pkg__",
],
deps = [
":dagger",
"//:dagger",
"//app",
"//app/src/main/java/org/oppia/android/app/application:abstract_application",
"//app/src/main/java/org/oppia/android/app/application:application_component",
Expand All @@ -32,5 +31,3 @@ kt_android_library(
"//utility/src/main/java/org/oppia/android/util/networking:debug_module",
],
)

dagger_rules()
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
This package contains the root application definitions for general availability builds of the app.
"""

load("@dagger//:workspace_defs.bzl", "dagger_rules")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")

kt_android_library(
Expand All @@ -17,7 +16,7 @@ kt_android_library(
"//app/src/test/java/org/oppia/android/app/application/ga:__pkg__",
],
deps = [
":dagger",
"//:dagger",
"//app",
"//app/src/main/java/org/oppia/android/app/application:abstract_application",
"//app/src/main/java/org/oppia/android/app/application:application_component",
Expand All @@ -28,5 +27,3 @@ kt_android_library(
"//utility/src/main/java/org/oppia/android/util/networking:prod_module",
],
)

dagger_rules()
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ This package contains testing utilities that may be needed to set up the root ap
testing environments.
"""

load("@dagger//:workspace_defs.bzl", "dagger_rules")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")

kt_android_library(
Expand All @@ -14,9 +13,7 @@ kt_android_library(
],
visibility = ["//:oppia_testing_visibility"],
deps = [
":dagger",
"//:dagger",
"//model/src/main/proto:version_java_proto_lite",
],
)

dagger_rules()
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Test-only utilities corresponding to app notices.
"""

load("@dagger//:workspace_defs.bzl", "dagger_rules")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")

kt_android_library(
Expand Down Expand Up @@ -69,5 +68,3 @@ kt_android_library(
"//app/src/main/java/org/oppia/android/app/testing/activity:test_activity",
],
)

dagger_rules()
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
Test-only utilities corresponding to BottomSheetOptionsMenu.
"""

load("@dagger//:workspace_defs.bzl", "dagger_rules")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")

kt_android_library(
Expand All @@ -17,5 +16,3 @@ kt_android_library(
"//app/src/main/java/org/oppia/android/app/testing/activity:test_activity",
],
)

dagger_rules()
5 changes: 0 additions & 5 deletions app/src/main/java/org/oppia/android/app/shim/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ Temporary shims for providing indirection in the Bazel build graph to unblock mo
parts of the app layer.
"""

load("@dagger//:workspace_defs.bzl", "dagger_rules")
load("@io_bazel_rules_kotlin//kotlin:kotlin.bzl", "kt_android_library")

IMPL_FILES = [
Expand Down Expand Up @@ -59,7 +58,6 @@ kt_android_library(
name = "impl",
srcs = UPDATED_IMPL_FILES,
deps = [
":dagger",
":intent_factory_shim",
":view_binding_shim",
"//app:databinding_resources",
Expand All @@ -76,11 +74,8 @@ kt_android_library(
],
visibility = ["//:oppia_prod_module_visibility"],
deps = [
":dagger",
":impl",
":intent_factory_shim",
":view_binding_shim",
],
)

dagger_rules()
Loading

0 comments on commit 6b724ac

Please sign in to comment.