Skip to content

Introduction

This plugin enables developing Java code that makes use of native libraries using the new Foreign Function & Memory API.

  • FFM API can be considered as a more modern and secure alternative to JNI for native access in Java.
  • The FFM-related Jextract tool reads C header files and generates Java bindings for statically typed native access. These are Java classes to be used in a Java project.
  • This Gradle plugin runs Jextract on your header files and makes the generated bindings available for your source code.

This plugin was created to get rid of a local Jextract installation requirement and to retain the “Clone&Build” Gradle experience. All you need is at least JVM 17 and your project should use at least Gradle v8.8.

  • Downloads Jextract for the current build platform and architecture, no additional installation steps are needed.
  • Preset conventions for Jextract versions 19 up to 25.
  • Download locations can be customized for more restrictive environments.
  • Alternately, use a local installation of Jextract.

All features are configurable via script DSL extension. So importing and configuring tasks directly is not necessary.

  • Configure as many libs as needed.
  • Customize the output path for each lib
  • Add the generated code to any Java source sets.
  • Filter which symbols in your lib should be included, via DSL or arg file.
  • Dump all includes into an arg file for further usage and filtering.

The plugin is committed to follow Gradle’s best practices.