Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a Spotless plugin #18

Merged
merged 14 commits into from
Feb 15, 2024
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ publishing {
}
```

### Spotless

The `net.neoforged.gradleutils.spotless` plugin provides integration (a formatter configuration) with Spotless.
Matyrobbrt marked this conversation as resolved.
Show resolved Hide resolved
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:
```gradle
spotlessUtils {
configure(spotless)
}
```

## License

This project is licensed under the GNU Lesser General Public License, or LGPL, version 2.1 only. See the `LICENSE` file
Expand Down
37 changes: 36 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,51 @@ java {
withSourcesJar()
}

sourceSets {
spotless
}

group 'net.neoforged.gradleutils'
version '3.0.0-alpha.10'
version '3.0.0-alpha.11'

repositories {
mavenCentral()
gradlePluginPortal()
}

// Spotless runs on J11
tasks.named('compileSpotlessJava', JavaCompile).configure {
javaCompiler = javaToolchains.compilerFor {
languageVersion = JavaLanguageVersion.of(11)
}
}
tasks.named('compileSpotlessGroovy', GroovyCompile).configure {
javaLauncher = javaToolchains.launcherFor {
languageVersion = JavaLanguageVersion.of(11)
}
}

if (System.getenv('GPP_KEY')) {
project.ext {
set('gradle.publish.key', System.getenv('GPP_KEY'))
set('gradle.publish.secret', System.getenv('GPP_SECRET'))
}
}

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'

api "net.neoforged:groovydslimprover:${gdi_version}"
api "net.neoforged:groovydslimprover:${gdi_version}:base"
api "net.neoforged:groovydslimprover:${gdi_version}:runtime"

spotlessImplementation(gradleApi())
spotlessImplementation 'com.diffplug.spotless:spotless-plugin-gradle:6.23.3'
}

sourceSets {
Expand Down Expand Up @@ -73,6 +96,7 @@ tasks.named('jar', Jar) {
license {
header(file('HEADER'))
skipExistingHeaders = true // Ignore existing license headers on files
exclude 'formatter-config.xml'
}

// Disable the license tasks for the template files
Expand All @@ -94,6 +118,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'
}
}
}

Expand All @@ -102,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
}
Expand Down
Loading
Loading