This is a sample Java Maven project that demonstrates how to set up a CI/CD pipeline with:
- GitHub Actions β for CI automation
- SonarQube / SonarCloud β for code quality & static analysis
- Snyk β for security vulnerability scanning
dummy-ci-cd-java/
βββ pom.xml # Maven build configuration
βββ src
β βββ main/java/com/example/App.java # Main Java application
β βββ test/java/com/example/AppTest.java # JUnit test
- Java 17
- Maven
- JUnit 4.13.2
- GitHub Actions
- SonarCloud
- Snyk
The pipeline is defined in .github/workflows/ci-cd.yml
and includes:
-
Build & Test
- Compiles the project using Maven
- Runs JUnit tests
-
SonarQube / SonarCloud Scan
- Runs
mvn sonar:sonar
- Uploads code quality & security analysis results
- Runs
-
Snyk Security Scan
- Scans for vulnerabilities in dependencies
- Fails if medium/high severity issues are found
Go to your repo β Settings β Secrets and variables β Actions and add:
Secret Name | Value |
---|---|
SONAR_TOKEN |
Token from SonarCloud account |
SONAR_HOST_URL |
https://sonarcloud.io |
SNYK_TOKEN |
Token from Snyk account |
-
Push any code changes (e.g., update
App.java
). -
Go to the Actions tab in GitHub.
-
Watch the pipeline run:
- β Build β compile & test
- β Sonar β code quality report
- β Snyk β vulnerability report
- SonarCloud Dashboard β Detailed code analysis (bugs, smells, coverage).
- Snyk Reports β Dependency security vulnerabilities.
- Add Jacoco for test coverage reports.
- Add Docker build & push step.
- Add deployment (e.g., AWS / Kubernetes).
- Add notifications (Slack/MS Teams).
β With this setup, every code push is automatically built, tested, analyzed, and security-checked before deployment.