Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
324 views
in Technique[技术] by (71.8m points)

Suppress java path warnings while -Werror using bazel version 4.0.0

Problem

I have a package with a java_library configured with javaopts = ["-Werror"]. Building was successful with 3.6.0. After upgrading to 4.0.0 I get

warning: [path] bad path element "some/path/some.jar" : no such file or directory

More inspection revealed that these jars are declared in the META-INF/MANIFEST.MF Class-Path in some of our dependencies that are being fetched through maven_install. And, obviously, they are not found in the referred to directory in the warning message. I tried adding "-Xlint:-path" to javacopts in our BUILD file, but warnings still exist.

Worth mentioning that removing the -Werror does not fail the build (although the warnings of course still exist).

To Reproduce

To reproduce on a simpler project, I replicated the case with the example repo from the java tutorial on bazel docs.

  1. git clone https://github.com/bazelbuild/examples

  2. Then applying this git patch

diff --git a/java-maven/BUILD b/java-maven/BUILD                                                                                                                            
index 60cdd7b..370b6f4 100644                                                                                                                                                
--- a/java-maven/BUILD                                                                                                                                                      
+++ b/java-maven/BUILD                                                                                                                                                      
@@ -5,7 +5,8 @@ package(default_visibility = ["//visibility:public"])                                                                                                        
 java_library(                                                                                                                                                              
     name = "java-maven-lib",                                                                                                                                                
     srcs = glob(["src/main/java/com/example/myproject/*.java"]),                                                                                                            
-    deps = ["@maven//:com_google_guava_guava"],                                                                                                                            
+    deps = ["@maven//:com_google_guava_guava", "@maven//:org_apache_beam_beam_model_job_management"],                                                                      
+   javacopts = ["-Werror", "-Xlint:-path"]                                                                                                                                  
 )                                                                                                                                                                          
                                                                                                                                                                             
 java_binary(                                                                                                                                                                
diff --git a/java-maven/WORKSPACE b/java-maven/WORKSPACE                                                                                                                    
index 1cbdf12..aa0df88 100644                                                                                                                                                
--- a/java-maven/WORKSPACE                                                                                                                                                  
+++ b/java-maven/WORKSPACE                                                                                                                                                  
@@ -17,6 +17,7 @@ maven_install(                                                                                                                                            
     artifacts = [                                                                                                                                                          
         "junit:junit:4.12",                                                                                                                                                
         "com.google.guava:guava:28.0-jre",                                                                                                                                  
+        "org.apache.beam:beam-model-job-management:2.19.0",                                                                                                                
     ],                                                                                                                                                                      
     fetch_sources = True,                                                                                                                                                  
     repositories = [
  1. bazel build //...

I also tried bazel build --javacopt="-Werror -Xlint:-path" //..., but also no luck

Can anyone advise what am I doing wrong and how to achieve suppressing this specific warning (path warnings) while still having -Werror?

question from:https://stackoverflow.com/questions/66051294/suppress-java-path-warnings-while-werror-using-bazel-version-4-0-0

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Digging deeper into Bazel codebase, I found the undocumented (to extent of my knowledge) flag Xerror: (vs Xerror), which takes a list of warnings to fail the build for. In my case I could do Xerror:-path instead the standard Xerror and Xlint:-path.

I found this bug report later, and also commented there.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...