Java Project Guardrails
Enforce Java-specific project standards including build tool wrappers, Java version requirements, Maven/Gradle version minimums, and test scope.
java to your lunar-config.yml:uses: github://earthly/lunar-lib/policies/java@v1.0.0
Included Guardrails
This policy includes 5 guardrails that enforce standards for your devex build and ci.
build-tool-wrapper-exists
Ensures a build tool wrapper exists (mvnw for Maven projects, gradlew for Gradle projects). Wrappers ensure reproducible builds without requiring a pre-installed build tool.
min-java-version
Ensures the Java version configured in the build file meets the minimum requirement. Checks pom.xml or build.gradle for the target Java version.
min-maven-version
Ensures the Maven version used in CI/CD commands meets the minimum requirement. Helps maintain build tool security and compatibility.
min-gradle-version
Ensures the Gradle version used in CI/CD commands meets the minimum requirement. Helps maintain build tool security and compatibility.
tests-all-modules
Ensures tests run across all modules rather than a subset. Prevents accidentally skipping tests in multi-module projects.
How Guardrails Fit into Lunar
Lunar guardrails define your engineering standards as code. They evaluate data collected by integrations and produce pass/fail checks with actionable feedback.
Policies support gradual enforcement—from silent scoring to blocking PRs or deployments—letting you roll out standards at your own pace without disrupting existing workflows.
Learn How Lunar Works →Required Integrations
This policy evaluates data gathered by one or more of the following integration(s).
Make sure to enable them in your lunar-config.yml.
Configuration
Configure this policy in your lunar-config.yml.
Inputs
| Input | Required | Default | Description |
|---|---|---|---|
min_java_version
|
Optional |
17
|
Minimum required Java version (e.g., "17", "21") |
min_maven_version
|
Optional |
3.9.0
|
Minimum required Maven version (e.g., "3.9.0") |
min_gradle_version
|
Optional |
8.0.0
|
Minimum required Gradle version (e.g., "8.0.0") |
Documentation
View on GitHubJava Project Guardrails
Enforce Java-specific project standards including build tool wrappers, Java version requirements, Maven/Gradle version minimums, and test scope.
Overview
This policy validates Java projects against best practices for build reproducibility and project structure. It ensures projects use build tool wrappers (mvnw/gradlew), target a minimum Java version, use recent build tool versions in CI, and run tests across all modules.
Policies
This plugin provides the following policies (use include to select a subset):
| Policy | Description | Failure Meaning |
|---|---|---|
build-tool-wrapper-exists |
Validates mvnw/gradlew exists | Missing build wrapper for reproducibility |
min-java-version |
Ensures minimum Java version in build config | Java target version too old |
min-maven-version |
Ensures minimum Maven version in CI/CD | CI Maven version too old |
min-gradle-version |
Ensures minimum Gradle version in CI/CD | CI Gradle version too old |
tests-all-modules |
Ensures tests run all modules | Tests may miss modules |
Required Data
This policy reads from the following Component JSON paths:
| Path | Type | Provided By |
|---|---|---|
.lang.java |
object | java collector |
.lang.java.version |
string | java collector |
.lang.java.build_systems |
array | java collector |
.lang.java.mvnw_exists |
boolean | java collector |
.lang.java.gradlew_exists |
boolean | java collector |
.lang.java.cicd.cmds |
array | java collector |
.lang.java.tests.scope |
string | java collector |
Installation
Add to your lunar-config.yml:
policies:
- uses: github://earthly/lunar-lib/policies/java@v1.0.0
on: [java]
enforcement: report-pr
with:
min_java_version: "17"
min_maven_version: "3.9.0"
min_gradle_version: "8.0.0"
Examples
Passing Example
{
"lang": {
"java": {
"version": "21",
"build_systems": ["maven"],
"mvnw_exists": true,
"cicd": {
"cmds": [{ "cmd": "mvn clean install", "version": "3.9.6", "tool": "maven" }]
},
"tests": { "scope": "all" }
}
}
}
Failing Example
{
"lang": {
"java": {
"version": "11",
"build_systems": ["maven"],
"mvnw_exists": false
}
}
}
Failure messages:
"Missing build tool wrapper(s): mvnw (Maven wrapper)""Java version 11 (major: 11) is below minimum 17"
Remediation
build-tool-wrapper-exists
- Maven: Run
mvn wrapper:wrapperto generate the Maven wrapper (mvnw) - Gradle: Run
gradle wrapperto generate the Gradle wrapper (gradlew)
min-java-version
- Maven: Update
<java.version>or<maven.compiler.source>in pom.xml - Gradle: Update
sourceCompatibilityin build.gradle
min-maven-version / min-gradle-version
- Update your CI/CD pipeline or build tool wrapper to use a newer version
tests-all-modules
- Remove
-pl/--projectsflags from Maven test commands - Remove
--testsfilters from Gradle test commands
Open Source
This policy is open source and available on GitHub. Contribute improvements, report issues, or fork it for your own use.
Common Use Cases
Explore how individual guardrails work with specific integrations.
Ready to Automate Your Standards?
See how Lunar can turn your engineering wiki, compliance docs, or postmortem action items into automated guardrails with our 100+ built-in guardrails.