GraalVM Native Build Tools

repository·master·Indexed 19 days ago

https://github.com/graalvm/native-build-tools

Plugins for Maven and Gradle that facilitate the creation of GraalVM Native Images within standard build lifecycles. It provides the native-gradle-plugin (ID: org.graalvm.buildtools.native) and native-maven-plugin to integrate native image compilation, JUnit Platform native testing, resource configuration, and tracing-agent metadata collection into the build process.

Tokens
41.5K
Snippets
77
Records
219
Agent score
66%

What's inside native-build-tools

  1. Overview of Native Build Tools components

    master

    Native Build Tools is a composite Gradle workspace that provides plugins and shared libraries for GraalVM Native Image integration. The repository is organized into several key functional areas:

    • Gradle product plugin (native-gradle-plugin/): Provides the Gradle plugin API, DSL, tasks, and command-line providers.
    • Maven product plugin (native-maven-plugin/): Provides Maven mojos, plugin descriptor generation, and configuration objects.
    • Shared libraries (common/utils/, common/graalvm-reachability-metadata/, common/junit-platform-native/): Contains build-tool-neutral utilities for Native Image, metadata lookup, resource analysis, and JUnit native runtime support.
    • Verification artifacts (samples/, test-support/, reproducers/): Includes realistic projects and reusable test artifacts to verify plugin behavior.
    • Build infrastructure (build-logic/, gradle/, config/): Manages repository conventions, publication, and validation.
    • CI workflows (.github/workflows/): Handles pull request gates, documentation deployment, and snapshot deployment.
  2. Overview of native-maven-plugin functional areas

    master

    The native-maven-plugin (packaged as maven-plugin) translates Maven project state, XML configuration, system properties, dependency scopes, and lifecycle phases into Native Build Tools behavior.

    Key functional areas include:

    • Goal Surface: Maven goals, lifecycle bindings, support goals, and profile usage.
    • Native Image Builds: Build behavior, main-class discovery, skipping, classpath scopes, SBOM, and argument files.
    • Configuration Model: Native Image options, command-line properties, parent POM merging, toolchain lookup, and override precedence.
    • Native Tests: Native test classpath, discovery, launcher selection, and execution.
    • Tracing Agent: Enablement, modes, output, and metadata merge/copy behavior.
    • Resources and Metadata: Resource configuration, reachability metadata, missing-metadata reports, schema validation, and entry points.
  3. Use the GraalVM Native Build Tools Gradle plugin

    master

    The native-gradle-plugin module provides the Gradle plugin identified by the ID org.graalvm.buildtools.native. This plugin enables Native Image workflows within Gradle projects by providing the graalvmNative DSL, specialized tasks, and integration with GraalVM's native image capabilities.

    To use the plugin, apply it to your Gradle project and configure your native image settings using the graalvmNative extension.

    plugins {
        id 'org.graalvm.buildtools.native'
    }
  4. Reference the Native Build Tools specification structure

    master

    The specification is organized into several key areas to help developers find the correct technical details:

    • grund.md: The fundamental reason for the project's existence.
    • goals.md & non-goals.md: Defines what the project aims to achieve and what is explicitly out of scope.
    • requirements.md: Cross-cutting compatibility and support constraints.
    • architecture/: Contains the repository component map, dependency directions, and implementation structure.
    • functional/: Contains the functional specifications for observable behaviors like native image builds, testing, and resource management.
    • decisions/: Records architectural decisions and tradeoffs.
    • glossary.md: Domain terms used throughout the specifications.
  5. Identify the responsibilities of common modules

    master

    The common directory is organized into specific modules based on their functional domain:

    • common/utils: Manages shared agent configuration models, resource configuration models, classpath and JAR analysis, Native Image command-line utilities, schema validation helpers, JUnit dependency helpers, and shared constants.
    • common/graalvm-reachability-metadata: Handles metadata repository access, artifact and module indexes, directory configuration, query objects, version selection, and support for missing metadata commands.
    • common/junit-platform-native: Provides JUnit Platform support required inside native test images, including native-image feature registration, test class registration, launcher behavior, and JUnit configuration providers.
  6. Use JUnit Platform support for GraalVM Native Image

    master

    This feature enables JUnit Platform testing support for GraalVM Native Image. It allows you to run JUnit tests within a native image.

    To use it, the artifact produced by this project must be included on your classpath. You can do this via build tool plugins or manual configuration.

    There are two modes of operation:

    1. Out of the box: For tests that do not use reflection internally.
    2. With the agent run: For tests that use internal reflection. This requires running the native-image-agent to generate necessary configuration.
    # Manual configuration if build tool support is missing:
    native-image \
        ... \
        --no-fallback \
        --features=org.graalvm.junit.platform.JUnitPlatformFeature \
        org.graalvm.junit.platform.NativeImageJUnitLauncher
  7. Compare Gradle and Maven Native Build Tools workflows

    master

    Native Build Tools provides parity between Gradle and Maven for GraalVM Native Image workflows. While the underlying build models differ, both plugins are designed to answer the same practical questions: building, running, testing, and managing metadata.

    Use the following mapping to find the relevant documentation for your specific build tool:

    User goalGradle adaptationMaven adaptation
    Build the main application imagenative-image-tasksgoal-surface, native-image-builds
    Run the application imagenative-image-tasksnative-image-builds
    Build and run tests as a native imagenative-testsnative-tests
    Generate resource configurationresources-and-metadataresources-and-metadata
    Use reachability metadataresources-and-metadataresources-and-metadata
    Inspect missing metadataresources-and-metadataresources-and-metadata
    Collect agent outputtracing-agenttracing-agent
  8. Understand the Functional Specification of Native Build Tools

    master

    The functional specifications define the observable behavior of Native Build Tools. This includes the expected behavior of commands, outputs, workflows, configuration contracts, generated artifacts, and verification expectations. While architecture specs explain implementation details, functional specs define what the tools must do for the user.

    Key areas covered by functional contracts include:

    • Cross-plugin parity: Ensuring consistent behavior between Gradle and Maven plugins.
    • Native Image builds: How native images are built from project state.
    • Native testing: Compiling and executing JUnit tests as native images.
    • Resources and Metadata: Handling resource configuration, reachability metadata, and schema validation.
    • Tracing Agent: Attaching the Native Image tracing agent and processing its output.
    • Option Precedence: How command-line arguments interact with durable configuration.
    • Build Infrastructure: Behavior regarding documentation, releases, and generated artifacts.
  9. Use the Native Image Gradle Plugin for GraalVM

    master

    The Native Image Gradle Plugin is a Gradle plugin designed to facilitate the building of GraalVM Native Images. It integrates GraalVM Native Image capabilities directly into the Gradle build lifecycle.

    For detailed end-user documentation, configuration options, and usage guides, refer to the official documentation site: https://graalvm.github.io/native-build-tools/

  10. Use the Native Image Maven Plugin for GraalVM

    master

    The native-maven-plugin is a Maven plugin designed to facilitate the building of GraalVM Native Images. It integrates the Native Image build process directly into the Maven lifecycle.

    For detailed end-user documentation, including configuration options and usage guides, refer to the official GraalVM Native Build Tools documentation site: https://graalvm.github.io/native-build-tools/.

  11. Why use Native Build Tools for GraalVM Native Image

    master

    Native Build Tools provides Gradle and Maven plugins that automate the complex requirements of building GraalVM Native Image applications. It integrates the following specialized workflows directly into your existing build tool:

    • Dependency Management: Automatically passes necessary dependencies to the native-image tool at build time.
    • Native Testing: Orchestrates a workflow that builds an executable binary and then executes it to run tests.
    • Agent Integration: Handles the extra steps required for the native-image agent to process metadata.
    • Reachability Metadata: Automates lookups for reachability metadata from the GraalVM Reachability Metadata Repository.