尝试使用通过build_file
属性在外部软件包工作区中定义的依赖项的,通过http_archive
导入的外部软件包中的workspace_file
中的目标失败。我在Debian测试中使用的是Bazel 0.27.0。
文档仅讨论引用提供的build_file
中的目标,但是我找不到任何信息可以引用提供的workspace_file
中提供的build_file
中定义的依赖项。
通常的@stringtemplate3//jar
语法会失败,但是我不知道如何包含对导入存档的引用,根据手册,引用必须以@antlr3_runtimes
开头。
项目布局如下:
├── antlr.BUILD
├── antlr.WORKSPACE
├── BUILD
├── external_dependency
│ └── src
│ └── main
│ └── java
│ └── bazel
│ ├── BUILD
│ └── Hello.java
├── LICENSE
└── WORKSPACE
WORKSPACE
定义如下:
workspace(name="bazel")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
name = "antlr3_runtimes",
sha256 = "d4f7d3c38c5523f8009ff37528e5797c81adb454be6acc9af507cfcb41f2016f",
strip_prefix = "antlr3-master",
urls = ["https://github.com/ibre5041/antlr3/archive/master.tar.gz"],
build_file = "@//:antlr.BUILD",
workspace_file = "@//:antlr.WORKSPACE",
)
似乎对提供的workspace_file
都没有进行分析。尝试解析自定义构建文件中的依赖关系时,该构建已经失败。
可以在此处找到一个复制子:https://github.com/marcohu/bazel
bazel build //...
显示以下错误消息:
ERROR: /home/user/.cache/bazel/_bazel_user/64492308e78c9898c41f12c18dd29b63/external/antlr3_runtimes/BUILD.bazel:43:1: no such package '@stringtemplate3//jar': The repository '@stringtemplate3' could not be resolved and referenced by '@antlr3_runtimes//:antlr3_tool'
ERROR: Analysis of target '//external_dependency/src/main/java/bazel:hello' failed; build aborted: no such package '@stringtemplate3//jar': The repository '@stringtemplate3' could not be resolved
我在Bazel问题跟踪器中报告了此问题,但被拒绝并提示在此处发布。
此用例是否不可能?还是我语法错误?
答案 0 :(得分:0)
至少到目前为止(我想此声明在将来的版本中可能会更改),bazel不直接支持可传递的外部依赖关系。即使您遇到这种情况,WORKSPACE
文件仍会被读入,并且如果它包含完全损坏的语法,它仍然会失败,但是不会“作用于”文件,您可以(当前)例如从不存在的文件中进行加载标签或调用未定义的函数,对于嵌套WORKSPACE
仍然不明智。
您基本上有两个选择:
在“父” /顶部http_archive
中重复嵌套的依赖项(WORKSPACE
规则)。
您可以定义一个函数,并使用相应的存储库规则加载并在“父” /顶部WORKSPACE
中调用。
答案 1 :(得分:0)
Bazel实际上确实支持对jvm依赖项的传递式获取。 https://github.com/bazelbuild/rules_jvm_external
WORKSPACE
$links = file('filepath.txt');
foreach($links as $link){
// connect and login to FTP server
$ftp_server = "myftpserver";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, $ftp_user_name, $ftp_user_pass);
$old_file = $link;
$new_file = str_replace("badword", "goodword",$old_file);
// try to rename $old_file to $new_file
if (ftp_rename($ftp_conn, $old_file, $new_file))
{
echo "Renamed $old_file to $new_file";
echo '<hr>';
}
else
{
echo "Problem renaming $old_file to $new_file";
}
// close connection
ftp_close($ftp_conn);
}
已构建
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
rules_jvm_external_tag = "2.0.1"
rules_jvm_external_sha = "55e8d3951647ae3dffde22b4f7f8dee11b3f70f3f89424713debd7076197eaca"
http_archive(
name = "rules_jvm_external",
sha256 = rules_jvm_external_sha,
strip_prefix = "rules_jvm_external-%s" % rules_jvm_external_tag,
url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % rules_jvm_external_tag,
)
load("@rules_jvm_external//:defs.bzl", "maven_install")
maven_install(
name = "maven",
artifacts = [
"io.grpc:grpc-netty-shaded:1.22.1",
"io.grpc:grpc-api:1.22.1",
"io.grpc:grpc-testing:1.22.1",
"io.grpc:grpc-core:1.22.1",
"junit:junit:4.12",
],
repositories = [
"https://jcenter.bintray.com/",
"https://repo1.maven.org/maven2",
],
)