使用bazel如何使用单独的jar文件创建tar文件

时间:2016-04-23 21:22:26

标签: java bazel

我想为java项目X创建一个tar文件,它依赖于库Y& Z的结构如

bin/runx (from src/main/scripts)
lib/x.jar (the compiled contents of src/main/java)
lib/y.jar (a maven_jar X depends on)
lib/z.jar (a maven_jar X depends on) 
conf/x (from src/main/resources/conf/x)

这是否受到任何内置的bazel规则的支持?这是我需要用skylark或bash写自己的东西吗?

2 个答案:

答案 0 :(得分:0)

我设法让它以一种非常可怕的方式运作。

https://github.com/yschimke/oksocial/blob/bazel/BUILD

我找不到一种很好的方法来扩展目标所需的jar文件。

load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")

pkg_tar(
    name = "bundle-libs",
    package_dir = "lib",
    files = [
      '//src/main/java/com/baulsupp/oksocial',
      '@com_squareup_okhttp3_okhttp//jar',
      '@com_squareup_okhttp3_logging_interceptor//jar',
      '@com_squareup_okio_okio//jar',
      '@com_fasterxml_jackson_core_jackson_databind//jar',
      '@com_fasterxml_jackson_dataformat_jackson_dataformat_yaml//jar',
      '@com_twitter_joauth//jar',
      '@com_google_oauth_client_google_oauth_client_jetty//jar',
      '@com_google_guava_guava//jar',
      '@org_mortbay_jetty_jetty//jar',
      '@com_github_mrmike_ok2curl//jar',
      '@commons_cli_commons_cli//jar',
      '@commons_lang_commons_lang//jar',
      '@commons_io_commons_io//jar',
      '@org_slf4j_slf4j_jcl//jar',
      '@io_airlift_airline//jar',
      '@javax_inject_javax_inject//jar',
    ],
    mode = "0644",
)

pkg_tar(
    name = "bundle-alpn",
    package_dir = "alpn",
    files = ["@alpn_boot//jar"],
    mode = "0644",
)

pkg_tar(
    name = "bundle-bin",
    package_dir = "bin",
    files = glob(["src/main/scripts/**"]),
    mode = "0755",
)

pkg_tar(
    name = "oksocial-bundle",
    extension = "tgz",
    deps = [
        ":bundle-bin",
        ":bundle-libs",
        ":bundle-alpn",
    ],
)

答案 1 :(得分:0)

pkg_tar应该支持,请参阅http://bazel.io/docs/be/pkg.html#pkg_tar