Update Spring Boot release, adding Gradle build and cleanup

- Update Spring Boot release, Checkstyle, Mysql.
- Formatting pom.xml with sortpom-maven-plugin.
- Rename README to standard file name.
- Adding GitHub Action for Gradle.
This commit is contained in:
Patrick Baumgartner 2024-11-05 09:45:11 +01:00 committed by Dave Syer
parent dff45cf70c
commit a50bfb65bb
10 changed files with 85 additions and 66 deletions

31
.github/workflows/gradle-build.yml vendored Normal file
View file

@ -0,0 +1,31 @@
# This workflow will build a Java project with Gradle, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/use-cases-and-examples/building-and-testing/building-and-testing-java-with-gradle
name: Java CI with Gradle
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
java: [ '17' ]
steps:
- uses: actions/checkout@v4
- name: Set up JDK ${{matrix.java}}
uses: actions/setup-java@v4
with:
java-version: ${{matrix.java}}
distribution: 'adopt'
cache: maven
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Build with Gradle
run: ./gradlew build

View file

@ -1,5 +1,5 @@
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time # This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven # For more information see: https://docs.github.com/en/actions/use-cases-and-examples/building-and-testing/building-and-testing-java-with-maven
name: Java CI with Maven name: Java CI with Maven
@ -26,4 +26,4 @@ jobs:
distribution: 'adopt' distribution: 'adopt'
cache: maven cache: maven
- name: Build with Maven Wrapper - name: Build with Maven Wrapper
run: ./mvnw -B package run: ./mvnw -B verify

4
.gitignore vendored
View file

@ -1,4 +1,5 @@
HELP.md HELP.md
pom.xml.bak
target/ target/
!.mvn/wrapper/maven-wrapper.jar !.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/ !**/src/main/**/target/
@ -41,6 +42,9 @@ out/
### VS Code ### ### VS Code ###
.vscode/ .vscode/
### SDK Man ###
.sdkmanrc
### CSS ### ### CSS ###
_site/ _site/
*.css *.css

View file

@ -1,4 +1,4 @@
# 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) # 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)
[![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/spring-projects/spring-petclinic) [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=7517918) [![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/spring-projects/spring-petclinic) [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=7517918)
@ -29,14 +29,6 @@ Or you can run it from Maven directly using the Spring Boot Maven plugin. If you
> NOTE: If you prefer to use Gradle, you can build the app using `./gradlew build` and look for the jar file in `build/libs`. > NOTE: If you prefer to use Gradle, you can build the app using `./gradlew build` and look for the jar file in `build/libs`.
At development time it is recommended to use the integration tests (whch have their own `main` method) to run the application. This will allow you to make changes to the content and see the changes immediately. You can run the integration tests from your IDE or using the command line. Because there are multiple main classes for different database configurations, you have to choose one, e.g:
```bash
./mvnw spring-boot:test-run -Dspring-boot.run.main-class=org.springframework.samples.petclinic.PetClinicIntegrationTests
```
Or you can run it in your IDE directly from the test class of your choice.
## Building a Container ## Building a Container
There is no `Dockerfile` in this project. You can build a container image (if you have a docker daemon) using the Spring Boot build plugin: There is no `Dockerfile` in this project. You can build a container image (if you have a docker daemon) using the Spring Boot build plugin:
@ -52,8 +44,7 @@ Our issue tracker is available [here](https://github.com/spring-projects/spring-
## Database configuration ## Database configuration
In its default configuration, Petclinic uses an in-memory database (H2) which In its default configuration, Petclinic uses an in-memory database (H2) which
gets populated at startup with data. If you launch the app from the integration tests, the h2 console is automatically gets populated at startup with data. The h2 console is exposed at `http://localhost:8080/h2-console`,
exposed at `http://localhost:8080/h2-console`,
and it is possible to inspect the content of the database using the `jdbc:h2:mem:<uuid>` URL. The UUID is printed at startup to the console. and it is possible to inspect the content of the database using the `jdbc:h2:mem:<uuid>` URL. The UUID is printed at startup to the console.
A similar setup is provided for MySQL and PostgreSQL if a persistent database configuration is needed. Note that whenever the database type changes, the app needs to run with a different profile: `spring.profiles.active=mysql` for MySQL or `spring.profiles.active=postgres` for PostgreSQL. See the [Spring Boot documentation](https://docs.spring.io/spring-boot/how-to/properties-and-configuration.html#howto.properties-and-configuration.set-active-spring-profiles) for more detail on how to set the active profile. A similar setup is provided for MySQL and PostgreSQL if a persistent database configuration is needed. Note that whenever the database type changes, the app needs to run with a different profile: `spring.profiles.active=mysql` for MySQL or `spring.profiles.active=postgres` for PostgreSQL. See the [Spring Boot documentation](https://docs.spring.io/spring-boot/how-to/properties-and-configuration.html#howto.properties-and-configuration.set-active-spring-profiles) for more detail on how to set the active profile.
@ -61,7 +52,7 @@ A similar setup is provided for MySQL and PostgreSQL if a persistent database co
You can start MySQL or PostgreSQL locally with whatever installer works for your OS or use docker: You can start MySQL or PostgreSQL locally with whatever installer works for your OS or use docker:
```bash ```bash
docker run -e MYSQL_USER=petclinic -e MYSQL_PASSWORD=petclinic -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=petclinic -p 3306:3306 mysql:9.0 docker run -e MYSQL_USER=petclinic -e MYSQL_PASSWORD=petclinic -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=petclinic -p 3306:3306 mysql:9.1
``` ```
or or

View file

@ -1,6 +1,6 @@
plugins { plugins {
id 'java' id 'java'
id 'org.springframework.boot' version '3.3.4' id 'org.springframework.boot' version '3.3.5'
id 'io.spring.dependency-management' version '1.1.6' id 'io.spring.dependency-management' version '1.1.6'
id 'org.graalvm.buildtools.native' version '0.10.3' id 'org.graalvm.buildtools.native' version '0.10.3'
id 'org.cyclonedx.bom' version '1.10.0' id 'org.cyclonedx.bom' version '1.10.0'
@ -25,7 +25,7 @@ repositories {
mavenCentral() mavenCentral()
} }
ext.checkstyleVersion = "10.18.1" ext.checkstyleVersion = "10.20.0"
ext.springJavaformatCheckstyleVersion = "0.0.43" ext.springJavaformatCheckstyleVersion = "0.0.43"
ext.webjarsFontawesomeVersion = "4.7.0" ext.webjarsFontawesomeVersion = "4.7.0"
ext.webjarsBootstrapVersion = "5.3.3" ext.webjarsBootstrapVersion = "5.3.3"

View file

@ -1,6 +1,6 @@
services: services:
mysql: mysql:
image: mysql:9.0 image: mysql:9.1
ports: ports:
- "3306:3306" - "3306:3306"
environment: environment:

86
pom.xml
View file

@ -1,18 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.samples</groupId>
<artifactId>spring-petclinic</artifactId>
<version>3.3.0-SNAPSHOT</version>
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>3.3.4</version> <version>3.3.5</version>
<relativePath/> <relativePath></relativePath>
</parent> </parent>
<groupId>org.springframework.samples</groupId>
<artifactId>spring-petclinic</artifactId>
<version>3.3.0-SNAPSHOT</version>
<name>petclinic</name> <name>petclinic</name>
<properties> <properties>
@ -28,11 +28,11 @@
<webjars-bootstrap.version>5.3.3</webjars-bootstrap.version> <webjars-bootstrap.version>5.3.3</webjars-bootstrap.version>
<webjars-font-awesome.version>4.7.0</webjars-font-awesome.version> <webjars-font-awesome.version>4.7.0</webjars-font-awesome.version>
<checkstyle.version>10.18.1</checkstyle.version> <checkstyle.version>10.20.0</checkstyle.version>
<jacoco.version>0.8.12</jacoco.version> <jacoco.version>0.8.12</jacoco.version>
<libsass.version>0.2.29</libsass.version> <libsass.version>0.2.29</libsass.version>
<lifecycle-mapping>1.0.0</lifecycle-mapping> <lifecycle-mapping>1.0.0</lifecycle-mapping>
<maven-checkstyle.version>3.5.0</maven-checkstyle.version> <maven-checkstyle.version>3.6.0</maven-checkstyle.version>
<nohttp-checkstyle.version>0.0.11</nohttp-checkstyle.version> <nohttp-checkstyle.version>0.0.11</nohttp-checkstyle.version>
<spring-format.version>0.0.43</spring-format.version> <spring-format.version>0.0.43</spring-format.version>
@ -171,10 +171,10 @@
<version>${spring-format.version}</version> <version>${spring-format.version}</version>
<executions> <executions>
<execution> <execution>
<phase>validate</phase>
<goals> <goals>
<goal>validate</goal> <goal>validate</goal>
</goals> </goals>
<phase>validate</phase>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
@ -197,19 +197,17 @@
<executions> <executions>
<execution> <execution>
<id>nohttp-checkstyle-validation</id> <id>nohttp-checkstyle-validation</id>
<goals>
<goal>check</goal>
</goals>
<phase>validate</phase> <phase>validate</phase>
<configuration> <configuration>
<configLocation>src/checkstyle/nohttp-checkstyle.xml</configLocation> <configLocation>src/checkstyle/nohttp-checkstyle.xml</configLocation>
<sourceDirectories>${basedir}</sourceDirectories> <sourceDirectories>${basedir}</sourceDirectories>
<includes>**/*</includes> <includes>**/*</includes>
<excludes>**/.git/**/*,**/.idea/**/*,**/target/**/,**/.flattened-pom.xml,**/*.class</excludes> <excludes>**/.git/**/*,**/.idea/**/*,**/target/**/,**/.flattened-pom.xml,**/*.class</excludes>
<propertyExpansion> <propertyExpansion>config_loc=${basedir}/src/checkstyle/</propertyExpansion>
config_loc=${basedir}/src/checkstyle/
</propertyExpansion>
</configuration> </configuration>
<goals>
<goal>check</goal>
</goals>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
@ -250,10 +248,10 @@
</execution> </execution>
<execution> <execution>
<id>report</id> <id>report</id>
<phase>prepare-package</phase>
<goals> <goals>
<goal>report</goal> <goal>report</goal>
</goals> </goals>
<phase>prepare-package</phase>
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
@ -271,14 +269,13 @@
<!-- Spring Boot Actuator displays sbom-related information if a CycloneDX SBOM file is <!-- Spring Boot Actuator displays sbom-related information if a CycloneDX SBOM file is
present at the classpath --> present at the classpath -->
<plugin> <plugin>
<?m2e ignore?> <?m2e ignore?>
<groupId>org.cyclonedx</groupId> <groupId>org.cyclonedx</groupId>
<artifactId>cyclonedx-maven-plugin</artifactId> <artifactId>cyclonedx-maven-plugin</artifactId>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
<licenses> <licenses>
<license> <license>
<name>Apache License, Version 2.0</name> <name>Apache License, Version 2.0</name>
@ -288,39 +285,38 @@
<repositories> <repositories>
<repository> <repository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots> <snapshots>
<enabled>true</enabled> <enabled>true</enabled>
</snapshots> </snapshots>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
</repository> </repository>
<repository> <repository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots> <snapshots>
<enabled>false</enabled> <enabled>false</enabled>
</snapshots> </snapshots>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</repository> </repository>
</repositories> </repositories>
<pluginRepositories> <pluginRepositories>
<pluginRepository> <pluginRepository>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
<snapshots> <snapshots>
<enabled>true</enabled> <enabled>true</enabled>
</snapshots> </snapshots>
<id>spring-snapshots</id>
<name>Spring Snapshots</name>
<url>https://repo.spring.io/snapshot</url>
</pluginRepository> </pluginRepository>
<pluginRepository> <pluginRepository>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
<snapshots> <snapshots>
<enabled>false</enabled> <enabled>false</enabled>
</snapshots> </snapshots>
<id>spring-milestones</id>
<name>Spring Milestones</name>
<url>https://repo.spring.io/milestone</url>
</pluginRepository> </pluginRepository>
</pluginRepositories> </pluginRepositories>
@ -335,11 +331,11 @@
<executions> <executions>
<execution> <execution>
<id>unpack</id> <id>unpack</id>
<?m2e execute onConfiguration,onIncremental?>
<phase>generate-resources</phase>
<goals> <goals>
<goal>unpack</goal> <goal>unpack</goal>
</goals> </goals>
<?m2e execute onConfiguration,onIncremental?>
<phase>generate-resources</phase>
<configuration> <configuration>
<artifactItems> <artifactItems>
<artifactItem> <artifactItem>
@ -358,21 +354,20 @@
<groupId>com.gitlab.haynes</groupId> <groupId>com.gitlab.haynes</groupId>
<artifactId>libsass-maven-plugin</artifactId> <artifactId>libsass-maven-plugin</artifactId>
<version>${libsass.version}</version> <version>${libsass.version}</version>
<configuration>
<inputPath>${basedir}/src/main/scss/</inputPath>
<outputPath>${basedir}/src/main/resources/static/resources/css/</outputPath>
<includePath>${project.build.directory}/webjars/META-INF/resources/webjars/bootstrap/${webjars-bootstrap.version}/scss/</includePath>
</configuration>
<executions> <executions>
<execution> <execution>
<phase>generate-resources</phase>
<?m2e execute onConfiguration,onIncremental?> <?m2e execute onConfiguration,onIncremental?>
<goals> <goals>
<goal>compile</goal> <goal>compile</goal>
</goals> </goals>
<phase>generate-resources</phase>
</execution> </execution>
</executions> </executions>
<configuration>
<inputPath>${basedir}/src/main/scss/</inputPath>
<outputPath>${basedir}/src/main/resources/static/resources/css/</outputPath>
<includePath>
${project.build.directory}/webjars/META-INF/resources/webjars/bootstrap/${webjars-bootstrap.version}/scss/</includePath>
</configuration>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
@ -406,7 +401,7 @@
</goals> </goals>
</pluginExecutionFilter> </pluginExecutionFilter>
<action> <action>
<ignore /> <ignore></ignore>
</action> </action>
</pluginExecution> </pluginExecution>
<pluginExecution> <pluginExecution>
@ -419,7 +414,7 @@
</goals> </goals>
</pluginExecutionFilter> </pluginExecutionFilter>
<action> <action>
<ignore /> <ignore></ignore>
</action> </action>
</pluginExecution> </pluginExecution>
<pluginExecution> <pluginExecution>
@ -432,7 +427,7 @@
</goals> </goals>
</pluginExecutionFilter> </pluginExecutionFilter>
<action> <action>
<ignore /> <ignore></ignore>
</action> </action>
</pluginExecution> </pluginExecution>
</pluginExecutions> </pluginExecutions>
@ -444,5 +439,4 @@
</build> </build>
</profile> </profile>
</profiles> </profiles>
</project> </project>

View file

@ -46,7 +46,7 @@ class MySqlIntegrationTests {
@ServiceConnection @ServiceConnection
@Container @Container
static MySQLContainer<?> container = new MySQLContainer<>("mysql:9.0"); static MySQLContainer<?> container = new MySQLContainer<>("mysql:9.1");
@LocalServerPort @LocalServerPort
int port; int port;

View file

@ -36,7 +36,7 @@ public class MysqlTestApplication {
@Profile("mysql") @Profile("mysql")
@Bean @Bean
static MySQLContainer<?> container() { static MySQLContainer<?> container() {
return new MySQLContainer<>("mysql:9.0"); return new MySQLContainer<>("mysql:9.1");
} }
public static void main(String[] args) { public static void main(String[] args) {

View file

@ -18,7 +18,6 @@ package org.springframework.samples.petclinic.vet;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.util.SerializationUtils; import org.springframework.util.SerializationUtils;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
/** /**