diff --git a/Jenkinsfile b/Jenkinsfile index 95851aab6..f5b3c151b 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -13,6 +13,7 @@ pipeline { environment { MAVEN_OPTS = '-Xmx1024m' PROJECT_NAME = 'spring-petclinic' + SONAR_PROJECT_KEY = 'spring-petclinic' } stages { @@ -52,6 +53,29 @@ pipeline { } } + stage('SonarQube Analysis') { + steps { + echo 'Running SonarQube analysis...' + withSonarQubeEnv('SonarQubeServer') { + sh """ + ./mvnw sonar:sonar \ + -Dsonar.projectKey=${env.SONAR_PROJECT_KEY} \ + -Dsonar.projectName=${env.PROJECT_NAME} \ + -Dsonar.projectVersion=${env.BUILD_NUMBER} \ + -Dsonar.qualitygate.wait=false + """ + } + } + } + + stage('Quality Gate') { + steps { + timeout(time: 5, unit: 'MINUTES') { + waitForQualityGate abortPipeline: true + } + } + } + stage('Code Quality') { steps { echo 'Running checkstyle...' diff --git a/README.md b/README.md index 248a142e2..c5b583f05 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ ## From the project root, provision the stack: - ```bash - docker compose up -d - ``` +```bash +docker compose up -d +``` # Spring PetClinic Sample Application [![Build Status](https://github.com/spring-projects/spring-petclinic/actions/workflows/maven-build.yml/badge.svg)](https://github.com/spring-projects/spring-petclinic/actions/workflows/maven-build.yml)[![Build Status](https://github.com/spring-projects/spring-petclinic/actions/workflows/gradle-build.yml/badge.svg)](https://github.com/spring-projects/spring-petclinic/actions/workflows/gradle-build.yml) @@ -16,7 +16,6 @@ See the presentation here: > **Note:** These slides refer to a legacy, pre–Spring Boot version of Petclinic and may not reflect the current Spring Boot–based implementation. > For up-to-date information, please refer to this repository and its documentation. - ## Run Petclinic locally Spring Petclinic is a [Spring Boot](https://spring.io/guides/gs/spring-boot) application built using [Maven](https://spring.io/guides/gs/maven/) or [Gradle](https://spring.io/guides/gs/gradle/). @@ -51,6 +50,14 @@ There is no `Dockerfile` in this project. You can build a container image (if yo ./mvnw spring-boot:build-image ``` +## Continuous Integration with Jenkins, SonarQube and Blue Ocean + +1. Install the Jenkins plugins **SonarQube Scanner for Jenkins**, **Pipeline Utility Steps**, **JaCoCo**, and **Blue Ocean**. +2. In Jenkins, go to _Manage Jenkins → Configure System_ and add a SonarQube server named `SonarQubeServer`. Provide the Sonar URL and a token issued from your SonarQube instance. The Jenkins global configuration will expose `SONAR_HOST_URL` and `SONAR_AUTH_TOKEN` to the pipeline. +3. Configure a Multibranch Pipeline or a Pipeline job that points at this repository. The provided `Jenkinsfile` now contains explicit stages for SonarQube analysis and the quality gate check; the `sonar-project.properties` file supplies project metadata and paths. +4. Trigger a build. In Jenkins, switch to the **Blue Ocean** view to visualize the pipeline stages (`Checkout` → `Build` → `Test` → `SonarQube Analysis` → `Quality Gate` → `Code Quality` → `Package` → `Archive`) and inspect test results, code coverage, and quality gate status inline. +5. Review the SonarQube dashboard after the build completes to explore issues, coverage, and maintainability metrics collected from the static analysis. + ## In case you find a bug/suggested improvement for Spring Petclinic Our issue tracker is available [here](https://github.com/spring-projects/spring-petclinic/issues). @@ -108,7 +115,7 @@ The following items should be installed in your system: - [Git command line tool](https://help.github.com/articles/set-up-git) - Your preferred IDE - Eclipse with the m2e plugin. Note: when m2e is available, there is an m2 icon in `Help -> About` dialog. If m2e is - not there, follow the install process [here](https://www.eclipse.org/m2e/) + not there, follow the install process [here](https://www.eclipse.org/m2e/) - [Spring Tools Suite](https://spring.io/tools) (STS) - [IntelliJ IDEA](https://www.jetbrains.com/idea/) - [VS Code](https://code.visualstudio.com) @@ -117,35 +124,35 @@ The following items should be installed in your system: 1. On the command line run: - ```bash - git clone https://github.com/spring-projects/spring-petclinic.git - ``` + ```bash + git clone https://github.com/spring-projects/spring-petclinic.git + ``` 1. Inside Eclipse or STS: - Open the project via `File -> Import -> Maven -> Existing Maven project`, then select the root directory of the cloned repo. + Open the project via `File -> Import -> Maven -> Existing Maven project`, then select the root directory of the cloned repo. - Then either build on the command line `./mvnw generate-resources` or use the Eclipse launcher (right-click on project and `Run As -> Maven install`) to generate the CSS. Run the application's main method by right-clicking on it and choosing `Run As -> Java Application`. + Then either build on the command line `./mvnw generate-resources` or use the Eclipse launcher (right-click on project and `Run As -> Maven install`) to generate the CSS. Run the application's main method by right-clicking on it and choosing `Run As -> Java Application`. 1. Inside IntelliJ IDEA: - In the main menu, choose `File -> Open` and select the Petclinic [pom.xml](pom.xml). Click on the `Open` button. + In the main menu, choose `File -> Open` and select the Petclinic [pom.xml](pom.xml). Click on the `Open` button. - - CSS files are generated from the Maven build. You can build them on the command line `./mvnw generate-resources` or right-click on the `spring-petclinic` project then `Maven -> Generates sources and Update Folders`. + - CSS files are generated from the Maven build. You can build them on the command line `./mvnw generate-resources` or right-click on the `spring-petclinic` project then `Maven -> Generates sources and Update Folders`. - - A run configuration named `PetClinicApplication` should have been created for you if you're using a recent Ultimate version. Otherwise, run the application by right-clicking on the `PetClinicApplication` main class and choosing `Run 'PetClinicApplication'`. + - A run configuration named `PetClinicApplication` should have been created for you if you're using a recent Ultimate version. Otherwise, run the application by right-clicking on the `PetClinicApplication` main class and choosing `Run 'PetClinicApplication'`. 1. Navigate to the Petclinic - Visit [http://localhost:8080](http://localhost:8080) in your browser. + Visit [http://localhost:8080](http://localhost:8080) in your browser. ## Looking for something in particular? -|Spring Boot Configuration | Class or Java property files | -|--------------------------|---| -|The Main Class | [PetClinicApplication](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java) | -|Properties Files | [application.properties](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/resources) | -|Caching | [CacheConfiguration](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/java/org/springframework/samples/petclinic/system/CacheConfiguration.java) | +| Spring Boot Configuration | Class or Java property files | +| ------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| The Main Class | [PetClinicApplication](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java) | +| Properties Files | [application.properties](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/resources) | +| Caching | [CacheConfiguration](https://github.com/spring-projects/spring-petclinic/blob/main/src/main/java/org/springframework/samples/petclinic/system/CacheConfiguration.java) | ## Interesting Spring Petclinic branches and forks @@ -159,17 +166,17 @@ GitHub org is the "canonical" implementation based on Spring Boot and Thymeleaf. One of the best parts about working on the Spring Petclinic application is that we have the opportunity to work in direct contact with many Open Source projects. We found bugs/suggested improvements on various topics such as Spring, Spring Data, Bean Validation and even Eclipse! In many cases, they've been fixed/implemented in just a few days. Here is a list of them: -| Name | Issue | -|------|-------| -| Spring JDBC: simplify usage of NamedParameterJdbcTemplate | [SPR-10256](https://github.com/spring-projects/spring-framework/issues/14889) and [SPR-10257](https://github.com/spring-projects/spring-framework/issues/14890) | -| Bean Validation / Hibernate Validator: simplify Maven dependencies and backward compatibility |[HV-790](https://hibernate.atlassian.net/browse/HV-790) and [HV-792](https://hibernate.atlassian.net/browse/HV-792) | -| Spring Data: provide more flexibility when working with JPQL queries | [DATAJPA-292](https://github.com/spring-projects/spring-data-jpa/issues/704) | +| Name | Issue | +| --------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- | +| Spring JDBC: simplify usage of NamedParameterJdbcTemplate | [SPR-10256](https://github.com/spring-projects/spring-framework/issues/14889) and [SPR-10257](https://github.com/spring-projects/spring-framework/issues/14890) | +| Bean Validation / Hibernate Validator: simplify Maven dependencies and backward compatibility | [HV-790](https://hibernate.atlassian.net/browse/HV-790) and [HV-792](https://hibernate.atlassian.net/browse/HV-792) | +| Spring Data: provide more flexibility when working with JPQL queries | [DATAJPA-292](https://github.com/spring-projects/spring-data-jpa/issues/704) | ## Contributing The [issue tracker](https://github.com/spring-projects/spring-petclinic/issues) is the preferred channel for bug reports, feature requests and submitting pull requests. -For pull requests, editor preferences are available in the [editor config](.editorconfig) for easy use in common text editors. Read more and download plugins at . All commits must include a __Signed-off-by__ trailer at the end of each commit message to indicate that the contributor agrees to the Developer Certificate of Origin. +For pull requests, editor preferences are available in the [editor config](.editorconfig) for easy use in common text editors. Read more and download plugins at . All commits must include a **Signed-off-by** trailer at the end of each commit message to indicate that the contributor agrees to the Developer Certificate of Origin. For additional details, please refer to the blog post [Hello DCO, Goodbye CLA: Simplifying Contributions to Spring](https://spring.io/blog/2025/01/06/hello-dco-goodbye-cla-simplifying-contributions-to-spring). ## License diff --git a/sonar-project.properties b/sonar-project.properties new file mode 100644 index 000000000..fa6096ae9 --- /dev/null +++ b/sonar-project.properties @@ -0,0 +1,14 @@ +sonar.projectKey=petclinic +sonar.projectName=PetClinic +sonar.sourceEncoding=UTF-8 + +sonar.sources=src/main/java +sonar.tests=src/test/java +sonar.java.binaries=target/classes + +sonar.junit.reportPaths=target/surefire-reports +sonar.jacoco.reportPaths=target/jacoco.exec + +sonar.exclusions=**/target/**,**/node_modules/** +sonar.test.inclusions=**/*Test.java +