11package com .formkiq .gradle ;
22
33import com .diffplug .gradle .spotless .SpotlessExtension ;
4+ import com .diffplug .spotless .extra .wtp .EclipseWtpFormatterStep ;
45import com .github .spotbugs .snom .SpotBugsExtension ;
56import org .gradle .api .Plugin ;
67import org .gradle .api .Project ;
@@ -20,6 +21,8 @@ public class JavaBasePlugin implements Plugin<Project> {
2021
2122 /** Checkstyle Version. */
2223 private static final String CHECKSTYLE_TOOL_VERSION = "10.12.4" ;
24+ /** Java version. */
25+ private static final int JAVA_VERSION = 17 ;
2326
2427 @ Override
2528 public void apply (Project root ) {
@@ -39,16 +42,18 @@ public void apply(Project root) {
3942 // Repositories
4043 p .getRepositories ().mavenLocal ();
4144 p .getRepositories ().mavenCentral ();
42- p .getRepositories ().maven (repo -> repo .setUrl ("https://central.sonatype.com/repository/maven-snapshots/" ));
45+ p .getRepositories ()
46+ .maven (repo -> repo .setUrl ("https://central.sonatype.com/repository/maven-snapshots/" ));
4347
4448 // Java toolchain 17
4549 JavaPluginExtension java = p .getExtensions ().getByType (JavaPluginExtension .class );
46- java .getToolchain ().getLanguageVersion ().set (JavaLanguageVersion .of (17 ));
50+ java .getToolchain ().getLanguageVersion ().set (JavaLanguageVersion .of (JAVA_VERSION ));
4751
4852 // Spotless
4953 p .getExtensions ().configure (SpotlessExtension .class , (SpotlessExtension s ) -> {
5054 s .java (j -> {
51- j .eclipse ().sortMembersEnabled (true ).configFile (p .getRootProject ().file ("spotless.eclipseformat.xml" ));
55+ j .eclipse ().sortMembersEnabled (true )
56+ .configFile (p .getRootProject ().file ("spotless.eclipseformat.xml" ));
5257 j .removeUnusedImports ();
5358 j .removeWildcardImports ();
5459 j .licenseHeaderFile (p .getRootProject ().file ("LICENSE" ));
@@ -60,12 +65,22 @@ public void apply(Project root) {
6065 g .trimTrailingWhitespace ();
6166 g .endWithNewline ();
6267 });
68+ s .json (j -> {
69+ j .target ("*.json" , "**/*.json" );
70+ j .prettier ();
71+ });
72+
73+ s .format ("xml" , f -> {
74+ f .target ("*.xml" , "**/*.xml" );
75+ f .eclipseWtp (EclipseWtpFormatterStep .XML );
76+ f .trimTrailingWhitespace ();
77+ f .endWithNewline ();
78+ });
6379 });
6480
6581 // SpotBugs
66- p .getExtensions ().configure (SpotBugsExtension .class , sb ->
67- sb .getExcludeFilter ().set (p .file (p .getRootDir () + "/config/gradle/spotbugs-exclude.xml" ))
68- );
82+ p .getExtensions ().configure (SpotBugsExtension .class , sb -> sb .getExcludeFilter ()
83+ .set (p .file (p .getRootDir () + "/config/gradle/spotbugs-exclude.xml" )));
6984
7085 p .getTasks ().withType (com .github .spotbugs .snom .SpotBugsTask .class ).configureEach (t -> {
7186 if (t .getReports ().findByName ("html" ) == null ) {
@@ -90,9 +105,8 @@ public void apply(Project root) {
90105 });
91106
92107 // Compiler flags
93- p .getTasks ().withType (JavaCompile .class ).configureEach (jc ->
94- jc .getOptions ().getCompilerArgs ().add ("-Xlint:deprecation" )
95- );
108+ p .getTasks ().withType (JavaCompile .class )
109+ .configureEach (jc -> jc .getOptions ().getCompilerArgs ().add ("-Xlint:deprecation" ));
96110
97111 // Tests
98112 p .getTasks ().withType (Test .class ).configureEach (t -> {
0 commit comments