rules_kotlin icon indicating copy to clipboard operation
rules_kotlin copied to clipboard

`experimental_strict_kotlin_deps` logs `null` for the missing dep

Open zack-sampson opened this issue 2 years ago • 2 comments

When I use experimental_strict_kotlin_deps = "error" in my toolchain definition, it does appear to find strict dep violations, but it doesn't correctly log the name of the violating dep. This is with v1.5.0. Looks like this:

** Please add the following dependencies: null to //identities-api/src/main:main 
 ** You can use the following buildozer command: buildozer 'add deps null' //identities-api/src/main:main

zack-sampson avatar Mar 18 '22 21:03 zack-sampson

I bumped to latest release 1.6 and also seeing this.


 ** Please add the following dependencies: null to //src/main/java/com/looker/jsrunner:jsrunner 
 ** You can use the following buildozer command: buildozer 'add deps null' //src/main/java/com/looker/jsrunner:jsrunner

fzakaria avatar Aug 10 '22 15:08 fzakaria

v1.7.0-RC-2 also has the issue.

fzakaria avatar Aug 10 '22 16:08 fzakaria

If you're using rules_jvm_external you might be seeing issue https://github.com/bazelbuild/rules_jvm_external/issues/283.

rules_kotlin looks for the Target-Label attribute for these suggestions. rules_jvm_external has an implementation that adds these attributes, but that is disabled by default. For us the suggestions improve when running the build with --@rules_jvm_external//settings:stamp_manifest=true, but there are still some nulls.

Note that you might want to use rules_jvm_external 4.4.2 or higher which includes https://github.com/bazelbuild/rules_jvm_external/pull/738 that fixes the stamping non-determinism issue.

lukaciko avatar Oct 07 '22 12:10 lukaciko

I dug a bit into this in a project using Android + rules_kotlin + rules_jvm_external. There can be many reasons why a Target-Label is missing, including the one I wrote above above, aar_import not producing it in classes_and_libs_merged.jar, kt_jvm_import not producing it etc.

I'd say the first thing to improve in rules_kotlin is to only print the buildozer command when the target label can be resolved and to print the path of the Jar file otherwise, as is done in Bazel/Java strict deps warnings:

https://github.com/bazelbuild/bazel/blob/68b1c7e98e94667054a58765b4e52a191e15c52f/src/java_tools/buildjar/java/com/google/devtools/build/buildjar/javac/plugins/dependency/StrictJavaDepsPlugin.java#L304-L307

Unused dependencies has a similar issue, but filters out dependencies without a target label.

lukaciko avatar Oct 11 '22 15:10 lukaciko

Bumping to 4.4.2 and adding --jvm_external//settings:stamp_manifest still shows as null; thanks for the tips though.

fzakaria avatar Oct 12 '22 18:10 fzakaria

Thank you @lukaciko. That fixed it for me. Btw, in rules_jvm_external 4.5, manifest stamping is default behaviour, so with that version you don't need to pass the --jvm_external//settings:stamp_manifest flag explicitly.

erlendvollset avatar Nov 16 '22 13:11 erlendvollset