From 3f932c0ef6c7f814e20d647085e5ba27b7f68124 Mon Sep 17 00:00:00 2001 From: Thomas Broyer Date: Sun, 29 Sep 2019 16:51:56 +0200 Subject: [PATCH] Switch from Spotless to ktlint-gradle for Kotlin code due to diffplug/spotless#409 and diffplug/spotless#419 Update to Ktlint 0.34.2 and enable experimental rules. --- build.gradle.kts | 13 +++++++----- buildSrc/build.gradle.kts | 20 +++++++++---------- .../src/main/kotlin/local/GwtTestExtension.kt | 2 +- .../src/main/kotlin/local/gwt-test.gradle.kts | 4 +++- .../kotlin/local/maven-publish.gradle.kts | 14 ++++++++----- 5 files changed, 31 insertions(+), 22 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 9e16b1a..458a3b3 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -5,8 +5,9 @@ plugins { id("local.gwt-test") id("local.maven-publish") - id("net.ltgt.errorprone") version "0.8" - id("com.diffplug.gradle.spotless") version "3.23.0" + id("net.ltgt.errorprone") version "0.8.1" + id("com.diffplug.gradle.spotless") version "3.24.3" + id("org.jlleitschuh.gradle.ktlint") version "8.2.0" id("com.github.hierynomus.license") version "0.15.0" } @@ -44,17 +45,19 @@ repositories { allprojects { apply(plugin = "com.diffplug.gradle.spotless") + apply(plugin = "org.jlleitschuh.gradle.ktlint") spotless { - kotlinGradle { - ktlint("0.32.0") - } java { // local.gwt-test generates sources, we only want to check sources targetExclude(fileTree(buildDir) { include("**/*.java") }) googleJavaFormat("1.7") } } + ktlint { + version.set("0.34.2") + enableExperimentalRules.set(true) + } } /* diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index a1d9887..1bb0081 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -2,7 +2,7 @@ plugins { `java-gradle-plugin` `kotlin-dsl` - id("com.diffplug.gradle.spotless") version "3.23.0" + id("org.jlleitschuh.gradle.ktlint") version "8.2.0" } repositories { jcenter() @@ -11,15 +11,15 @@ kotlinDslPluginOptions { experimentalWarning.set(false) } -spotless { - val ktlintVersion = "0.32.0" - kotlin { - // for some reason, spotless includes *.kts but won't lint them as scripts - targetExclude("**/*.kts") - ktlint(ktlintVersion) +ktlint { + version.set("0.34.2") + enableExperimentalRules.set(true) + kotlinScriptAdditionalPaths { + include(fileTree("src/main/kotlin")) } - kotlinGradle { - target("*.gradle.kts", "src/main/kotlin/**/*.gradle.kts") - ktlint(ktlintVersion) + filter { + exclude() { + it.file in fileTree(buildDir) + } } } diff --git a/buildSrc/src/main/kotlin/local/GwtTestExtension.kt b/buildSrc/src/main/kotlin/local/GwtTestExtension.kt index 39a97bc..0072eae 100644 --- a/buildSrc/src/main/kotlin/local/GwtTestExtension.kt +++ b/buildSrc/src/main/kotlin/local/GwtTestExtension.kt @@ -1,8 +1,8 @@ package local +import javax.inject.Inject import org.gradle.api.model.ObjectFactory import org.gradle.kotlin.dsl.property -import javax.inject.Inject open class GwtTestExtension @Inject constructor(objects: ObjectFactory) { val moduleName = objects.property() diff --git a/buildSrc/src/main/kotlin/local/gwt-test.gradle.kts b/buildSrc/src/main/kotlin/local/gwt-test.gradle.kts index 0148929..6156c03 100644 --- a/buildSrc/src/main/kotlin/local/gwt-test.gradle.kts +++ b/buildSrc/src/main/kotlin/local/gwt-test.gradle.kts @@ -14,7 +14,9 @@ val generateGwtTestSources by tasks.registering(Copy::class) { if (it == "import junit.framework.TestCase;") { "import com.google.gwt.junit.client.GWTTestCase;" } else { - it.replace("extends TestCase {", """extends GWTTestCase { + it.replace( + "extends TestCase {", + """extends GWTTestCase { @Override public String getModuleName() { return "${extension.moduleName.get()}"; }""" ) diff --git a/buildSrc/src/main/kotlin/local/maven-publish.gradle.kts b/buildSrc/src/main/kotlin/local/maven-publish.gradle.kts index e0ca96c..0c4165e 100644 --- a/buildSrc/src/main/kotlin/local/maven-publish.gradle.kts +++ b/buildSrc/src/main/kotlin/local/maven-publish.gradle.kts @@ -24,11 +24,15 @@ val sourcesJar by tasks.creating(Jar::class) { val sonatypeRepository = publishing.repositories.maven { name = "sonatype" - setUrl(provider { - if (isSnapshot) - uri("https://oss.sonatype.org/content/repositories/snapshots/") else - uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/") - }) + setUrl( + provider { + if (isSnapshot) { + uri("https://oss.sonatype.org/content/repositories/snapshots/") + } else { + uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/") + } + } + ) credentials { username = project.findProperty("ossrhUsername") as? String password = project.findProperty("ossrhPassword") as? String