Tutorial: Java Spring Boot API
What This Tutorial Will Cover
Section titled “What This Tutorial Will Cover”When Java support lands, this tutorial will walk through:
- Creating a minimal Spring Boot REST API with
GET /healthandGET /greetendpoints - Writing JUnit 5 tests and configuring JaCoCo to produce an XML coverage report
- Running
nolapse init --repo . --lang javato create the baseline from the JaCoCo report - Simulating a coverage regression by removing a test method
- Running
nolapse run --repo . --lang javaand seeing it exit 1 - Adding a GitHub Actions workflow with Maven or Gradle that gates PRs on coverage
Expected Project Structure
Section titled “Expected Project Structure”hello-spring/├── src/│ ├── main/java/com/example/hello/│ │ ├── HelloController.java│ │ └── HelloApplication.java│ └── test/java/com/example/hello/│ └── HelloControllerTest.java├── pom.xml├── .audit/│ └── coverage/│ └── baseline.md└── nolapse.yamlExpected Commands (Once Available)
Section titled “Expected Commands (Once Available)”Build and test with Maven
Section titled “Build and test with Maven”mvn verifyJaCoCo generates target/site/jacoco/jacoco.xml. nolapse will read this file.
Initialise
Section titled “Initialise”nolapse init --repo . --lang javaRun a check
Section titled “Run a check”nolapse run --repo . --lang javaGitHub Actions workflow (Maven)
Section titled “GitHub Actions workflow (Maven)”name: Coverage check
on: pull_request:
jobs: coverage: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 with: fetch-depth: 0
- name: Set up Java uses: actions/setup-java@v4 with: java-version: "21" distribution: temurin
- name: Build and test run: mvn verify
- name: Run nolapse uses: nolapse/nolapse-action@v1 with: repo-token: ${{ secrets.GITHUB_TOKEN }} lang: java warn-threshold: "0.5" fail-threshold: "1.0"JaCoCo Configuration
Section titled “JaCoCo Configuration”nolapse will read the JaCoCo XML report. Add the JaCoCo plugin to pom.xml:
<plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> <version>0.8.11</version> <executions> <execution> <goals><goal>prepare-agent</goal></goals> </execution> <execution> <id>report</id> <phase>verify</phase> <goals><goal>report</goal></goals> </execution> </executions></plugin>Get Notified
Section titled “Get Notified”Watch the nolapse changelog for the Java runner release. Once available, this tutorial will be updated with full working commands and example output.
See Also
Section titled “See Also”- Tutorial: Go Microservice — a fully working tutorial available today
- Tutorial: Python Django App — a fully working tutorial available today
- Multi-Language Projects — run multiple language components side by side