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
# 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
@ -26,4 +26,4 @@ jobs:
distribution: 'adopt'
cache: maven
- name: Build with Maven Wrapper
run: ./mvnw -B package
run: ./mvnw -B verify

4
.gitignore vendored
View file

@ -1,4 +1,5 @@
HELP.md
pom.xml.bak
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
@ -41,6 +42,9 @@ out/
### VS Code ###
.vscode/
### SDK Man ###
.sdkmanrc
### CSS ###
_site/
*.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)
@ -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`.
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
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
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
exposed at `http://localhost:8080/h2-console`,
gets populated at startup with data. The h2 console is 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.
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:
```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

View file

@ -1,6 +1,6 @@
plugins {
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 'org.graalvm.buildtools.native' version '0.10.3'
id 'org.cyclonedx.bom' version '1.10.0'
@ -25,7 +25,7 @@ repositories {
mavenCentral()
}
ext.checkstyleVersion = "10.18.1"
ext.checkstyleVersion = "10.20.0"
ext.springJavaformatCheckstyleVersion = "0.0.43"
ext.webjarsFontawesomeVersion = "4.7.0"
ext.webjarsBootstrapVersion = "5.3.3"

View file

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

86
pom.xml
View file

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

View file

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

View file

@ -36,7 +36,7 @@ public class MysqlTestApplication {
@Profile("mysql")
@Bean
static MySQLContainer<?> container() {
return new MySQLContainer<>("mysql:9.0");
return new MySQLContainer<>("mysql:9.1");
}
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.springframework.util.SerializationUtils;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.assertj.core.api.Assertions.assertThat;
/**