The Maven build automatically compiles the native Rust library before running tests. No manual steps are required.
- Maven triggers cargo: During the
generate-resourcesphase, Maven runscargo build --release --libinnative/matchy/ - Tests use the built library: The surefire plugin is configured with
-Djna.library.pathpointing tonative/matchy/target/release - Incremental builds: Cargo's incremental compilation means subsequent builds complete in ~0.1s when nothing has changed
# Full build and test (builds Rust library automatically)
mvn clean test
# Just compile Java code (also builds Rust library)
mvn compile
# Package (includes building native library)
mvn package- Java 11+: For compiling and running the Java code
- Maven: For building the project
- Rust/Cargo: For compiling the native library (installed automatically via rustup or your package manager)
The pom.xml includes:
-
Properties defining the native library paths:
<native.matchy.dir>${project.basedir}/../native/matchy</native.matchy.dir> <native.target.dir>${native.matchy.dir}/target/release</native.target.dir>
-
exec-maven-plugin to build the Rust library:
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <execution> <phase>generate-resources</phase> <goals><goal>exec</goal></goals> <configuration> <executable>cargo</executable> <arguments> <argument>build</argument> <argument>--release</argument> <argument>--lib</argument> </arguments> </configuration> </execution> </plugin>
-
Surefire plugin configured to find the native library:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <argLine>-Djna.library.path=${native.target.dir}</argLine> </configuration> </plugin>
The GitHub Actions workflows have been simplified to just run mvn test - the native library build is handled automatically by Maven.
For cross-platform releases:
- Build on each target platform (Linux x64, Linux ARM64, macOS, Windows)
- Maven will automatically build the appropriate native library for each platform
- Collect the built libraries from
native/matchy/target/release/ - Bundle them into the final JAR with platform-specific paths