From aac78bcbad37a0877b8d02da89006655f491cf94 Mon Sep 17 00:00:00 2001 From: Albert Tregnaghi Date: Tue, 8 Feb 2022 16:36:49 +0100 Subject: [PATCH] Introduce gradle gradle spotless for java #771 - added sechub eclipse formatter - added importer order settings --- build.gradle | 16 ++ gradle.properties | 1 + gradle/spotless.eclipseformat.xml | 390 ++++++++++++++++++++++++++++++ gradle/spotless.gradle | 17 ++ gradle/spotless.importorder | 6 + 5 files changed, 430 insertions(+) create mode 100644 gradle/spotless.eclipseformat.xml create mode 100644 gradle/spotless.gradle create mode 100644 gradle/spotless.importorder diff --git a/build.gradle b/build.gradle index aa8d108240..91d7f75f66 100644 --- a/build.gradle +++ b/build.gradle @@ -27,6 +27,7 @@ plugins { id 'org.asciidoctor.jvm.pdf' version '3.3.2' id 'org.openapi.generator' version '5.2.0' id 'org.springframework.boot' version '2.6.2' apply false + id 'com.diffplug.spotless' version '6.2.1' } /* check buildsystem */ def githubActor = System.getenv('GITHUB_ACTOR') @@ -64,6 +65,7 @@ task internalCleanRootBuildFolder(type: Delete){ tasks.clean.dependsOn.internalCleanRootBuildFolder allprojects { + apply from: rootProject.file('gradle/spotless.gradle') def customMavenRepoURL = System.getenv('CUST_MVN_URL') if (customMavenRepoURL!=null){ @@ -76,7 +78,21 @@ allprojects { } } + +} + +spotless { + groovyGradle { + target '*.gradle', 'gradle/*.gradle' + } + format 'dotfiles', { + target '.gitignore', '.gitattributes', '.editorconfig' + indentWithSpaces(2) + trimTrailingWhitespace() + endWithNewline() + } } + apply from: "${rootProject.projectDir}/build-versioning.gradle" apply from: "${rootProject.projectDir}/build-java.gradle" apply from: "${rootProject.projectDir}/build-spring.gradle" diff --git a/gradle.properties b/gradle.properties index f9649deab3..dbd0baf4ce 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,3 +4,4 @@ # ============================================================================= replacePlaceholders=true org.gradle.jvmargs=-Xmx2048m + diff --git a/gradle/spotless.eclipseformat.xml b/gradle/spotless.eclipseformat.xml new file mode 100644 index 0000000000..72506c64b2 --- /dev/null +++ b/gradle/spotless.eclipseformat.xml @@ -0,0 +1,390 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gradle/spotless.gradle b/gradle/spotless.gradle new file mode 100644 index 0000000000..124c31900e --- /dev/null +++ b/gradle/spotless.gradle @@ -0,0 +1,17 @@ +apply plugin: 'com.diffplug.spotless' +spotless { + + if (projectType.javaProjects.contains(project)){ + java { + bumpThisNumberIfACustomStepChanges(1) + // currently we do not use spotless here, but our own bash solution - but spotless would be: + //licenseHeaderFile rootProject.file('gradle/spotless.license') + importOrderFile rootProject.file('gradle/spotless.importorder') + eclipse().configFile rootProject.file('gradle/spotless.eclipseformat.xml') + trimTrailingWhitespace() + removeUnusedImports() + } + } + +} + diff --git a/gradle/spotless.importorder b/gradle/spotless.importorder new file mode 100644 index 0000000000..5dc651c731 --- /dev/null +++ b/gradle/spotless.importorder @@ -0,0 +1,6 @@ +#Organize Import Order +#Tue Feb 08 16:32:36 CET 2022 +0=java +1=javax +2=org +3=com