Skip to content

Commit

Permalink
Update Spring Boot release, adding Gradle build and cleanup
Browse files Browse the repository at this point in the history
- Update Spring Boot release, Checkstyle, Mysql.
- Formatting pom.xml with sortpom-maven-plugin.
- Rename README to standard file name.
- Adding GitHub Action for Gradle.
  • Loading branch information
patbaumgartner committed Nov 5, 2024
1 parent dff45cf commit b720f57
Show file tree
Hide file tree
Showing 10 changed files with 85 additions and 66 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/gradle-build.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions .github/workflows/maven-build.yml
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -26,4 +26,4 @@ jobs:
distribution: 'adopt'
cache: maven
- name: Build with Maven Wrapper
run: ./mvnw -B package
run: ./mvnw -B verify
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
HELP.md
pom.xml.bak
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
Expand Down Expand Up @@ -41,6 +42,9 @@ out/
### VS Code ###
.vscode/

### SDK Man ###
.sdkmanrc

### CSS ###
_site/
*.css
Expand Down
15 changes: 3 additions & 12 deletions readme.md → README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -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:
Expand All @@ -52,16 +44,15 @@ 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.

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
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
services:
mysql:
image: mysql:9.0
image: mysql:9.1
ports:
- "3306:3306"
environment:
Expand Down
86 changes: 40 additions & 46 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -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>

Expand Down Expand Up @@ -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>
Expand All @@ -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>
Expand Down Expand Up @@ -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>
Expand All @@ -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>
Expand All @@ -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>

Expand All @@ -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>
Expand All @@ -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>
Expand Down Expand Up @@ -406,7 +401,7 @@
</goals>
</pluginExecutionFilter>
<action>
<ignore />
<ignore></ignore>
</action>
</pluginExecution>
<pluginExecution>
Expand All @@ -419,7 +414,7 @@
</goals>
</pluginExecutionFilter>
<action>
<ignore />
<ignore></ignore>
</action>
</pluginExecution>
<pluginExecution>
Expand All @@ -432,7 +427,7 @@
</goals>
</pluginExecutionFilter>
<action>
<ignore />
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
Expand All @@ -444,5 +439,4 @@
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
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;

/**
Expand Down

0 comments on commit b720f57

Please sign in to comment.