diff --git a/CHANGES.md b/CHANGES.md index ce24e4a5f6..420530d059 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,10 +10,11 @@ This document is intended for Spotless developers. We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (starting after version `1.27.0`). ## [Unreleased] -### Changed +### Build * All `CHANGES.md` are now in keepachangelog format. ([#507](https://github.com/diffplug/spotless/pull/507)) * We now use [javadoc.io](https://javadoc.io/) instead of github pages. ([#508](https://github.com/diffplug/spotless/pull/508)) * We no longer publish `-SNAPSHOT` for every build to `master`, since we have good [JitPack integration](https://github.com/diffplug/spotless/blob/master/CONTRIBUTING.md#gradle---any-commit-in-a-public-github-repo-this-one-or-any-fork). ([#508](https://github.com/diffplug/spotless/pull/508)) +* Improved how we use Spotless on itself. ([#509](https://github.com/diffplug/spotless/pull/509)) ## [1.27.0] - 2020-01-01 * Ignored `KtLintStepTest`, because [gradle/gradle#11752](https://github.com/gradle/gradle/issues/11752) is causing too many CI failures. ([#499](https://github.com/diffplug/spotless/pull/499)) diff --git a/_ext/eclipse-wtp/build.gradle b/_ext/eclipse-wtp/build.gradle index 1dca2707c4..3d79503157 100644 --- a/_ext/eclipse-wtp/build.gradle +++ b/_ext/eclipse-wtp/build.gradle @@ -1,3 +1,6 @@ +plugins { + id 'com.diffplug.gradle.spotless' version '3.27.0' +} ext { developers = [ fvgh: [ name: 'Frank Vennemeyer', email: 'frankgh@zoho.com' ], @@ -118,3 +121,10 @@ fileTree(dir: testLocation).include('**/*Test.java').each { file -> } test.dependsOn "${testFile}" } + +spotless { + format 'xml', { + target 'src/main/resources/**/*.xml' + eclipseWtp('xml').configFile 'spotless.xmlformat.prefs' + } +} diff --git a/spotless.xmlformat.prefs b/_ext/eclipse-wtp/spotless.xmlformat.prefs similarity index 100% rename from spotless.xmlformat.prefs rename to _ext/eclipse-wtp/spotless.xmlformat.prefs diff --git a/build.gradle b/build.gradle index 7b6a4638c0..c6148ab3dc 100644 --- a/build.gradle +++ b/build.gradle @@ -11,6 +11,23 @@ plugins { id 'org.jdrupes.mdoclet' version '1.0.5' apply false // https://github.com/spotbugs/spotbugs/releases id "com.github.spotbugs" version "2.0.0" apply false + // here + id 'com.diffplug.gradle.spotless' version '3.27.0' +} + +// this is... not the canonical way to do spotless :) +allprojects { + apply from: rootProject.file('gradle/spotless.gradle') +} +apply from: rootProject.file('gradle/spotless-freshmark.gradle') + +spotless { + format 'dotfiles', { + target '.gitignore', '.gitattributes', '.editorconfig' + indentWithSpaces(2) + trimTrailingWhitespace() + endWithNewline() + } } // root eclipse project diff --git a/gradle/spotless-freshmark.gradle b/gradle/spotless-freshmark.gradle new file mode 100644 index 0000000000..ee76cfe820 --- /dev/null +++ b/gradle/spotless-freshmark.gradle @@ -0,0 +1,14 @@ +apply plugin: 'com.diffplug.gradle.spotless' +spotless { + freshmark { + target '*.md' + propertiesFile(rootProject.file('gradle.properties')) + properties { + it.put('yes', ':+1:') + it.put('no', ':white_large_square:') + } + indentWithSpaces(2) + trimTrailingWhitespace() + endWithNewline() + } +} diff --git a/spotless.eclipseformat.xml b/gradle/spotless.eclipseformat.xml similarity index 100% rename from spotless.eclipseformat.xml rename to gradle/spotless.eclipseformat.xml diff --git a/gradle/spotless.gradle b/gradle/spotless.gradle new file mode 100644 index 0000000000..151b6dd58e --- /dev/null +++ b/gradle/spotless.gradle @@ -0,0 +1,32 @@ +apply plugin: 'com.diffplug.gradle.spotless' +spotless { + def noInternalDepsClosure = { + String text = it + /* + * No good way to get around using this import: + * https://github.com/gradle/gradle/issues/3191 + */ + String regex = "import org\\.gradle\\.api\\.internal\\.(?!plugins\\.DslObject)" + if ((text.contains('import org.gradle.internal.') || text.find(regex)) && + !text.contains('def noInternalDepsClosure')) { + throw new AssertionError("Accidental internal import") + } + } + if (project.name != 'ide' && project != rootProject) { + // the rootProject and ide projects don't have any java + java { + custom 'noInternalDeps', noInternalDepsClosure + bumpThisNumberIfACustomStepChanges(1) + licenseHeaderFile rootProject.file('gradle/spotless.license') + importOrderFile rootProject.file('gradle/spotless.importorder') + eclipse().configFile rootProject.file('gradle/spotless.eclipseformat.xml') + trimTrailingWhitespace() + removeUnusedImports() + } + } + groovyGradle { + target '*.gradle' + paddedCell() + greclipse().configFile rootProject.files('gradle/spotless.eclipseformat.xml', 'gradle/spotless.groovyformat.prefs') + } +} diff --git a/spotless.groovyformat.prefs b/gradle/spotless.groovyformat.prefs similarity index 100% rename from spotless.groovyformat.prefs rename to gradle/spotless.groovyformat.prefs diff --git a/spotless.importorder b/gradle/spotless.importorder similarity index 100% rename from spotless.importorder rename to gradle/spotless.importorder diff --git a/spotless.license b/gradle/spotless.license similarity index 100% rename from spotless.license rename to gradle/spotless.license diff --git a/plugin-gradle/build.gradle b/plugin-gradle/build.gradle index f7e3e4850b..0f5216bfce 100644 --- a/plugin-gradle/build.gradle +++ b/plugin-gradle/build.gradle @@ -2,6 +2,7 @@ ext.artifactId = project.artifactIdGradle ext.version = project.versionGradle apply from: rootProject.file('gradle/java-setup.gradle') apply from: rootProject.file('gradle/java-publish.gradle') +apply from: rootProject.file('gradle/spotless-freshmark.gradle') apply plugin: 'java-library' apply plugin: 'com.gradle.plugin-publish' @@ -28,24 +29,19 @@ dependencies { tasks.eclipse.dependsOn(pluginUnderTestMetadata) -///////////////////// -// SPOTLESS (fake) // -///////////////////// -task spotlessCheck(type: JavaExec) { - classpath sourceSets.test.runtimeClasspath - main = 'com.diffplug.gradle.spotless.SelfTestCheck' -} -check.dependsOn(spotlessCheck) - -task spotlessApply(type: JavaExec) { - classpath sourceSets.test.runtimeClasspath - main = 'com.diffplug.gradle.spotless.SelfTestApply' -} test { testLogging.showStandardStreams = true } -test { useJUnit { excludeCategories 'com.diffplug.spotless.category.NpmTest' } } +test { + useJUnit { + excludeCategories 'com.diffplug.spotless.category.NpmTest' + } +} -task npmTest(type: Test) { useJUnit { includeCategories 'com.diffplug.spotless.category.NpmTest' } } +task npmTest(type: Test) { + useJUnit { + includeCategories 'com.diffplug.spotless.category.NpmTest' + } +} ////////////////////////// // GRADLE PLUGIN PORTAL // diff --git a/plugin-maven/build.gradle b/plugin-maven/build.gradle index c2aa5a4bb1..6543259057 100644 --- a/plugin-maven/build.gradle +++ b/plugin-maven/build.gradle @@ -6,6 +6,8 @@ plugins { id 'cz.malohlava.visteg' version '1.0.5' // https://github.com/mmalohlava/gradle-visteg } +apply from: rootProject.file('gradle/spotless-freshmark.gradle') + // to generate taskGraph.pdf // - set enabled (below) to true // - run: ./gradlew :plugin-maven:test diff --git a/spotlessSelf.gradle b/spotlessSelf.gradle deleted file mode 100644 index 8746f464bb..0000000000 --- a/spotlessSelf.gradle +++ /dev/null @@ -1,71 +0,0 @@ -buildscript { - repositories { - jcenter() - } -} - -// applied by SelfTest -plugins { - id 'com.diffplug.gradle.spotless' - id 'java' -} - -repositories { jcenter() } -spotless { - def noInternalDepsClosure = { - String text = it - /* - * No good way to get around using this import: - * https://github.com/gradle/gradle/issues/3191 - */ - String regex = "import org\\.gradle\\.api\\.internal\\.(?!plugins\\.DslObject)" - if ((text.contains('import org.gradle.internal.') || text.find(regex)) && - !text.contains('def noInternalDepsClosure')) { - throw new AssertionError("Accidental internal import") - } - } - java { - target fileTree('.') { - include '**/*.java' - exclude '_ext/*/build/**' - } - custom 'noInternalDeps', noInternalDepsClosure - bumpThisNumberIfACustomStepChanges(1) - licenseHeaderFile 'spotless.license' - importOrderFile 'spotless.importorder' - eclipse().configFile 'spotless.eclipseformat.xml' - trimTrailingWhitespace() - removeUnusedImports() - } - groovyGradle { - target fileTree('.') { - include '**/*.gradle' - exclude '_ext/**' - } - paddedCell() - custom 'noInternalDeps', noInternalDepsClosure - bumpThisNumberIfACustomStepChanges(3) - greclipse().configFile('spotless.eclipseformat.xml', 'spotless.groovyformat.prefs') - } - freshmark { - target '**/*.md' - propertiesFile('gradle.properties') - properties { - it.put('yes', ':+1:') - it.put('no', ':white_large_square:') - } - } - format 'misc', { - target '**/*.md', '**/*.gitignore' - indentWithSpaces(2) - trimTrailingWhitespace() - endWithNewline() - } - format 'xml', { - target fileTree('.') { - include '**/*.xml', '**/*.xsd' - exclude '**/build/**' - } - eclipseWtp('xml').configFile 'spotless.xmlformat.prefs' - } -}