Bazel构建无法在Maven项目中进行 [英] Bazel build is not working on from Maven project
本文介绍了Bazel构建无法在Maven项目中进行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是Bazel的新手,正在学习其构建工作,目前我正在尝试通过Maven项目进行bazel构建,请告诉我如何使其工作,谢谢.
I'm new to Bazel and learning its build work, currently I am trying to do with bazel build from a Maven project, please advise me how to make it working, thanks.
这是我要定义的 WORKSPACE 文件:
maven_jar(
name = "junit",
artifact = "junit:junit:3.8.1",
)
maven_jar(
name = "log4j1",
artifact = "org.apache.logging.log4j:log4j-core:2.6.2",
)
maven_jar(
name = "log4j2",
artifact = "org.apache.logging.log4j:log4j-api:2.6.2",
)
.....
这是我要定义的 BUILD 文件:
package(default_visibility = ["//visibility:public"])
java_binary(
name = "everything",
srcs = glob(["src/main/java/**/*.java"]),
resources = glob(["src/main/resources/**"]),
main_class = "src/main/java/com/test/test/test/App",
deps = [
"@junit//jar",
"@log4j1//jar",
"@log4j2//jar",
"@jackson//jar",
"@jsonsimple//jar",
"@commonsdbutils//jar",
"@commons//jar",
"@guava//jar",
"@poi//jar"],
)
这是Bazel构建结果:
Here is I got Bazel build results:
mbp:bazel_test me$ bazel build //:everything
INFO: Analysed target //:everything (1 packages loaded).
INFO: Found 1 target...
ERROR: /Users/me/git/test/test/BUILD:4:1: Building everything-class.jar (104 source files) failed (Exit 1)
src/main/java/com/test/test/test/Testapp.java:13: error: cannot find symbol
import org.apache.poi.ss.usermodel.Cell;
^
symbol: class Cell
location: program package org.apache.poi.ss.usermodel
.....
Target //:everything failed to build
推荐答案
我在这里看到两个问题:
I see two problems here:
-
main_class
属性应使用点而不是斜杠:
- The
main_class
attribute should use dots instead of slashes:
java_binary(
name = "everything",
srcs = glob(["src/main/java/**/*.java"]),
main_class = "src.main.java.com.test.test.test.App",
...
- poi jar中没有
org.apache.poi.ss.usermodel.Cell
类. - There's no
org.apache.poi.ss.usermodel.Cell
class in the poi jar.
找到罐子的名称:
$ bazel query --output=build @poi//jar
...
java_import(
name = "jar",
visibility = ["//visibility:public"],
jars = ["@poi//jar:poi-ooxml-3.9.jar"],
srcjar = "@poi//jar:poi-ooxml-3.9-sources.jar",
)
包的位置是$(bazel info output_base)/external/poi
,现在(从上面的bazel query
输出中的srcs
属性中)我们知道该文件名为poi-ooxml-3.9.jar
:
The package's location is $(bazel info output_base)/external/poi
, and now we know (from the srcs
attribute in the bazel query
output above) that the file is called poi-ooxml-3.9.jar
:
$ unzip -l $(bazel info output_base)/external/poi/jar/poi-ooxml-3.9.jar | grep "org.apache.poi.ss.usermodel"
0 2012-11-26 17:14 org/apache/poi/ss/usermodel/
2970 2012-11-26 17:14 org/apache/poi/ss/usermodel/WorkbookFactory.class
这篇关于Bazel构建无法在Maven项目中进行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文