javabazeltink

Add google tink java lib in bazel


I'm working on a java project where bazel is being used. I'm looking to add tink java lib in bazel but looks like com_github_google_tink is not a valid package name.

java_library(
    name = "testlib",
    srcs = glob(["*.java"]),
    deps = [
        "@com_github_google_tink",
    ],
    visibility = ["//visibility:public"],
)```
I already referred this article https://developers.google.com/tink/install-tink but it only talks about adding java deps in maven. Can someone help ? 

Solution

  • Are you using rules_jvm_external to get the tink dependency?

    https://github.com/bazelbuild/rules_jvm_external

    If not, you might try adding this or similar to your WORKSPACE file:

    load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
    
    RULES_JVM_EXTERNAL_TAG = "4.2"
    RULES_JVM_EXTERNAL_SHA = "cd1a77b7b02e8e008439ca76fd34f5b07aecb8c752961f9640dea15e9e5ba1ca"
    
    http_archive(
        name = "rules_jvm_external",
        strip_prefix = "rules_jvm_external-%s" % RULES_JVM_EXTERNAL_TAG,
        sha256 = RULES_JVM_EXTERNAL_SHA,
        url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % RULES_JVM_EXTERNAL_TAG,
    )
    load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps")
    rules_jvm_external_deps()
    load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup")
    rules_jvm_external_setup()
    load("@rules_jvm_external//:defs.bzl", "maven_install")
    
    maven_install(
        artifacts = [
            "com.google.crypto.tink:tink:1.6.1",
        ],
        repositories = [
            "https://repo1.maven.org/maven2",
        ],
    )
    

    Then you can use the tink dependency from maven in your BUILD / BUILD.bazel file like this:

    java_library(
        name = "testlib",
        srcs = glob(["*.java"]),
        deps = [
            "@maven//:com_google_crypto_tink_tink",
        ],
        visibility = ["//visibility:public"],
    )