--strict_java_deps=off doesnot work

33 views
Skip to first unread message

Krish Narukulla

unread,
May 7, 2021, 2:26:49 AMMay 7
to bazel-discuss
I am trying to build target without specifying direct dependencies in BUILD file.

bazel build --strict_java_deps=off <target>

Documentation:

This option controls whether javac checks for missing direct dependencies. Java targets must explicitly declare all directly used targets as dependencies. This flag instructs javac to determine the jars actually used for type checking each java file, and warn/error if they are not the output of a direct dependency of the current target.

  • off means checking is disabled.
  • warn means javac will generate standard java warnings of type [strict] for each missing direct dependency.
  • default, strict and error all mean javac will generate errors instead of warnings, causing the current target to fail to build if any missing direct dependencies are found. This is also the default behavior when the flag is unspecified.


Lars Clausen

unread,
May 7, 2021, 4:19:41 AMMay 7
to Krish Narukulla, bazel-discuss
What are your reasons for trying to do this? And what problem are you encountering that makes you post here?

I would recommend against depending on indirect dependencies (pun intended). If you get your dependencies transitively, you might suddenly get broken due to a change in one of your dependencies. Also, it makes it harder for Bazel to reason about your build, and thus can cause worse performance. If it's just that you don't want to do the work to keep your dependency list up to date, you may want to look at Gazelle (https://github.com/bazelbuild/bazel-gazelle).

-Lars
 


--
You received this message because you are subscribed to the Google Groups "bazel-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bazel-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bazel-discuss/c8a488c0-f3fa-43f2-8c77-d2a7337389den%40googlegroups.com.

Krish Narukulla

unread,
May 7, 2021, 1:27:43 PMMay 7
to Lars Clausen, bazel-discuss
We are trying to migrate pantsbuild to bazel so encountered build issues. pantsbuild does not require to specify all "direct dependencies".

Thanks

Alex Humesky

unread,
May 11, 2021, 8:08:52 PMMay 11
to Krish Narukulla, Lars Clausen, bazel-discuss
This seems to be working fine for me. What errors are you encountering? Do you have a minimal reproduction of the problem?

$ cat BUILD
java_library(
  name = "A",
  srcs = ["A.java"],
  deps = [":B"],
)

java_library(
  name = "B",
  srcs = ["B.java"],
  deps = [":C"],
)

java_library(
  name = "C",
  srcs = ["C.java"],
)

$ cat A.java
package foo;

public class A {
  B b;
  C c;
}

$ cat B.java
package foo;

public class B {
  C c;
}

$ cat C.java
package foo;

public class C {
}

$ bazel build A
INFO: Build option --experimental_strict_java_deps has changed, discarding analysis cache.
INFO: Analyzed target //:A (0 packages loaded, 445 targets configured).
INFO: Found 1 target...
ERROR: /home/ahumesky/bazel-workspaces/java-strict-deps/BUILD:1:13: Building libA.jar (1 source file) failed: (Exit 1): java failed: error executing command external/remotejdk11_linux/bin/java -XX:+UseParallelOldGC -XX:-CompactStrings '--patch-module=java.compiler=external/remote_java_tools_linux/java_tools/java_compiler.jar' ... (remaining 15 argument(s) skipped)
A.java:5: error: [strict] Using type foo.C from an indirect dependency (TOOL_INFO: "//:C"). See command below **
  C c;
  ^
 ** Please add the following dependencies:
  //:C to //:A
 ** You can use the following buildozer command:
buildozer 'add deps //:C' //:A

Target //:A failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.488s, Critical Path: 0.16s
INFO: 4 processes: 2 internal, 2 worker.
FAILED: Build did NOT complete successfully

$ bazel build A --strict_java_deps=off
INFO: Build option --experimental_strict_java_deps has changed, discarding analysis cache.
INFO: Analyzed target //:A (0 packages loaded, 445 targets configured).
INFO: Found 1 target...
Target //:A up-to-date:
  bazel-bin/libA.jar
INFO: Elapsed time: 0.432s, Critical Path: 0.15s
INFO: 4 processes: 1 internal, 3 worker.
INFO: Build completed successfully, 4 total actions


Reply all
Reply to author
Forward
0 new messages