maven-artifacts.md

September 19, 2024 ยท View on GitHub

Using GraalVM artifacts from Maven

Several important GraalVM artifacts are distributed via Maven, including the GraalVM SDK, Truffle API, and others.

These rules have some macros which make use of this libraries a bit easier, particularly via rules_jvm_external.

Installing a Maven artifact

From a WORKSPACE.bazel:

# ... setup code for `rules_jvm_external` ...
# ... setup code for `rules_graalvm` ...

load("@rules_graalvm//graalvm/artifacts:maven.bzl", "graalvm")
load("@rules_jvm_external//:defs.bzl", "maven_install")
load("@rules_jvm_external//:specs.bzl", "maven")
maven_install(
    artifacts = [
        graalvm.artifact(
            maven,
            artifact = graalvm.catalog.SDK,
            version = "23.0.1",
        ),
    ],
)

What this does: The graalvm.artifact call will add the graalvm.catalog.SDK artifact via the maven struct provided by rules_jvm_external.

This is equivalent to the normal arguments expected by maven_install:

maven_install(
    artifacts = [
        "org.graalvm.sdk:graal-sdk:23.0.1",
    ],
)

Using a Maven artifact

In addition to the macro made available for use in the WORKSPACE file, there is also a macro which makes it easy to use these Maven artifacts in your java_library(deps = *):

load("@rules_graalvm//graalvm/artifacts:maven.bzl", graalvm = "alias")

java_library(
    name = "java",
    srcs = ["Main.java"],
    deps = [
        graalvm.artifact(graalvm.catalog.SDK),

        # other equivalent forms of this same dependency:
        #
        # graalvm.alias("org.graalvm.sdk", "graal-sdk"),
        # "@maven//:org_graalvm_sdk_graal_sdk",
    ],
)

Available Maven dependencies

ArtifactCatalog symbolMaven coordinateNotes
GraalVM SDKcatalog.SDKorg.graalvm.sdk:graal-sdkMain GraalVM SDK package
Truffle APIcatalog.TRUFFLEorg.graalvm.truffle:truffle-apiAPI package for Truffle language implementors
Truffle NFIcatalog.TRUFFLE.NFIorg.graalvm.truffle:truffle-nfiNative Function Interface package or Truffle