Repository: jhipster/jhipster-lite
Pull request #11606 (2024-12-19 22:01:29)

feat(checkstyle): use latest checkstyle version when using checkstyle maven plugin

murdos: Failing build was caused by main being broken due to esbuild and vite v6.0.4: https://github.com/evanw/esbuild/issues/4010
I've manually triggered renovate update for vite v6.0.5 to fix the issue.

Patch:
diff --git a/src/main/java/tech/jhipster/lite/generator/server/javatool/checkstyle/domain/CheckstyleModuleFactory.java b/src/main/java/tech/jhipster/lite/generator/server/javatool/checkstyle/domain/CheckstyleModuleFactory.java
index 730f97115..2c41cc7f9 100644
--- a/src/main/java/tech/jhipster/lite/generator/server/javatool/checkstyle/domain/CheckstyleModuleFactory.java
+++ b/src/main/java/tech/jhipster/lite/generator/server/javatool/checkstyle/domain/CheckstyleModuleFactory.java
@@ -2,6 +2,7 @@ package tech.jhipster.lite.generator.server.javatool.checkstyle.domain;
 
 import static tech.jhipster.lite.module.domain.JHipsterModule.from;
 import static tech.jhipster.lite.module.domain.JHipsterModule.gradleCorePlugin;
+import static tech.jhipster.lite.module.domain.JHipsterModule.javaDependency;
 import static tech.jhipster.lite.module.domain.JHipsterModule.mavenPlugin;
 import static tech.jhipster.lite.module.domain.JHipsterModule.moduleBuilder;
 import static tech.jhipster.lite.module.domain.JHipsterModule.pluginExecution;
@@ -12,6 +13,7 @@ import tech.jhipster.lite.module.domain.JHipsterModule;
 import tech.jhipster.lite.module.domain.file.JHipsterSource;
 import tech.jhipster.lite.module.domain.gradleplugin.GradleMainBuildPlugin;
 import tech.jhipster.lite.module.domain.javabuild.VersionSlug;
+import tech.jhipster.lite.module.domain.javadependency.JavaDependency;
 import tech.jhipster.lite.module.domain.mavenplugin.MavenPlugin;
 import tech.jhipster.lite.module.domain.properties.JHipsterModuleProperties;
 import tech.jhipster.lite.shared.error.domain.Assert;
@@ -19,6 +21,7 @@ import tech.jhipster.lite.shared.error.domain.Assert;
 public class CheckstyleModuleFactory {
 
   private static final JHipsterSource TEMPLATES_SOURCE = from("server/javatool/checkstyle/main");
+  private static final String CHECKSTYLE = "checkstyle";
 
   public JHipsterModule buildModule(JHipsterModuleProperties properties) {
     Assert.notNull("properties", properties);
@@ -51,14 +54,19 @@ public class CheckstyleModuleFactory {
         <failsOnError>true</failsOnError>
         """
       )
+      .addDependency(checkstyleDependency())
       .addExecution(pluginExecution().goals("check").id("validate").phase(VALIDATE))
       .build();
   }
 
+  private JavaDependency checkstyleDependency() {
+    return javaDependency().groupId("com.puppycrawl.tools").artifactId(CHECKSTYLE).versionSlug(CHECKSTYLE).build();
+  }
+
   private GradleMainBuildPlugin checkstyleGradlePlugin() {
-    VersionSlug toolVersionSlug = new VersionSlug("checkstyle");
+    VersionSlug toolVersionSlug = new VersionSlug(CHECKSTYLE);
     return gradleCorePlugin()
-      .id("checkstyle")
+      .id(CHECKSTYLE)
       .toolVersionSlug(toolVersionSlug)
       .configuration(
         """
diff --git a/src/main/resources/generator/dependencies/build.gradle.kts b/src/main/resources/generator/dependencies/build.gradle.kts
index ba3e2cfed..4d7329a78 100644
--- a/src/main/resources/generator/dependencies/build.gradle.kts
+++ b/src/main/resources/generator/dependencies/build.gradle.kts
@@ -1,6 +1,5 @@
 plugins {
   java
-  checkstyle
   alias(libs.plugins.jib)
   alias(libs.plugins.protobuf)
   // jhipster-needle-gradle-plugin
@@ -12,10 +11,6 @@ java {
   }
 }
 
-checkstyle {
-  toolVersion = libs.versions.checkstyle.get()
-}
-
 // jhipster-needle-gradle-project-extension-plugin-configuration
 
 repositories {
@@ -29,7 +24,6 @@ version = "0.0.1-SNAPSHOT"
 // jhipster-needle-profile-activation
 
 dependencies {
-  implementation(libs.checkstyle)
   // jhipster-needle-gradle-implementation-dependencies
   // jhipster-needle-gradle-compile-dependencies
   // jhipster-needle-gradle-runtime-dependencies
diff --git a/src/main/resources/generator/dependencies/gradle/libs.versions.toml b/src/main/resources/generator/dependencies/gradle/libs.versions.toml
index 9f6579255..a0a45c239 100644
--- a/src/main/resources/generator/dependencies/gradle/libs.versions.toml
+++ b/src/main/resources/generator/dependencies/gradle/libs.versions.toml
@@ -7,12 +7,6 @@ jacoco = "0.8.11"
 sonarqube = "4.4.1.3373"
 node-gradle = "7.0.2"
 
-[libraries]
-[libraries.checkstyle]
-group = "com.puppycrawl.tools"
-name = "checkstyle"
-version.ref = "checkstyle"
-
 [plugins]
 [plugins.jib]
 id = "com.google.cloud.tools.jib"
diff --git a/src/main/resources/generator/dependencies/pom.xml b/src/main/resources/generator/dependencies/pom.xml
index 2d57ab47c..3ab51ad7d 100644
--- a/src/main/resources/generator/dependencies/pom.xml
+++ b/src/main/resources/generator/dependencies/pom.xml
@@ -56,6 +56,7 @@
     <os-maven-plugin.version>1.7.1</os-maven-plugin.version>
     <protobuf-maven-plugin.version>2.7.3</protobuf-maven-plugin.version>
     <maven-resources-plugin.version>3.3.1</maven-resources-plugin.version>
+    <checkstyle.version>10.21.0</checkstyle.version>
     <maven-checkstyle-plugin.version>3.6.0</maven-checkstyle-plugin.version>
     <git-commit-id-plugin.version>9.0.1</git-commit-id-plugin.version>
     <frontend-maven-plugin.version>1.15.1</frontend-maven-plugin.version>
@@ -422,6 +423,11 @@
         <artifactId>liquibase-linter-maven-plugin</artifactId>
         <version>${liquibase-linter-maven-plugin.version}</version>
       </dependency>
+      <dependency>
+        <groupId>com.puppycrawl.tools</groupId>
+        <artifactId>checkstyle</artifactId>
+        <version>${checkstyle.version}</version>
+      </dependency>
     </dependencies>
   </dependencyManagement>
 </project>
diff --git a/src/main/resources/generator/server/springboot/mvc/security/oauth2/account/main/infrastructure/primary/RestAccount.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/oauth2/account/main/infrastructure/primary/RestAccount.java.mustache
index f33be9f59..c0dfdacd9 100644
--- a/src/main/resources/generator/server/springboot/mvc/security/oauth2/account/main/infrastructure/primary/RestAccount.java.mustache
+++ b/src/main/resources/generator/server/springboot/mvc/security/oauth2/account/main/infrastructure/primary/RestAccount.java.mustache
@@ -52,7 +52,7 @@ final class RestAccount {
     return roles;
   }
 
-  private static class RestAccountBuilder {
+  private static final class RestAccountBuilder {
 
     private String username;
     private String name;
diff --git a/src/main/resources/generator/server/springboot/mvc/security/oauth2/core/main/infrastructure/primary/CustomClaimConverter.java.mustache b/src/main/resources/generator/server/springboot/mvc/security/oauth2/core/main/infrastructure/primary/CustomClaimConverter.java.mustache
index e04232841..2edc4da32 100644
--- a/src/main/resources/generator/server/springboot/mvc/security/oauth2/core/main/infrastructure/primary/CustomClaimConverter.java.mustache
+++ b/src/main/resources/generator/server/springboot/mvc/security/oauth2/core/main/infrastructure/primary/CustomClaimConverter.java.mustache
@@ -124,7 +124,7 @@ class CustomClaimConverter implements Converter<Map<String, Object>, Map<String,
     }
   }
 
-  private static class NameClaimAppender implements ClaimAppender {
+  private static final class NameClaimAppender implements ClaimAppender {
 
     @Override
     public void append(Map<String, Object> claim, ObjectNode user) {
@@ -140,7 +140,7 @@ class CustomClaimConverter implements Converter<Map<String, Object>, Map<String,
     }
   }
 
-  private static class GroupClaimAppender implements ClaimAppender {
+  private static final class GroupClaimAppender implements ClaimAppender {
 
     @Override
     public void append(Map<String, Object> claim, ObjectNode user) {
@@ -152,7 +152,7 @@ class CustomClaimConverter implements Converter<Map<String, Object>, Map<String,
     }
   }
 
-  private static class RolesClaimAppender implements ClaimAppender {
+  private static final class RolesClaimAppender implements ClaimAppender {
 
     @Override
     public void append(Map<String, Object> claim, ObjectNode user) {


Test patch:
diff --git a/src/test/java/tech/jhipster/lite/generator/server/javatool/checkstyle/domain/CheckstyleModuleFactoryTest.java b/src/test/java/tech/jhipster/lite/generator/server/javatool/checkstyle/domain/CheckstyleModuleFactoryTest.java
index 267fedac0..576a7a812 100644
--- a/src/test/java/tech/jhipster/lite/generator/server/javatool/checkstyle/domain/CheckstyleModuleFactoryTest.java
+++ b/src/test/java/tech/jhipster/lite/generator/server/javatool/checkstyle/domain/CheckstyleModuleFactoryTest.java
@@ -1,6 +1,9 @@
 package tech.jhipster.lite.generator.server.javatool.checkstyle.domain;
 
-import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.*;
+import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.assertThatModuleWithFiles;
+import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.gradleBuildFile;
+import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.gradleLibsVersionFile;
+import static tech.jhipster.lite.module.infrastructure.secondary.JHipsterModulesAssertions.pomFile;
 
 import org.junit.jupiter.api.Test;
 import tech.jhipster.lite.TestFileUtils;
@@ -37,6 +40,13 @@ class CheckstyleModuleFactoryTest {
                     </goals>
                   </execution>
                 </executions>
+                <dependencies>
+                  <dependency>
+                    <groupId>com.puppycrawl.tools</groupId>
+                    <artifactId>checkstyle</artifactId>
+                    <version>${checkstyle.version}</version>
+                  </dependency>
+                </dependencies>
                 <configuration>
                   <configLocation>checkstyle.xml</configLocation>
                   <includeTestSourceDirectory>true</includeTestSourceDirectory>
@@ -46,6 +56,7 @@ class CheckstyleModuleFactoryTest {
               </plugin>
         """
       )
+      .containing("<checkstyle.version>")
       .and()
       .hasFile("checkstyle.xml")
       .containing("<module name=\"IllegalImport\">")