From 887c4f5fde84158ac72a133839a905d5ee7c29e3 Mon Sep 17 00:00:00 2001 From: Matyrobbrt Date: Thu, 14 Dec 2023 19:50:54 +0200 Subject: [PATCH 01/13] Optional spotless support --- build.gradle | 19 +- .../gradleutils/GradleUtilsPlugin.groovy | 4 + .../ExtractSpotlessConfiguration.groovy | 54 +++ .../spotless/SpotlessUtilsExtension.groovy | 62 +++ src/main/resources/formatter-config.xml | 401 ++++++++++++++++++ 5 files changed, 537 insertions(+), 3 deletions(-) create mode 100644 src/main/groovy/net/neoforged/gradleutils/spotless/ExtractSpotlessConfiguration.groovy create mode 100644 src/main/groovy/net/neoforged/gradleutils/spotless/SpotlessUtilsExtension.groovy create mode 100644 src/main/resources/formatter-config.xml diff --git a/build.gradle b/build.gradle index 35a5d8d..e374665 100644 --- a/build.gradle +++ b/build.gradle @@ -14,11 +14,21 @@ java { } group 'net.neoforged.gradleutils' -version '3.0.0-alpha.7' +version '3.0.0-alpha.7-spotless' repositories { - mavenCentral() - gradlePluginPortal() + mavenCentral { + content { + excludeGroup('com.diffplug.spotless') + } + } + gradlePluginPortal { + metadataSources { + // Spotless requires J11, so ignore the Gradle metadata as otherwise the dependency wouldn't be resolved + ignoreGradleMetadataRedirection() + mavenPom() + } + } } if (System.getenv('GPP_KEY')) { @@ -35,6 +45,8 @@ dependencies { api "net.neoforged:groovydslimprover:${gdi_version}" api "net.neoforged:groovydslimprover:${gdi_version}:base" api "net.neoforged:groovydslimprover:${gdi_version}:runtime" + + compileOnly 'com.diffplug.spotless:spotless-plugin-gradle:6.23.3' } sourceSets { @@ -54,6 +66,7 @@ tasks.named(sourceSets.main.processResourcesTaskName, Copy) { license { header(file('HEADER')) skipExistingHeaders = true // Ignore existing license headers on files + exclude 'formatter-config.xml' } // Disable the license tasks for the template files diff --git a/src/main/groovy/net/neoforged/gradleutils/GradleUtilsPlugin.groovy b/src/main/groovy/net/neoforged/gradleutils/GradleUtilsPlugin.groovy index 28b96c6..97a59e3 100644 --- a/src/main/groovy/net/neoforged/gradleutils/GradleUtilsPlugin.groovy +++ b/src/main/groovy/net/neoforged/gradleutils/GradleUtilsPlugin.groovy @@ -37,5 +37,9 @@ class GradleUtilsPlugin implements Plugin { //Setup the CI project task. project.tasks.register("setupGitHubActionsWorkflows", ExtractActionsWorkflowsTask.class) GradleUtils.setupCITasks(project) + + if (project.plugins.hasPlugin('com.diffplug.spotless')) { + project.extensions.create('spotlessUtils', Class.forName('net.neoforged.gradleutils.spotless.SpotlessUtilsExtension'), project) + } } } diff --git a/src/main/groovy/net/neoforged/gradleutils/spotless/ExtractSpotlessConfiguration.groovy b/src/main/groovy/net/neoforged/gradleutils/spotless/ExtractSpotlessConfiguration.groovy new file mode 100644 index 0000000..c6c9735 --- /dev/null +++ b/src/main/groovy/net/neoforged/gradleutils/spotless/ExtractSpotlessConfiguration.groovy @@ -0,0 +1,54 @@ +/* + * Copyright (c) NeoForged and contributors + * SPDX-License-Identifier: LGPL-2.1-only + */ + +package net.neoforged.gradleutils.spotless + +import groovy.transform.CompileStatic +import org.gradle.api.DefaultTask +import org.gradle.api.file.RegularFileProperty +import org.gradle.api.provider.Property +import org.gradle.api.tasks.Input +import org.gradle.api.tasks.OutputFile +import org.gradle.api.tasks.TaskAction +import org.gradle.work.DisableCachingByDefault + +import java.nio.file.Files +import java.nio.file.Paths + +@CompileStatic +@DisableCachingByDefault(because = 'configuration contained inside the jar may change') +abstract class ExtractSpotlessConfiguration extends DefaultTask { + @Input + abstract Property getTargetConfiguration() + + @OutputFile + abstract RegularFileProperty getOutput() + + ExtractSpotlessConfiguration() { + // configuration contained inside the jar may change + outputs.upToDateWhen { + false + } + } + + @TaskAction + void run() { + final output = this.getOutput().get().asFile.toPath() + if (Files.notExists(output)) { + Files.createDirectories(output.parent) + } + + try ( + final input = SpotlessUtilsExtension.getResourceAsStream('/formatter-config.xml'); + final out = Files.newOutputStream(output) + ) { + byte[] buffer = new byte[1024] + int len + while ((len = input.read(buffer)) > 0) { + out.write(buffer, 0, len) + } + } + } +} diff --git a/src/main/groovy/net/neoforged/gradleutils/spotless/SpotlessUtilsExtension.groovy b/src/main/groovy/net/neoforged/gradleutils/spotless/SpotlessUtilsExtension.groovy new file mode 100644 index 0000000..2b5b0f2 --- /dev/null +++ b/src/main/groovy/net/neoforged/gradleutils/spotless/SpotlessUtilsExtension.groovy @@ -0,0 +1,62 @@ +/* + * Copyright (c) NeoForged and contributors + * SPDX-License-Identifier: LGPL-2.1-only + */ + +package net.neoforged.gradleutils.spotless + +import com.diffplug.gradle.spotless.JavaExtension +import com.diffplug.gradle.spotless.SpotlessExtension +import com.diffplug.gradle.spotless.SpotlessTask +import groovy.transform.CompileStatic +import org.gradle.api.Project + +import javax.inject.Inject +import java.nio.file.Files + +@CompileStatic +abstract class SpotlessUtilsExtension { + final File configPath + + @Inject + SpotlessUtilsExtension(Project project) { + configPath = new File(project.rootDir, '.gradle/formatter-config.xml') + + if (!configPath.exists()) { + Files.createDirectories(configPath.toPath().parent) + + try ( + final input = SpotlessUtilsExtension.getResourceAsStream('/formatter-config.xml'); + final output = Files.newOutputStream(configPath.toPath()) + ) { + byte[] buffer = new byte[1024]; + int len + while ((len = input.read(buffer)) > 0) { + output.write(buffer, 0, len) + } + } + } + + final extract = project.tasks.register('extraGUSpotlessConfiguration', ExtractSpotlessConfiguration) { + it.output.set(configPath) + it.targetConfiguration.set(SpotlessUtilsExtension.getResource('/formatter-config.xml')) + } + + project.tasks.withType(SpotlessTask).configureEach { + it.dependsOn(extract) + } + } + + void configure(SpotlessExtension ext) { + ext.java(this.&configure) + } + + void configure(JavaExtension ext) { + ext.endWithNewline() + ext.indentWithSpaces() + ext.removeUnusedImports() + ext.toggleOffOn() + ext.eclipse().configFile(configPath) + ext.importOrder() + } +} diff --git a/src/main/resources/formatter-config.xml b/src/main/resources/formatter-config.xml new file mode 100644 index 0000000..c6e4aa6 --- /dev/null +++ b/src/main/resources/formatter-config.xml @@ -0,0 +1,401 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 387cd258f8b3fd8aa8a6b763ea1d941d4c82819c Mon Sep 17 00:00:00 2001 From: Matyrobbrt Date: Thu, 14 Dec 2023 19:56:57 +0200 Subject: [PATCH 02/13] Update config --- build.gradle | 13 +++++++------ src/main/resources/formatter-config.xml | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/build.gradle b/build.gradle index e374665..9f48b06 100644 --- a/build.gradle +++ b/build.gradle @@ -22,12 +22,13 @@ repositories { excludeGroup('com.diffplug.spotless') } } - gradlePluginPortal { - metadataSources { - // Spotless requires J11, so ignore the Gradle metadata as otherwise the dependency wouldn't be resolved - ignoreGradleMetadataRedirection() - mavenPom() - } + gradlePluginPortal() +} + +// Spotless runs on J11 +configurations { + compileClasspath { + attributes.attribute Attribute.of('org.gradle.jvm.version', Integer), 11 } } diff --git a/src/main/resources/formatter-config.xml b/src/main/resources/formatter-config.xml index c6e4aa6..f097461 100644 --- a/src/main/resources/formatter-config.xml +++ b/src/main/resources/formatter-config.xml @@ -13,7 +13,7 @@ - + @@ -398,4 +398,4 @@ - + \ No newline at end of file From afdb9025ae4e59baa36c64adc2e2c17cda058e11 Mon Sep 17 00:00:00 2001 From: Matyrobbrt Date: Thu, 25 Jan 2024 10:54:56 +0200 Subject: [PATCH 03/13] Separate spotless stuff into its own plugin --- build.gradle | 7 +++++++ .../gradleutils/GradleUtilsPlugin.groovy | 4 ---- .../gradleutils/spotless/SpotlessPlugin.groovy | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 src/main/groovy/net/neoforged/gradleutils/spotless/SpotlessPlugin.groovy diff --git a/build.gradle b/build.gradle index c6d1605..0016a14 100644 --- a/build.gradle +++ b/build.gradle @@ -108,6 +108,13 @@ gradlePlugin { tags.set(['versioning', 'changelog']) implementationClass = 'net.neoforged.gradleutils.GradleUtilsPlugin' } + gradleutilsSpotless { + id = 'net.neoforged.gradleutils.spotless' + displayName = 'GradleUtils Spotless' + description = 'A plugin that configures spotless on projects' + tags.set(['spotless']) + implementationClass = 'net.neoforged.gradleutils.spotless.SpotlessPlugin' + } } } diff --git a/src/main/groovy/net/neoforged/gradleutils/GradleUtilsPlugin.groovy b/src/main/groovy/net/neoforged/gradleutils/GradleUtilsPlugin.groovy index 97a59e3..28b96c6 100644 --- a/src/main/groovy/net/neoforged/gradleutils/GradleUtilsPlugin.groovy +++ b/src/main/groovy/net/neoforged/gradleutils/GradleUtilsPlugin.groovy @@ -37,9 +37,5 @@ class GradleUtilsPlugin implements Plugin { //Setup the CI project task. project.tasks.register("setupGitHubActionsWorkflows", ExtractActionsWorkflowsTask.class) GradleUtils.setupCITasks(project) - - if (project.plugins.hasPlugin('com.diffplug.spotless')) { - project.extensions.create('spotlessUtils', Class.forName('net.neoforged.gradleutils.spotless.SpotlessUtilsExtension'), project) - } } } diff --git a/src/main/groovy/net/neoforged/gradleutils/spotless/SpotlessPlugin.groovy b/src/main/groovy/net/neoforged/gradleutils/spotless/SpotlessPlugin.groovy new file mode 100644 index 0000000..4b9fecc --- /dev/null +++ b/src/main/groovy/net/neoforged/gradleutils/spotless/SpotlessPlugin.groovy @@ -0,0 +1,18 @@ +/* + * Copyright (c) NeoForged and contributors + * SPDX-License-Identifier: LGPL-2.1-only + */ + +package net.neoforged.gradleutils.spotless + +import groovy.transform.CompileStatic +import org.gradle.api.Plugin +import org.gradle.api.Project + +@CompileStatic +class SpotlessPlugin implements Plugin { + @Override + void apply(Project project) { + project.extensions.create('spotlessUtils', SpotlessUtilsExtension, project) + } +} From 46034f6fa645001859c99f0b776973d21b50442f Mon Sep 17 00:00:00 2001 From: Matyrobbrt Date: Thu, 25 Jan 2024 10:58:19 +0200 Subject: [PATCH 04/13] Remove unneeded property --- .../spotless/ExtractSpotlessConfiguration.groovy | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main/groovy/net/neoforged/gradleutils/spotless/ExtractSpotlessConfiguration.groovy b/src/main/groovy/net/neoforged/gradleutils/spotless/ExtractSpotlessConfiguration.groovy index c6c9735..8101084 100644 --- a/src/main/groovy/net/neoforged/gradleutils/spotless/ExtractSpotlessConfiguration.groovy +++ b/src/main/groovy/net/neoforged/gradleutils/spotless/ExtractSpotlessConfiguration.groovy @@ -8,21 +8,15 @@ package net.neoforged.gradleutils.spotless import groovy.transform.CompileStatic import org.gradle.api.DefaultTask import org.gradle.api.file.RegularFileProperty -import org.gradle.api.provider.Property -import org.gradle.api.tasks.Input import org.gradle.api.tasks.OutputFile import org.gradle.api.tasks.TaskAction import org.gradle.work.DisableCachingByDefault import java.nio.file.Files -import java.nio.file.Paths @CompileStatic @DisableCachingByDefault(because = 'configuration contained inside the jar may change') abstract class ExtractSpotlessConfiguration extends DefaultTask { - @Input - abstract Property getTargetConfiguration() - @OutputFile abstract RegularFileProperty getOutput() From 4859a0dbca8e6961ddc2b53df4adbc82fcf36ea4 Mon Sep 17 00:00:00 2001 From: Matyrobbrt Date: Thu, 25 Jan 2024 11:00:04 +0200 Subject: [PATCH 05/13] Bump version --- build.gradle | 2 +- .../gradleutils/spotless/SpotlessUtilsExtension.groovy | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 0016a14..c28b7d5 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ java { } group 'net.neoforged.gradleutils' -version '3.0.0-alpha.10' +version '3.0.0-alpha.11' repositories { mavenCentral { diff --git a/src/main/groovy/net/neoforged/gradleutils/spotless/SpotlessUtilsExtension.groovy b/src/main/groovy/net/neoforged/gradleutils/spotless/SpotlessUtilsExtension.groovy index 2b5b0f2..c96c7c9 100644 --- a/src/main/groovy/net/neoforged/gradleutils/spotless/SpotlessUtilsExtension.groovy +++ b/src/main/groovy/net/neoforged/gradleutils/spotless/SpotlessUtilsExtension.groovy @@ -39,7 +39,6 @@ abstract class SpotlessUtilsExtension { final extract = project.tasks.register('extraGUSpotlessConfiguration', ExtractSpotlessConfiguration) { it.output.set(configPath) - it.targetConfiguration.set(SpotlessUtilsExtension.getResource('/formatter-config.xml')) } project.tasks.withType(SpotlessTask).configureEach { From cd7b3def7050080e97ac6708708ac19c22efeb74 Mon Sep 17 00:00:00 2001 From: Matyrobbrt Date: Fri, 9 Feb 2024 17:14:26 +0200 Subject: [PATCH 06/13] Review comments --- build.gradle | 34 +++++++++++++------ .../ExtractSpotlessConfiguration.groovy | 6 +--- .../spotless/SpotlessPlugin.groovy | 0 .../spotless/SpotlessUtilsExtension.groovy | 6 +--- 4 files changed, 26 insertions(+), 20 deletions(-) rename src/{main => spotless}/groovy/net/neoforged/gradleutils/spotless/ExtractSpotlessConfiguration.groovy (87%) rename src/{main => spotless}/groovy/net/neoforged/gradleutils/spotless/SpotlessPlugin.groovy (100%) rename src/{main => spotless}/groovy/net/neoforged/gradleutils/spotless/SpotlessUtilsExtension.groovy (88%) diff --git a/build.gradle b/build.gradle index c28b7d5..b7b6ce9 100644 --- a/build.gradle +++ b/build.gradle @@ -13,22 +13,27 @@ java { withSourcesJar() } +sourceSets { + spotless +} + group 'net.neoforged.gradleutils' version '3.0.0-alpha.11' repositories { - mavenCentral { - content { - excludeGroup('com.diffplug.spotless') - } - } + mavenCentral() gradlePluginPortal() } // Spotless runs on J11 -configurations { - compileClasspath { - attributes.attribute Attribute.of('org.gradle.jvm.version', Integer), 11 +tasks.named('compileSpotlessJava', JavaCompile).configure { + javaCompiler = javaToolchains.compilerFor { + languageVersion = JavaLanguageVersion.of(11) + } +} +tasks.named('compileSpotlessGroovy', GroovyCompile).configure { + javaLauncher = javaToolchains.launcherFor { + languageVersion = JavaLanguageVersion.of(11) } } @@ -39,6 +44,10 @@ if (System.getenv('GPP_KEY')) { } } +configurations { + spotlessImplementation.extendsFrom(api) +} + dependencies { api 'org.eclipse.jgit:org.eclipse.jgit:5.10.0.202012080955-r' api 'io.github.gradle-nexus:publish-plugin:1.3.0' @@ -47,7 +56,8 @@ dependencies { api "net.neoforged:groovydslimprover:${gdi_version}:base" api "net.neoforged:groovydslimprover:${gdi_version}:runtime" - compileOnly 'com.diffplug.spotless:spotless-plugin-gradle:6.23.3' + spotlessImplementation(gradleApi()) + spotlessImplementation 'com.diffplug.spotless:spotless-plugin-gradle:6.23.3' } sourceSets { @@ -111,7 +121,7 @@ gradlePlugin { gradleutilsSpotless { id = 'net.neoforged.gradleutils.spotless' displayName = 'GradleUtils Spotless' - description = 'A plugin that configures spotless on projects' + description = 'A plugin that configures Spotless on projects' tags.set(['spotless']) implementationClass = 'net.neoforged.gradleutils.spotless.SpotlessPlugin' } @@ -123,6 +133,10 @@ final changelogTask = tasks.register('changelog', GenerateChangelogTask) { it.changelogFile.set(layout.buildDirectory.file('changelog.txt')) } +tasks.named('jar', Jar) { + from(sourceSets.spotless.output) +} + tasks.named('assemble') { it.dependsOn changelogTask } diff --git a/src/main/groovy/net/neoforged/gradleutils/spotless/ExtractSpotlessConfiguration.groovy b/src/spotless/groovy/net/neoforged/gradleutils/spotless/ExtractSpotlessConfiguration.groovy similarity index 87% rename from src/main/groovy/net/neoforged/gradleutils/spotless/ExtractSpotlessConfiguration.groovy rename to src/spotless/groovy/net/neoforged/gradleutils/spotless/ExtractSpotlessConfiguration.groovy index 8101084..cd7cfbe 100644 --- a/src/main/groovy/net/neoforged/gradleutils/spotless/ExtractSpotlessConfiguration.groovy +++ b/src/spotless/groovy/net/neoforged/gradleutils/spotless/ExtractSpotlessConfiguration.groovy @@ -38,11 +38,7 @@ abstract class ExtractSpotlessConfiguration extends DefaultTask { final input = SpotlessUtilsExtension.getResourceAsStream('/formatter-config.xml'); final out = Files.newOutputStream(output) ) { - byte[] buffer = new byte[1024] - int len - while ((len = input.read(buffer)) > 0) { - out.write(buffer, 0, len) - } + input.transferTo(out) } } } diff --git a/src/main/groovy/net/neoforged/gradleutils/spotless/SpotlessPlugin.groovy b/src/spotless/groovy/net/neoforged/gradleutils/spotless/SpotlessPlugin.groovy similarity index 100% rename from src/main/groovy/net/neoforged/gradleutils/spotless/SpotlessPlugin.groovy rename to src/spotless/groovy/net/neoforged/gradleutils/spotless/SpotlessPlugin.groovy diff --git a/src/main/groovy/net/neoforged/gradleutils/spotless/SpotlessUtilsExtension.groovy b/src/spotless/groovy/net/neoforged/gradleutils/spotless/SpotlessUtilsExtension.groovy similarity index 88% rename from src/main/groovy/net/neoforged/gradleutils/spotless/SpotlessUtilsExtension.groovy rename to src/spotless/groovy/net/neoforged/gradleutils/spotless/SpotlessUtilsExtension.groovy index c96c7c9..3c0d7e0 100644 --- a/src/main/groovy/net/neoforged/gradleutils/spotless/SpotlessUtilsExtension.groovy +++ b/src/spotless/groovy/net/neoforged/gradleutils/spotless/SpotlessUtilsExtension.groovy @@ -29,11 +29,7 @@ abstract class SpotlessUtilsExtension { final input = SpotlessUtilsExtension.getResourceAsStream('/formatter-config.xml'); final output = Files.newOutputStream(configPath.toPath()) ) { - byte[] buffer = new byte[1024]; - int len - while ((len = input.read(buffer)) > 0) { - output.write(buffer, 0, len) - } + input.transferTo(output) } } From 42e2418badc87749e4d490ae81e72ef24384a194 Mon Sep 17 00:00:00 2001 From: Matyrobbrt Date: Fri, 9 Feb 2024 17:39:53 +0200 Subject: [PATCH 07/13] Use `withPlugin` --- .../net/neoforged/gradleutils/spotless/SpotlessPlugin.groovy | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/spotless/groovy/net/neoforged/gradleutils/spotless/SpotlessPlugin.groovy b/src/spotless/groovy/net/neoforged/gradleutils/spotless/SpotlessPlugin.groovy index 4b9fecc..e2c2309 100644 --- a/src/spotless/groovy/net/neoforged/gradleutils/spotless/SpotlessPlugin.groovy +++ b/src/spotless/groovy/net/neoforged/gradleutils/spotless/SpotlessPlugin.groovy @@ -13,6 +13,8 @@ import org.gradle.api.Project class SpotlessPlugin implements Plugin { @Override void apply(Project project) { - project.extensions.create('spotlessUtils', SpotlessUtilsExtension, project) + project.pluginManager.withPlugin('com.diffplug.spotless') { + project.extensions.create('spotlessUtils', SpotlessUtilsExtension, project) + } } } From 542d1bf013b970adc8001d2fe665b8ee73581704 Mon Sep 17 00:00:00 2001 From: Matyrobbrt Date: Fri, 9 Feb 2024 17:46:23 +0200 Subject: [PATCH 08/13] More complaining --- .../spotless/SpotlessUtilsExtension.groovy | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/spotless/groovy/net/neoforged/gradleutils/spotless/SpotlessUtilsExtension.groovy b/src/spotless/groovy/net/neoforged/gradleutils/spotless/SpotlessUtilsExtension.groovy index 3c0d7e0..b1582f6 100644 --- a/src/spotless/groovy/net/neoforged/gradleutils/spotless/SpotlessUtilsExtension.groovy +++ b/src/spotless/groovy/net/neoforged/gradleutils/spotless/SpotlessUtilsExtension.groovy @@ -22,17 +22,6 @@ abstract class SpotlessUtilsExtension { SpotlessUtilsExtension(Project project) { configPath = new File(project.rootDir, '.gradle/formatter-config.xml') - if (!configPath.exists()) { - Files.createDirectories(configPath.toPath().parent) - - try ( - final input = SpotlessUtilsExtension.getResourceAsStream('/formatter-config.xml'); - final output = Files.newOutputStream(configPath.toPath()) - ) { - input.transferTo(output) - } - } - final extract = project.tasks.register('extraGUSpotlessConfiguration', ExtractSpotlessConfiguration) { it.output.set(configPath) } @@ -47,6 +36,18 @@ abstract class SpotlessUtilsExtension { } void configure(JavaExtension ext) { + // Spotless requires the config file to exist during configuration + if (!configPath.exists()) { + Files.createDirectories(configPath.toPath().parent) + + try ( + final input = SpotlessUtilsExtension.getResourceAsStream('/formatter-config.xml'); + final output = Files.newOutputStream(configPath.toPath()) + ) { + input.transferTo(output) + } + } + ext.endWithNewline() ext.indentWithSpaces() ext.removeUnusedImports() From 2a5cd3cd3eeec90182252442ca82b9b905891bea Mon Sep 17 00:00:00 2001 From: Matyrobbrt <65940752+Matyrobbrt@users.noreply.github.com> Date: Fri, 9 Feb 2024 18:14:01 +0200 Subject: [PATCH 09/13] Update task name --- .../gradleutils/spotless/SpotlessUtilsExtension.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spotless/groovy/net/neoforged/gradleutils/spotless/SpotlessUtilsExtension.groovy b/src/spotless/groovy/net/neoforged/gradleutils/spotless/SpotlessUtilsExtension.groovy index b1582f6..005ec29 100644 --- a/src/spotless/groovy/net/neoforged/gradleutils/spotless/SpotlessUtilsExtension.groovy +++ b/src/spotless/groovy/net/neoforged/gradleutils/spotless/SpotlessUtilsExtension.groovy @@ -22,7 +22,7 @@ abstract class SpotlessUtilsExtension { SpotlessUtilsExtension(Project project) { configPath = new File(project.rootDir, '.gradle/formatter-config.xml') - final extract = project.tasks.register('extraGUSpotlessConfiguration', ExtractSpotlessConfiguration) { + final extract = project.tasks.register('extractGUSpotlessConfiguration', ExtractSpotlessConfiguration) { it.output.set(configPath) } From 126471eefa8739c3f88fc07cc0b954edb2519879 Mon Sep 17 00:00:00 2001 From: Matyrobbrt Date: Fri, 9 Feb 2024 18:33:27 +0200 Subject: [PATCH 10/13] Update formatter config --- src/main/resources/formatter-config.xml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/resources/formatter-config.xml b/src/main/resources/formatter-config.xml index f097461..8632531 100644 --- a/src/main/resources/formatter-config.xml +++ b/src/main/resources/formatter-config.xml @@ -1,6 +1,6 @@ - + @@ -57,7 +57,7 @@ - + @@ -99,7 +99,7 @@ - + @@ -224,7 +224,7 @@ - + @@ -361,7 +361,7 @@ - + @@ -398,4 +398,4 @@ - \ No newline at end of file + From 537cafab9283034cb2c3ca8342181bab824da9b9 Mon Sep 17 00:00:00 2001 From: Matyrobbrt <65940752+Matyrobbrt@users.noreply.github.com> Date: Fri, 9 Feb 2024 18:50:48 +0200 Subject: [PATCH 11/13] Readme --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 09401fb..65eb796 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,12 @@ publishing { } ``` +### Spotless + +The `net.neoforged.gradleutils.spotless` plugin provides integration (a formatter configuration) with Spotless. + +This plugin provides a `spotlessUtils` extension which has a `configure` method that can be called with the `spotless` extension to configure Spotless and use the formatter configuration provided by GradleUtils. + ## License This project is licensed under the GNU Lesser General Public License, or LGPL, version 2.1 only. See the `LICENSE` file From 0b2a7d1a568a83488d09a3282c8ac7cfe38f153a Mon Sep 17 00:00:00 2001 From: Matyrobbrt <65940752+Matyrobbrt@users.noreply.github.com> Date: Thu, 15 Feb 2024 09:51:22 +0200 Subject: [PATCH 12/13] Update README.md --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 65eb796..4ae14ec 100644 --- a/README.md +++ b/README.md @@ -62,8 +62,15 @@ publishing { ### Spotless The `net.neoforged.gradleutils.spotless` plugin provides integration (a formatter configuration) with Spotless. +This plugin must be applied to the buildscript, as GradleUtils does not apply it automatically. +This plugin also requires Gradle to run with at least Java 11, much like Spotless does. -This plugin provides a `spotlessUtils` extension which has a `configure` method that can be called with the `spotless` extension to configure Spotless and use the formatter configuration provided by GradleUtils. +This plugin provides a `spotlessUtils` extension which has a `configure` method that can be called with the `spotless` extension to configure Spotless and use the formatter configuration provided by GradleUtils: +```gradle +spotlessUtils { + configure(spotless) +} +``` ## License From a9ceb846f463788c5ae0f65a2300eb09d07adb97 Mon Sep 17 00:00:00 2001 From: Matyrobbrt <65940752+Matyrobbrt@users.noreply.github.com> Date: Thu, 15 Feb 2024 09:52:01 +0200 Subject: [PATCH 13/13] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4ae14ec..87e022a 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ publishing { ### Spotless The `net.neoforged.gradleutils.spotless` plugin provides integration (a formatter configuration) with Spotless. -This plugin must be applied to the buildscript, as GradleUtils does not apply it automatically. +The Spotless plugin must be manually applied to the buildscript, as GradleUtils does not apply it automatically. This plugin also requires Gradle to run with at least Java 11, much like Spotless does. This plugin provides a `spotlessUtils` extension which has a `configure` method that can be called with the `spotless` extension to configure Spotless and use the formatter configuration provided by GradleUtils: