Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce a parent POM for Spring Boot projects #162

Merged
merged 36 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
58 changes: 10 additions & 48 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
@@ -1,68 +1,30 @@
name: Build Maven Projects
name: Build Maven Projects (Java 8, 11, 17)

on:
push:
schedule:
- cron: '0 5 * * SUN'

jobs:
build-java-8-and-17-projects:
build-java-8-11-17-projects:
strategy:
fail-fast: false
matrix:
versions: [8, 17]
runs-on: ubuntu-20.04
versions: [8, 11, 17]
runs-on: ubuntu-latest
name: Build Java ${{ matrix.versions }} projects
steps:
- name: VCS checkout
uses: actions/checkout@v1

- name: Set up cache
uses: actions/cache@v1
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-jdk${{ matrix.versions }}-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-jdk${{ matrix.versions }}-
uses: actions/checkout@v4

- name: Set up JDK ${{ matrix.versions }}
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
java-version: ${{ matrix.versions }}
distribution: 'adopt'
java-package: 'jdk'
distribution: adopt
cache: maven

- name: Build all projects with Maven
run: |
chmod +x ./buildJdk${{ matrix.versions }}Projects.sh
./buildJdk${{ matrix.versions }}Projects.sh

build-java-11-project-batches:
strategy:
fail-fast: false
matrix:
batch: [1, 2, 3]
runs-on: ubuntu-20.04
name: Build Java 11 Batch ${{ matrix.batch }} projects
steps:
- name: VCS checkout
uses: actions/checkout@v1

- name: Set up cache
uses: actions/cache@v1
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-jdk${{ matrix.batch }}-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-jdk${{ matrix.batch }}-

- name: Set up JDK $11
uses: actions/setup-java@v2
with:
java-version: 11
distribution: 'adopt'
java-package: 'jdk'

- name: Build all projects of batch with Maven
run: |
chmod +x ./buildJdk11Projects_0${{ matrix.batch }}.sh
./buildJdk11Projects_0${{ matrix.batch }}.sh

44 changes: 23 additions & 21 deletions .github/workflows/sampleJavaMavenProject.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,62 @@ on: [push]

jobs:
compile:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
strategy:
matrix:
java: [ 11, 12, 13 ]
java: [ 21 ]
name: Java ${{ matrix.java }} compile
steps:
- name: Checkout Source Code
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Setup Java
uses: actions/setup-java@v2
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-package: jdk
java-version: ${{ matrix.java }}

- name: Compile the Project
working-directory: github-actions-java-maven
run: mvn -B compile
run: ./mvnw -f github-actions-java-maven/pom.xml -B compile

build:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
needs: compile
name: Build the Maven Project
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Set up JDK 11
uses: actions/setup-java@v2
- uses: actions/checkout@v3

- name: Set up JDK 21
uses: actions/setup-java@v3
with:
distribution: 'adopt'
java-version: '11'
java-version: '21'
java-package: jdk
cache: 'maven'

- name: Build and test project
working-directory: github-actions-java-maven
run: mvn -B verify
run: ./mvnw -f github-actions-java-maven/pom.xml -B verify

- name: Upload Maven build artifact
uses: actions/upload-artifact@v2
with:
name: artifact.jar
path: github-actions-java-maven/target/github-actions-java-maven.jar

deploy:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
needs: build
name: Build Docker Container and Deploy to Kubernetes
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Download Maven build artifact
uses: actions/download-artifact@v2
with:
name: artifact.jar
path: github-actions-java-maven/target

- name: Build Docker container
working-directory: github-actions-java-maven
run: |
Expand All @@ -68,7 +68,9 @@ jobs:
env:
SUPER_SECRET: ${{ secrets.SUPER_SECRET }}
run: echo "Content of secret - $SUPER_SECRET"

- name: Push Docker images
run: echo "Pushing Docker image to Container Registry (e.g. ECR)"

- name: Deploy application
run: echo "Deploying application (e.g. Kubernetes)"
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.DS_Store
.idea
*.iml
*.iml
*.bak
target
spotless-index
17 changes: 17 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/Lucas-C/pre-commit-hooks
rev: v1.5.4
hooks:
- id: forbid-crlf
- id: remove-crlf
- repo: https://github.com/ejba/pre-commit-maven
rev: v0.3.4
hooks:
- id: maven
args: ['-f pom.xml spotless:apply']
21 changes: 7 additions & 14 deletions avoid-repeating-attributes-in-jpa-entities/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,20 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>de.blog.rieckpil</groupId>
<parent>
<groupId>de.rieckpil.blog</groupId>
<artifactId>blog-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>avoid-repeating-attributes-in-jpa-entities</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

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

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package de.blog.rieckpil;

import jakarta.persistence.*;
import java.time.LocalDateTime;
import java.util.concurrent.ThreadLocalRandom;
import lombok.Data;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.concurrent.ThreadLocalRandom;

@Data
@MappedSuperclass
public class BaseEnterpriseEntity {
Expand All @@ -18,15 +17,12 @@ public class BaseEnterpriseEntity {

private String internId;

@CreationTimestamp
private LocalDateTime createdAt;
@CreationTimestamp private LocalDateTime createdAt;

@UpdateTimestamp
private LocalDateTime updatedAt;
@UpdateTimestamp private LocalDateTime updatedAt;

@PrePersist
public void prePersist() {
this.internId = String.valueOf(Math.abs(ThreadLocalRandom.current().nextInt()));
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package de.blog.rieckpil;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import lombok.Data;

import javax.persistence.Column;
import javax.persistence.Entity;

@Data
@Entity
public class Customer extends BaseEnterpriseEntity {
Expand All @@ -14,5 +13,4 @@ public class Customer extends BaseEnterpriseEntity {

@Column(nullable = false, length = 40)
private String customerId;

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@

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

public interface CustomerRepository extends JpaRepository<Customer, Long> {
}
public interface CustomerRepository extends JpaRepository<Customer, Long> {}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public class DatabaseFiller implements CommandLineRunner {
private final CustomerRepository customerRepository;
private final ProductRepository productRepository;

public DatabaseFiller(CustomerRepository customerRepository, ProductRepository productRepository) {
public DatabaseFiller(
CustomerRepository customerRepository, ProductRepository productRepository) {
this.customerRepository = customerRepository;
this.productRepository = productRepository;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package de.blog.rieckpil;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import lombok.Data;

import javax.persistence.Column;
import javax.persistence.Entity;

@Data
@Entity
public class Product extends BaseEnterpriseEntity {
Expand All @@ -13,5 +12,4 @@ public class Product extends BaseEnterpriseEntity {
private String name;

private int amount;

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@

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

public interface ProductRepository extends JpaRepository<Product, Long> {
}
public interface ProductRepository extends JpaRepository<Product, Long> {}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@
public class ApplicationTests {

@Test
public void contextLoads() {
}

public void contextLoads() {}
}
29 changes: 15 additions & 14 deletions buildJdk11Projects_01.sh → buildJdk11Projects.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,31 @@ set -o pipefail

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

declare -a arr=("whats-new-in-spring-boot-2.1"
declare -a arr=(
"charts-in-pdf-java-ee"
"avoid-repeating-attributes-in-jpa-entities"
"java-benchmarking-with-jmh"
"lazy-loading-of-jpa-attributes-with-hibernate"
"graalvm-intro"
"send-emails-with-sendgrid-and-spring-boot"
"bootstrap-jakarta-ee-8-application"
"custom-maven-archetype"
"demo-crud-application"
"dynamic-sql-querying-with-pagination"
"deploy-spring-boot-to-gke"
"spring-boot-hibernate-flyway-best-practices"
"guide-to-jakarta-ee-with-react-and-postgresql"
"five-java-9-features"
"consumer-driven-contracts-with-spring-cloud-contract/book-store-client"
"java-ee-with-kotlin"
"spring-boot-with-kotlin"
"difference-between-mock-and-mockbean"
"spring-boot-override-test-properties"
"test-java-http-clients"
"spring-boot-test-mail-sending"
"spring-boot-shedlock"
"spring-data-mongo-test-testcontainers"
"telegram-bot-notifications-with-java"
"websockets-with-jakarta-ee"
"open-liberty-maven-plugin-review"
"jakarta-ee-react-file-handling"
"review-microshed-testing"
"whats-new-in-microprofile-3.1"
"serverless-java-aws-examples/thumbnail-generator"
"serverless-java-aws-examples/spring-cloud-function-aws"
"serverless-java-aws-examples/spring-cloud-function-kotlin-aws"
"five-unknown-junit-5-features"
"mockito-tips-and-tricks"
"testing-libraries-overview"
"testing-java-applications-with-maven"
"open-rewrite-example"
)

for project in "${arr[@]}"
Expand Down
Loading
Loading