From 2616a7ed80f086b82a250a4e4db4276204d72484 Mon Sep 17 00:00:00 2001 From: "A.Fink" Date: Thu, 18 Apr 2024 00:37:49 +0300 Subject: [PATCH 1/4] gradle 8.7 (for JDK 21) --- basic-gradle-java/gradle/wrapper/gradle-wrapper.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/basic-gradle-java/gradle/wrapper/gradle-wrapper.properties b/basic-gradle-java/gradle/wrapper/gradle-wrapper.properties index 070cb70..d951fac 100644 --- a/basic-gradle-java/gradle/wrapper/gradle-wrapper.properties +++ b/basic-gradle-java/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists From a91432e87d372332671d7f3508d284b4d61aa6fd Mon Sep 17 00:00:00 2001 From: "A.Fink" Date: Thu, 18 Apr 2024 00:40:16 +0300 Subject: [PATCH 2/4] =?UTF-8?q?javax=20=E2=86=92=20jakarta?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/org/example/domain/BaseDomain.java | 6 +++--- .../src/main/java/org/example/domain/Customer.java | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/basic-gradle-java/src/main/java/org/example/domain/BaseDomain.java b/basic-gradle-java/src/main/java/org/example/domain/BaseDomain.java index 5202c6b..a7cf476 100644 --- a/basic-gradle-java/src/main/java/org/example/domain/BaseDomain.java +++ b/basic-gradle-java/src/main/java/org/example/domain/BaseDomain.java @@ -3,10 +3,10 @@ import io.ebean.Model; import io.ebean.annotation.WhenCreated; import io.ebean.annotation.WhenModified; +import jakarta.persistence.Id; +import jakarta.persistence.MappedSuperclass; +import jakarta.persistence.Version; -import javax.persistence.Id; -import javax.persistence.MappedSuperclass; -import javax.persistence.Version; import java.time.Instant; @MappedSuperclass diff --git a/basic-gradle-java/src/main/java/org/example/domain/Customer.java b/basic-gradle-java/src/main/java/org/example/domain/Customer.java index 6f1de9d..f396300 100644 --- a/basic-gradle-java/src/main/java/org/example/domain/Customer.java +++ b/basic-gradle-java/src/main/java/org/example/domain/Customer.java @@ -1,10 +1,10 @@ package org.example.domain; -import org.example.domain.finder.CustomerFinder; import io.ebean.annotation.NotNull; +import jakarta.persistence.Entity; +import jakarta.persistence.Lob; +import org.example.domain.finder.CustomerFinder; -import javax.persistence.Entity; -import javax.persistence.Lob; import java.time.LocalDate; @Entity From 49da352ec2b5bf8ad544546989765294fa928eb7 Mon Sep 17 00:00:00 2001 From: "A.Fink" Date: Thu, 18 Apr 2024 01:29:31 +0300 Subject: [PATCH 3/4] Lombok code compaction; ErrorProne --- basic-gradle-java/build.gradle | 52 +++++++++++++++---- basic-gradle-java/lombok.config | 20 +++++++ .../java/org/example/domain/BaseDomain.java | 40 ++++---------- .../java/org/example/domain/Customer.java | 35 ++++--------- 4 files changed, 81 insertions(+), 66 deletions(-) create mode 100644 basic-gradle-java/lombok.config diff --git a/basic-gradle-java/build.gradle b/basic-gradle-java/build.gradle index c36d56e..32782bb 100644 --- a/basic-gradle-java/build.gradle +++ b/basic-gradle-java/build.gradle @@ -1,7 +1,9 @@ plugins { id('idea') id('java') - id('io.ebean') version '13.11.0' + id("io.freefair.lombok") version 'latest.release' + id("io.ebean") version "latest.release" + id("net.ltgt.errorprone") version "latest.release" } repositories { @@ -15,22 +17,49 @@ java { } } -compileJava { - options.release = 17 +tasks.withType(JavaCompile).configureEach { options.encoding = 'UTF-8' + options.compilerArgs.addAll(['-Xlint:all,-serial', '-parameters']) + options.release.set(17) // javac --release 7→8..22+ + options.deprecation = true + options.debug = true + + options.errorprone { + enabled = true + disableWarningsInGeneratedCode = true + excludedPaths = ".*/(generated|test).*/.*" + disable("UnusedVariable") + disable("MissingSummary") + errorproneArgs = ["-XepExcludedPaths:.*/test/.*"] + } } dependencies { + errorprone("com.google.errorprone:error_prone_core:latest.release") + implementation "com.google.code.findbugs:jsr305:latest.release" // https://javadoc.io/doc/com.google.code.findbugs/jsr305/latest/index.html - implementation 'org.avaje.composite:logback:1.1' - implementation 'org.postgresql:postgresql:42.5.1' - implementation 'io.ebean:ebean:13.11.0' + implementation "io.ebean:ebean:latest.release" // apt query bean generation - annotationProcessor 'io.ebean:querybean-generator:13.11.0' + annotationProcessor 'io.ebean:querybean-generator:latest.release' + + + testImplementation 'org.junit.jupiter:junit-jupiter:latest.release' + testImplementation 'io.ebean:ebean-test:latest.release' + + testImplementation("ch.qos.logback:logback-classic:1.2.+") - testImplementation 'io.avaje:junit:1.1' - testImplementation 'io.ebean:ebean-test:13.11.0' + testImplementation 'org.postgresql:postgresql:latest.release' +} +configurations.configureEach { // .implementation ? https://tomgregory.com/how-to-exclude-gradle-dependencies/ + exclude group: 'io.ebean', module: 'ebean-joda-time' + + exclude group: "commons-logging", module: "commons-logging" // spring? + exclude group: "org.apache.logging.log4j", module: "log4j-api" + exclude group: "org.apache.logging.log4j", module: "log4j-to-slf4j" + exclude group: "org.jboss.slf4j", module: "slf4j-jboss-logmanager" + + exclude group: "com.mchange", module: "c3p0" } test { @@ -38,9 +67,12 @@ test { } ebean { - debugLevel = 1 //0 - 9 + debugLevel = 9 //0 - 9 + queryBeans = true } +lombok { version = "latest.release" } + test { testLogging.showStandardStreams = true testLogging.exceptionFormat = 'full' diff --git a/basic-gradle-java/lombok.config b/basic-gradle-java/lombok.config new file mode 100644 index 0000000..8a682f8 --- /dev/null +++ b/basic-gradle-java/lombok.config @@ -0,0 +1,20 @@ +#lombok.anyConstructor.addConstructorProperties=true → javac -parameters ➕ copyableAnnotations ➕ @RequiredArgsConstructor(onConstructor_=@JsonCreator) + +#lombok.log.fieldName = LOGGER + +lombok.addNullAnnotations = javax +#lombok.addNullAnnotations=CUSTOM:com.example.annotations.NonNull:com.example.annotations.Nullable + +lombok.var.flagUsage = error + +lombok.addLombokGeneratedAnnotation = true + +lombok.copyableAnnotations += org.springframework.beans.factory.annotation.Qualifier +lombok.copyableAnnotations += com.fasterxml.jackson.annotation.JsonProperty +lombok.copyableAnnotations += com.fasterxml.jackson.databind.annotation.JsonDeserialize +lombok.copyableAnnotations += com.fasterxml.jackson.annotation.JsonFormat + +config.stopBubbling = true + +lombok.extern.findbugs.addSuppressFBWarnings = false +lombok.addSuppressWarnings = true diff --git a/basic-gradle-java/src/main/java/org/example/domain/BaseDomain.java b/basic-gradle-java/src/main/java/org/example/domain/BaseDomain.java index a7cf476..1b803fa 100644 --- a/basic-gradle-java/src/main/java/org/example/domain/BaseDomain.java +++ b/basic-gradle-java/src/main/java/org/example/domain/BaseDomain.java @@ -6,10 +6,19 @@ import jakarta.persistence.Id; import jakarta.persistence.MappedSuperclass; import jakarta.persistence.Version; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; import java.time.Instant; @MappedSuperclass +@Getter @Setter +@ToString(doNotUseGetters = true, callSuper = false) // avoid getters! +//@Accessors(fluent = true, chain = true) // instead of @Builder(toBuilder = true) +@NoArgsConstructor @AllArgsConstructor public abstract class BaseDomain extends Model { @Id @@ -24,35 +33,4 @@ public abstract class BaseDomain extends Model { @WhenModified Instant whenModified; - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public long getVersion() { - return version; - } - - public void setVersion(long version) { - this.version = version; - } - - public Instant getWhenCreated() { - return whenCreated; - } - - public void setWhenCreated(Instant whenCreated) { - this.whenCreated = whenCreated; - } - - public Instant getWhenModified() { - return whenModified; - } - - public void setWhenModified(Instant whenModified) { - this.whenModified = whenModified; - } } diff --git a/basic-gradle-java/src/main/java/org/example/domain/Customer.java b/basic-gradle-java/src/main/java/org/example/domain/Customer.java index f396300..d19d409 100644 --- a/basic-gradle-java/src/main/java/org/example/domain/Customer.java +++ b/basic-gradle-java/src/main/java/org/example/domain/Customer.java @@ -3,11 +3,21 @@ import io.ebean.annotation.NotNull; import jakarta.persistence.Entity; import jakarta.persistence.Lob; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; import org.example.domain.finder.CustomerFinder; import java.time.LocalDate; @Entity +// DON'T! @Data, @EqualsAndHashCode See https://ebean.io/docs/best-practice/ +@Getter @Setter +@ToString(doNotUseGetters = true, callSuper = true) // avoid getters! +@NoArgsConstructor @AllArgsConstructor +//@Accessors(fluent = true, chain = true) // instead of @Builder(toBuilder = true) public class Customer extends BaseDomain { public static final CustomerFinder find = new CustomerFinder(); @@ -23,29 +33,4 @@ public class Customer extends BaseDomain { public Customer(String name) { this.name = name; } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public LocalDate getStartDate() { - return startDate; - } - - public void setStartDate(LocalDate startDate) { - this.startDate = startDate; - } - - public String getComments() { - return comments; - } - - public void setComments(String comments) { - this.comments = comments; - } - } From c9c6dca57cc79da498bb267cac1c0f62f9aad646 Mon Sep 17 00:00:00 2001 From: "A.Fink" Date: Thu, 18 Apr 2024 01:36:10 +0300 Subject: [PATCH 4/4] ignore /generated_tests --- basic-gradle-java/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/basic-gradle-java/.gitignore b/basic-gradle-java/.gitignore index 54e8a29..3f0d8a1 100644 --- a/basic-gradle-java/.gitignore +++ b/basic-gradle-java/.gitignore @@ -1,6 +1,7 @@ out/ build/ generated/ +generated_tests/ .gradle/ .idea/ *.iml