diff --git a/generators/app/__snapshots__/generator.spec.mts.snap b/generators/app/__snapshots__/generator.spec.mts.snap
index 1bc6f4f7da26..6490ef3d9b4c 100644
--- a/generators/app/__snapshots__/generator.spec.mts.snap
+++ b/generators/app/__snapshots__/generator.spec.mts.snap
@@ -370,6 +370,8 @@ exports[`generator - app with default config should match snapshot 1`] = `
"picocli": "'PICOCLI-VERSION'",
"properties-maven-plugin": "'PROPERTIES-MAVEN-PLUGIN-VERSION'",
"sonar-maven-plugin": "'SONAR-MAVEN-PLUGIN-VERSION'",
+ "spotless-gradle-plugin": "'SPOTLESS-GRADLE-PLUGIN-VERSION'",
+ "spotless-maven-plugin": "'SPOTLESS-MAVEN-PLUGIN-VERSION'",
"spring-boot": "'SPRING-BOOT-VERSION'",
"spring-pulsar": "'SPRING-PULSAR-VERSION'",
"typesafe": "'TYPESAFE-VERSION'",
@@ -908,6 +910,8 @@ exports[`generator - app with gateway should match snapshot 1`] = `
"picocli": "'PICOCLI-VERSION'",
"properties-maven-plugin": "'PROPERTIES-MAVEN-PLUGIN-VERSION'",
"sonar-maven-plugin": "'SONAR-MAVEN-PLUGIN-VERSION'",
+ "spotless-gradle-plugin": "'SPOTLESS-GRADLE-PLUGIN-VERSION'",
+ "spotless-maven-plugin": "'SPOTLESS-MAVEN-PLUGIN-VERSION'",
"spring-boot": "'SPRING-BOOT-VERSION'",
"spring-pulsar": "'SPRING-PULSAR-VERSION'",
"typesafe": "'TYPESAFE-VERSION'",
@@ -1445,6 +1449,8 @@ exports[`generator - app with microservice should match snapshot 1`] = `
"picocli": "'PICOCLI-VERSION'",
"properties-maven-plugin": "'PROPERTIES-MAVEN-PLUGIN-VERSION'",
"sonar-maven-plugin": "'SONAR-MAVEN-PLUGIN-VERSION'",
+ "spotless-gradle-plugin": "'SPOTLESS-GRADLE-PLUGIN-VERSION'",
+ "spotless-maven-plugin": "'SPOTLESS-MAVEN-PLUGIN-VERSION'",
"spring-boot": "'SPRING-BOOT-VERSION'",
"spring-pulsar": "'SPRING-PULSAR-VERSION'",
"typesafe": "'TYPESAFE-VERSION'",
diff --git a/generators/server/resources/gradle/libs.versions.toml b/generators/server/resources/gradle/libs.versions.toml
index 7077ce3a1034..88d46b7ea9f2 100644
--- a/generators/server/resources/gradle/libs.versions.toml
+++ b/generators/server/resources/gradle/libs.versions.toml
@@ -7,6 +7,8 @@ gradle-liquibase = { id = 'org.liquibase.gradle', version = '2.2.0' }
gradle-sonarqube = { id = 'org.sonarqube', version = '4.2.1.3168' }
+spotless-gradle-plugin = { id = 'com.diffplug.spotless', version = '6.19.0' }
+
gradle-modernizer-plugin = { id = 'com.github.andygoossens.gradle-modernizer-plugin', version = '1.8.0' }
gradle-enterprise = { id = 'com.gradle.enterprise', version = '3.13.4' }
diff --git a/generators/server/resources/pom.xml b/generators/server/resources/pom.xml
index 09e8bf753c70..f618f17d8ccd 100644
--- a/generators/server/resources/pom.xml
+++ b/generators/server/resources/pom.xml
@@ -54,6 +54,7 @@
6.6.0
1.1.0
3.9.1.2184
+ 2.37.0
@@ -283,6 +284,11 @@
sonar-maven-plugin
${sonar-maven-plugin.version}
+
+ com.diffplug.spotless
+ spotless-maven-plugin
+ ${spotless-maven-plugin.version}
+
diff --git a/generators/server/templates/build.gradle.ejs b/generators/server/templates/build.gradle.ejs
index ebc057cc8b09..6164055f427e 100644
--- a/generators/server/templates/build.gradle.ejs
+++ b/generators/server/templates/build.gradle.ejs
@@ -32,6 +32,7 @@ plugins {
id "com.github.node-gradle.node"
<%_ } _%>
id "org.sonarqube"
+ id "com.diffplug.spotless"
id "io.spring.nohttp"
id "com.github.andygoossens.gradle-modernizer-plugin"
<%_ if (gatlingTests) { _%>
@@ -61,6 +62,13 @@ ext {
apply from: "gradle/docker.gradle"
apply from: "gradle/sonar.gradle"
+
+spotless {
+ java {
+ removeUnusedImports()
+ }
+}
+
<%_ if (enableSwaggerCodegen) { _%>
apply from: "gradle/swagger.gradle"
<%_ } _%>
diff --git a/generators/server/templates/gradle.properties.ejs b/generators/server/templates/gradle.properties.ejs
index 5d44f7cd82ac..f39df9698eee 100644
--- a/generators/server/templates/gradle.properties.ejs
+++ b/generators/server/templates/gradle.properties.ejs
@@ -70,6 +70,7 @@ gitPropertiesPluginVersion=<%- javaDependencies['gradle-git-properties'] %>
gradleNodePluginVersion=<%- javaDependencies['node-gradle'] %>
<%_ } _%>
sonarqubePluginVersion=<%- javaDependencies['gradle-sonarqube'] %>
+spotlessPluginVersion=<%- javaDependencies['spotless-gradle-plugin'] %>
<%_ if (enableSwaggerCodegen) { _%>
openapiPluginVersion=<%- javaDependencies['openapi-generator-maven-plugin'] %>
<%_ } _%>
diff --git a/generators/server/templates/npmw b/generators/server/templates/npmw
index 12a91e52a611..ed50b5686f01 100755
--- a/generators/server/templates/npmw
+++ b/generators/server/templates/npmw
@@ -5,6 +5,7 @@ basedir=`dirname "$0"`
if [ -f "$basedir/mvnw" ]; then
bindir="$basedir/target/node"
repodir="$basedir/target/node/node_modules"
+ spotlessApplyCommand="$basedir/mvnw process-sources"
installCommand="$basedir/mvnw -Pwebapp frontend:install-node-and-npm@install-node-and-npm"
PATH="$basedir/$builddir/:$PATH"
@@ -13,6 +14,7 @@ if [ -f "$basedir/mvnw" ]; then
elif [ -f "$basedir/gradlew" ]; then
bindir="$basedir/build/node/bin"
repodir="$basedir/build/node/lib/node_modules"
+ spotlessApplyCommand="$basedir/gradlew spotlessApply"
installCommand="$basedir/gradlew npmSetup"
else
echo "Using npm installed globally"
@@ -22,6 +24,10 @@ fi
NPM_EXE="$repodir/npm/bin/npm-cli.js"
NODE_EXE="$bindir/node"
+if [ ! -z "$spotlessApplyCommand" ]; then
+ $spotlessApplyCommand || true
+fi
+
if [ ! -x "$NPM_EXE" ] || [ ! -x "$NODE_EXE" ]; then
$installCommand || true
fi
diff --git a/generators/server/templates/npmw.cmd b/generators/server/templates/npmw.cmd
index b6e798095812..22fc4683a6c0 100644
--- a/generators/server/templates/npmw.cmd
+++ b/generators/server/templates/npmw.cmd
@@ -8,14 +8,20 @@ if exist "%NPMW_DIR%mvnw.cmd" (
set NODE_EXE=^"^"
set NODE_PATH=%NPMW_DIR%target\node\
set NPM_EXE=^"%NPMW_DIR%target\node\npm.cmd^"
+ set SPOTLESS_APPLY_COMMAND=^"%NPMW_DIR%mvnw.cmd^" process-sources
set INSTALL_NPM_COMMAND=^"%NPMW_DIR%mvnw.cmd^" -Pwebapp frontend:install-node-and-npm@install-node-and-npm
) else (
set NODE_EXE=^"%NPMW_DIR%build\node\bin\node.exe^"
set NODE_PATH=%NPMW_DIR%build\node\bin\
set NPM_EXE=^"%NPMW_DIR%build\node\lib\node_modules\npm\bin\npm-cli.js^"
+ set SPOTLESS_APPLY_COMMAND=^"%NPMW_DIR%gradlew.bat^" spotlessApply
set INSTALL_NPM_COMMAND=^"%NPMW_DIR%gradlew.bat^" npmSetup
)
+if exist %SPOTLESS_APPLY_COMMAND% (
+ call %SPOTLESS_APPLY_COMMAND%
+)
+
if not exist %NPM_EXE% (
call %INSTALL_NPM_COMMAND%
)
diff --git a/generators/server/templates/pom.xml.ejs b/generators/server/templates/pom.xml.ejs
index a93061f925c6..2d4b65ed4f52 100644
--- a/generators/server/templates/pom.xml.ejs
+++ b/generators/server/templates/pom.xml.ejs
@@ -101,6 +101,7 @@
<%_ } _%>
<%- javaDependencies['properties-maven-plugin'] %>
<%- javaDependencies['sonar-maven-plugin'] %>
+ <%- javaDependencies['spotless-maven-plugin'] %>
@@ -406,6 +407,10 @@
org.sonarsource.scanner.maven
sonar-maven-plugin
+
+ com.diffplug.spotless
+ spotless-maven-plugin
+
org.springframework.boot
spring-boot-maven-plugin
@@ -845,6 +850,25 @@
sonar-maven-plugin
${sonar-maven-plugin.version}
+
+ com.diffplug.spotless
+ spotless-maven-plugin
+ ${spotless-maven-plugin.version}
+
+
+
+
+
+
+
+ spotless
+ process-sources
+
+ apply
+
+
+
+
org.springframework.boot
spring-boot-maven-plugin
diff --git a/generators/server/templates/settings.gradle.ejs b/generators/server/templates/settings.gradle.ejs
index f91c0f1ea1ad..d90ddb86b89d 100644
--- a/generators/server/templates/settings.gradle.ejs
+++ b/generators/server/templates/settings.gradle.ejs
@@ -37,6 +37,7 @@ pluginManagement {
id 'com.github.node-gradle.node' version "${gradleNodePluginVersion}"
<%_ } _%>
id 'org.sonarqube' version "${sonarqubePluginVersion}"
+ id 'com.diffplug.spotless' version "${spotlessPluginVersion}"
id "io.spring.nohttp" version "${noHttpCheckstyleVersion}"
id 'com.github.andygoossens.gradle-modernizer-plugin' version "${modernizerPluginVersion}"
<%_ if (enableGradleEnterprise) { _%>