Databinding: Cannot enable strict deps when layout XML references classes from a direct dependency.
Description of the problem / feature request:
When databinding is enabled, consider
<?xml version="1.0" encoding="utf-8"?>
<layout>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
here the class androidx.constraintlayout.widget.ConstraintLayout comes from a direct dependency on current module ie. from @maven//:com_google_android_material_material.
Even though it is a direct dependency, strict deps check complains that it is a transitive dependency and fails the error
external/remotejdk11_macos/bin/java -XX:+UseParallelOldGC -XX:-CompactStrings '--patch-module=java.compiler=external/remote_java_tools_darwin/java_tools/java_compiler.jar' '--patch-module=jdk.compiler=external/remote_java_tools_darwin/java_tools/jdk_compiler.jar' '--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED' '--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED' '--add-opens=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED' '--add-opens=java.base/java.nio=ALL-UNNAMED' '--add-opens=java.base/java.lang=ALL-UNNAMED' -jar external/remote_java_tools_darwin/java_tools/JavaBuilder_deploy.jar @bazel-out/darwin-fastbuild/bin/app/libapp.jar-0.params @bazel-out/darwin-fastbuild/bin/app/libapp.jar-1.params)
Execution platform: @local_config_platform//:host
bazel-out/darwin-fastbuild/bin/app/_javac/app/libapp_sources/com/example/databindingstrictdeps/databinding/ActivityMainBindingImpl.java:20: error: [strict] Using type androidx.constraintlayout.widget.ConstraintLayout from an indirect dependency (TOOL_INFO: "bazel-out/android-armeabi-v7a-fastbuild/bin/external/maven/_aar/androidx_constraintlayout_constraintlayout/classes_and_libs_merged.jar").
private final androidx.constraintlayout.widget.ConstraintLayout mboundView0;
^
Target //app:app failed to build
Feature requests: what underlying problem are you trying to solve with this feature?
build --strict_java_deps=off
fixes the issue but would like to enable strict deps.
Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
- Unzip and run
bazelisk build //app
Observe build failed.
What operating system are you running Bazel on?
MacOs Catalina 10.15.7
What's the output of bazel info release?
release 4.1.0
If bazel info release returns "development version" or "(@non-git)", tell us how you built Bazel.
NIL
What's the output of git remote get-url origin ; git rev-parse master ; git rev-parse HEAD ?
NIL
Have you found anything relevant by searching the web?
I suspect this function is the cause: https://github.com/bazelbuild/bazel/blob/13b737acf6ae76539adb76e43a6fddf6d0684691/src/main/java/com/google/devtools/build/lib/rules/android/AndroidCommon.java#L868
I think JavaCommon created there does not handle deps correctly considering this function is only used for Databinding it does not affect Bazel's other Java functionality.
Related bazelbuild/bazel#2694