Skip to content

Commit 6685a00

Browse files
authored
introduce a parent POM for Spring Boot projects (#162)
1 parent 12057bb commit 6685a00

File tree

432 files changed

+4136
-4923
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

432 files changed

+4136
-4923
lines changed

.github/workflows/maven.yml

+10-48
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,30 @@
1-
name: Build Maven Projects
1+
name: Build Maven Projects (Java 8, 11, 17)
2+
23
on:
34
push:
45
schedule:
56
- cron: '0 5 * * SUN'
7+
68
jobs:
7-
build-java-8-and-17-projects:
9+
build-java-8-11-17-projects:
810
strategy:
911
fail-fast: false
1012
matrix:
11-
versions: [8, 17]
12-
runs-on: ubuntu-20.04
13+
versions: [8, 11, 17]
14+
runs-on: ubuntu-latest
1315
name: Build Java ${{ matrix.versions }} projects
1416
steps:
1517
- name: VCS checkout
16-
uses: actions/checkout@v1
17-
18-
- name: Set up cache
19-
uses: actions/cache@v1
20-
with:
21-
path: ~/.m2/repository
22-
key: ${{ runner.os }}-maven-jdk${{ matrix.versions }}-${{ hashFiles('**/pom.xml') }}
23-
restore-keys: |
24-
${{ runner.os }}-maven-jdk${{ matrix.versions }}-
18+
uses: actions/checkout@v4
2519

2620
- name: Set up JDK ${{ matrix.versions }}
27-
uses: actions/setup-java@v2
21+
uses: actions/setup-java@v4
2822
with:
2923
java-version: ${{ matrix.versions }}
30-
distribution: 'adopt'
31-
java-package: 'jdk'
24+
distribution: adopt
25+
cache: maven
3226

3327
- name: Build all projects with Maven
3428
run: |
3529
chmod +x ./buildJdk${{ matrix.versions }}Projects.sh
3630
./buildJdk${{ matrix.versions }}Projects.sh
37-
38-
build-java-11-project-batches:
39-
strategy:
40-
fail-fast: false
41-
matrix:
42-
batch: [1, 2, 3]
43-
runs-on: ubuntu-20.04
44-
name: Build Java 11 Batch ${{ matrix.batch }} projects
45-
steps:
46-
- name: VCS checkout
47-
uses: actions/checkout@v1
48-
49-
- name: Set up cache
50-
uses: actions/cache@v1
51-
with:
52-
path: ~/.m2/repository
53-
key: ${{ runner.os }}-maven-jdk${{ matrix.batch }}-${{ hashFiles('**/pom.xml') }}
54-
restore-keys: |
55-
${{ runner.os }}-maven-jdk${{ matrix.batch }}-
56-
57-
- name: Set up JDK $11
58-
uses: actions/setup-java@v2
59-
with:
60-
java-version: 11
61-
distribution: 'adopt'
62-
java-package: 'jdk'
63-
64-
- name: Build all projects of batch with Maven
65-
run: |
66-
chmod +x ./buildJdk11Projects_0${{ matrix.batch }}.sh
67-
./buildJdk11Projects_0${{ matrix.batch }}.sh
68-

.github/workflows/sampleJavaMavenProject.yml

+23-21
Original file line numberDiff line numberDiff line change
@@ -4,62 +4,62 @@ on: [push]
44

55
jobs:
66
compile:
7-
runs-on: ubuntu-20.04
7+
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
java: [ 11, 12, 13 ]
10+
java: [ 21 ]
1111
name: Java ${{ matrix.java }} compile
1212
steps:
1313
- name: Checkout Source Code
14-
uses: actions/checkout@v2
14+
uses: actions/checkout@v3
15+
1516
- name: Setup Java
16-
uses: actions/setup-java@v2
17+
uses: actions/setup-java@v3
1718
with:
1819
distribution: 'adopt'
1920
java-package: jdk
2021
java-version: ${{ matrix.java }}
22+
2123
- name: Compile the Project
22-
working-directory: github-actions-java-maven
23-
run: mvn -B compile
24+
run: ./mvnw -f github-actions-java-maven/pom.xml -B compile
2425

2526
build:
26-
runs-on: ubuntu-20.04
27+
runs-on: ubuntu-latest
2728
needs: compile
2829
name: Build the Maven Project
2930
steps:
30-
- uses: actions/checkout@v2
31-
- uses: actions/cache@v2
32-
with:
33-
path: ~/.m2/repository
34-
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
35-
restore-keys: |
36-
${{ runner.os }}-maven-
37-
- name: Set up JDK 11
38-
uses: actions/setup-java@v2
31+
- uses: actions/checkout@v3
32+
33+
- name: Set up JDK 21
34+
uses: actions/setup-java@v3
3935
with:
4036
distribution: 'adopt'
41-
java-version: '11'
37+
java-version: '21'
4238
java-package: jdk
39+
cache: 'maven'
40+
4341
- name: Build and test project
44-
working-directory: github-actions-java-maven
45-
run: mvn -B verify
42+
run: ./mvnw -f github-actions-java-maven/pom.xml -B verify
43+
4644
- name: Upload Maven build artifact
4745
uses: actions/upload-artifact@v2
4846
with:
4947
name: artifact.jar
5048
path: github-actions-java-maven/target/github-actions-java-maven.jar
5149

5250
deploy:
53-
runs-on: ubuntu-20.04
51+
runs-on: ubuntu-latest
5452
needs: build
5553
name: Build Docker Container and Deploy to Kubernetes
5654
steps:
57-
- uses: actions/checkout@v2
55+
- uses: actions/checkout@v3
56+
5857
- name: Download Maven build artifact
5958
uses: actions/download-artifact@v2
6059
with:
6160
name: artifact.jar
6261
path: github-actions-java-maven/target
62+
6363
- name: Build Docker container
6464
working-directory: github-actions-java-maven
6565
run: |
@@ -68,7 +68,9 @@ jobs:
6868
env:
6969
SUPER_SECRET: ${{ secrets.SUPER_SECRET }}
7070
run: echo "Content of secret - $SUPER_SECRET"
71+
7172
- name: Push Docker images
7273
run: echo "Pushing Docker image to Container Registry (e.g. ECR)"
74+
7375
- name: Deploy application
7476
run: echo "Deploying application (e.g. Kubernetes)"

.gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
.DS_Store
22
.idea
3-
*.iml
3+
*.iml
4+
*.bak
5+
target
6+
spotless-index

.pre-commit-config.yaml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v4.5.0
4+
hooks:
5+
- id: check-yaml
6+
- id: end-of-file-fixer
7+
- id: trailing-whitespace
8+
- repo: https://github.com/Lucas-C/pre-commit-hooks
9+
rev: v1.5.4
10+
hooks:
11+
- id: forbid-crlf
12+
- id: remove-crlf
13+
- repo: https://github.com/ejba/pre-commit-maven
14+
rev: v0.3.4
15+
hooks:
16+
- id: maven
17+
args: ['-f pom.xml spotless:apply']

avoid-repeating-attributes-in-jpa-entities/pom.xml

+7-14
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,20 @@
33
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
44
<modelVersion>4.0.0</modelVersion>
55

6-
<groupId>de.blog.rieckpil</groupId>
6+
<parent>
7+
<groupId>de.rieckpil.blog</groupId>
8+
<artifactId>blog-parent</artifactId>
9+
<version>0.0.1-SNAPSHOT</version>
10+
<relativePath>../pom.xml</relativePath>
11+
</parent>
12+
713
<artifactId>avoid-repeating-attributes-in-jpa-entities</artifactId>
814
<version>0.0.1-SNAPSHOT</version>
915
<packaging>jar</packaging>
1016

1117
<name>avoid-repeating-attributes-in-jpa-entities</name>
1218
<description>Demo project fo avoiding repeated attributes in JPA entities</description>
1319

14-
<parent>
15-
<groupId>org.springframework.boot</groupId>
16-
<artifactId>spring-boot-starter-parent</artifactId>
17-
<version>2.3.0.RELEASE</version>
18-
<relativePath/> <!-- lookup parent from repository -->
19-
</parent>
20-
21-
<properties>
22-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23-
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24-
<java.version>11</java.version>
25-
</properties>
26-
2720
<dependencies>
2821
<dependency>
2922
<groupId>org.springframework.boot</groupId>
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package de.blog.rieckpil;
22

3+
import jakarta.persistence.*;
4+
import java.time.LocalDateTime;
5+
import java.util.concurrent.ThreadLocalRandom;
36
import lombok.Data;
47
import org.hibernate.annotations.CreationTimestamp;
58
import org.hibernate.annotations.UpdateTimestamp;
69

7-
import javax.persistence.*;
8-
import java.time.LocalDateTime;
9-
import java.util.concurrent.ThreadLocalRandom;
10-
1110
@Data
1211
@MappedSuperclass
1312
public class BaseEnterpriseEntity {
@@ -18,15 +17,12 @@ public class BaseEnterpriseEntity {
1817

1918
private String internId;
2019

21-
@CreationTimestamp
22-
private LocalDateTime createdAt;
20+
@CreationTimestamp private LocalDateTime createdAt;
2321

24-
@UpdateTimestamp
25-
private LocalDateTime updatedAt;
22+
@UpdateTimestamp private LocalDateTime updatedAt;
2623

2724
@PrePersist
2825
public void prePersist() {
2926
this.internId = String.valueOf(Math.abs(ThreadLocalRandom.current().nextInt()));
3027
}
31-
3228
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package de.blog.rieckpil;
22

3+
import jakarta.persistence.Column;
4+
import jakarta.persistence.Entity;
35
import lombok.Data;
46

5-
import javax.persistence.Column;
6-
import javax.persistence.Entity;
7-
87
@Data
98
@Entity
109
public class Customer extends BaseEnterpriseEntity {
@@ -14,5 +13,4 @@ public class Customer extends BaseEnterpriseEntity {
1413

1514
@Column(nullable = false, length = 40)
1615
private String customerId;
17-
1816
}

avoid-repeating-attributes-in-jpa-entities/src/main/java/de/blog/rieckpil/CustomerRepository.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22

33
import org.springframework.data.jpa.repository.JpaRepository;
44

5-
public interface CustomerRepository extends JpaRepository<Customer, Long> {
6-
}
5+
public interface CustomerRepository extends JpaRepository<Customer, Long> {}

avoid-repeating-attributes-in-jpa-entities/src/main/java/de/blog/rieckpil/DatabaseFiller.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ public class DatabaseFiller implements CommandLineRunner {
99
private final CustomerRepository customerRepository;
1010
private final ProductRepository productRepository;
1111

12-
public DatabaseFiller(CustomerRepository customerRepository, ProductRepository productRepository) {
12+
public DatabaseFiller(
13+
CustomerRepository customerRepository, ProductRepository productRepository) {
1314
this.customerRepository = customerRepository;
1415
this.productRepository = productRepository;
1516
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package de.blog.rieckpil;
22

3+
import jakarta.persistence.Column;
4+
import jakarta.persistence.Entity;
35
import lombok.Data;
46

5-
import javax.persistence.Column;
6-
import javax.persistence.Entity;
7-
87
@Data
98
@Entity
109
public class Product extends BaseEnterpriseEntity {
@@ -13,5 +12,4 @@ public class Product extends BaseEnterpriseEntity {
1312
private String name;
1413

1514
private int amount;
16-
1715
}

avoid-repeating-attributes-in-jpa-entities/src/main/java/de/blog/rieckpil/ProductRepository.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22

33
import org.springframework.data.jpa.repository.JpaRepository;
44

5-
public interface ProductRepository extends JpaRepository<Product, Long> {
6-
}
5+
public interface ProductRepository extends JpaRepository<Product, Long> {}

avoid-repeating-attributes-in-jpa-entities/src/test/java/de/blog/rieckpil/ApplicationTests.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,5 @@
77
public class ApplicationTests {
88

99
@Test
10-
public void contextLoads() {
11-
}
12-
10+
public void contextLoads() {}
1311
}

buildJdk11Projects_01.sh buildJdk11Projects.sh

+15-14
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,31 @@ set -o pipefail
55

66
mvn -B -f consumer-driven-contracts-with-spring-cloud-contract/book-store-server install
77

8-
declare -a arr=("whats-new-in-spring-boot-2.1"
8+
declare -a arr=(
99
"charts-in-pdf-java-ee"
10-
"avoid-repeating-attributes-in-jpa-entities"
1110
"java-benchmarking-with-jmh"
12-
"lazy-loading-of-jpa-attributes-with-hibernate"
1311
"graalvm-intro"
14-
"send-emails-with-sendgrid-and-spring-boot"
1512
"bootstrap-jakarta-ee-8-application"
1613
"custom-maven-archetype"
17-
"demo-crud-application"
18-
"dynamic-sql-querying-with-pagination"
19-
"deploy-spring-boot-to-gke"
20-
"spring-boot-hibernate-flyway-best-practices"
2114
"guide-to-jakarta-ee-with-react-and-postgresql"
2215
"five-java-9-features"
2316
"consumer-driven-contracts-with-spring-cloud-contract/book-store-client"
2417
"java-ee-with-kotlin"
25-
"spring-boot-with-kotlin"
26-
"difference-between-mock-and-mockbean"
27-
"spring-boot-override-test-properties"
2818
"test-java-http-clients"
29-
"spring-boot-test-mail-sending"
30-
"spring-boot-shedlock"
31-
"spring-data-mongo-test-testcontainers"
19+
"telegram-bot-notifications-with-java"
20+
"websockets-with-jakarta-ee"
21+
"open-liberty-maven-plugin-review"
22+
"jakarta-ee-react-file-handling"
23+
"review-microshed-testing"
24+
"whats-new-in-microprofile-3.1"
25+
"serverless-java-aws-examples/thumbnail-generator"
26+
"serverless-java-aws-examples/spring-cloud-function-aws"
27+
"serverless-java-aws-examples/spring-cloud-function-kotlin-aws"
28+
"five-unknown-junit-5-features"
29+
"mockito-tips-and-tricks"
30+
"testing-libraries-overview"
31+
"testing-java-applications-with-maven"
32+
"open-rewrite-example"
3233
)
3334

3435
for project in "${arr[@]}"

0 commit comments

Comments
 (0)