Skip to content

Commit 3f932c0

Browse files
committed
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.
1 parent 6318e83 commit 3f932c0

File tree

5 files changed

+31
-22
lines changed

5 files changed

+31
-22
lines changed

build.gradle.kts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ plugins {
55
id("local.gwt-test")
66
id("local.maven-publish")
77

8-
id("net.ltgt.errorprone") version "0.8"
9-
id("com.diffplug.gradle.spotless") version "3.23.0"
8+
id("net.ltgt.errorprone") version "0.8.1"
9+
id("com.diffplug.gradle.spotless") version "3.24.3"
10+
id("org.jlleitschuh.gradle.ktlint") version "8.2.0"
1011
id("com.github.hierynomus.license") version "0.15.0"
1112
}
1213

@@ -44,17 +45,19 @@ repositories {
4445

4546
allprojects {
4647
apply(plugin = "com.diffplug.gradle.spotless")
48+
apply(plugin = "org.jlleitschuh.gradle.ktlint")
4749

4850
spotless {
49-
kotlinGradle {
50-
ktlint("0.32.0")
51-
}
5251
java {
5352
// local.gwt-test generates sources, we only want to check sources
5453
targetExclude(fileTree(buildDir) { include("**/*.java") })
5554
googleJavaFormat("1.7")
5655
}
5756
}
57+
ktlint {
58+
version.set("0.34.2")
59+
enableExperimentalRules.set(true)
60+
}
5861
}
5962

6063
/*

buildSrc/build.gradle.kts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ plugins {
22
`java-gradle-plugin`
33
`kotlin-dsl`
44

5-
id("com.diffplug.gradle.spotless") version "3.23.0"
5+
id("org.jlleitschuh.gradle.ktlint") version "8.2.0"
66
}
77
repositories {
88
jcenter()
@@ -11,15 +11,15 @@ kotlinDslPluginOptions {
1111
experimentalWarning.set(false)
1212
}
1313

14-
spotless {
15-
val ktlintVersion = "0.32.0"
16-
kotlin {
17-
// for some reason, spotless includes *.kts but won't lint them as scripts
18-
targetExclude("**/*.kts")
19-
ktlint(ktlintVersion)
14+
ktlint {
15+
version.set("0.34.2")
16+
enableExperimentalRules.set(true)
17+
kotlinScriptAdditionalPaths {
18+
include(fileTree("src/main/kotlin"))
2019
}
21-
kotlinGradle {
22-
target("*.gradle.kts", "src/main/kotlin/**/*.gradle.kts")
23-
ktlint(ktlintVersion)
20+
filter {
21+
exclude() {
22+
it.file in fileTree(buildDir)
23+
}
2424
}
2525
}

buildSrc/src/main/kotlin/local/GwtTestExtension.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package local
22

3+
import javax.inject.Inject
34
import org.gradle.api.model.ObjectFactory
45
import org.gradle.kotlin.dsl.property
5-
import javax.inject.Inject
66

77
open class GwtTestExtension @Inject constructor(objects: ObjectFactory) {
88
val moduleName = objects.property<String>()

buildSrc/src/main/kotlin/local/gwt-test.gradle.kts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ val generateGwtTestSources by tasks.registering(Copy::class) {
1414
if (it == "import junit.framework.TestCase;") {
1515
"import com.google.gwt.junit.client.GWTTestCase;"
1616
} else {
17-
it.replace("extends TestCase {", """extends GWTTestCase {
17+
it.replace(
18+
"extends TestCase {",
19+
"""extends GWTTestCase {
1820
@Override
1921
public String getModuleName() { return "${extension.moduleName.get()}"; }"""
2022
)

buildSrc/src/main/kotlin/local/maven-publish.gradle.kts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,15 @@ val sourcesJar by tasks.creating(Jar::class) {
2424

2525
val sonatypeRepository = publishing.repositories.maven {
2626
name = "sonatype"
27-
setUrl(provider {
28-
if (isSnapshot)
29-
uri("https://oss.sonatype.org/content/repositories/snapshots/") else
30-
uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
31-
})
27+
setUrl(
28+
provider {
29+
if (isSnapshot) {
30+
uri("https://oss.sonatype.org/content/repositories/snapshots/")
31+
} else {
32+
uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
33+
}
34+
}
35+
)
3236
credentials {
3337
username = project.findProperty("ossrhUsername") as? String
3438
password = project.findProperty("ossrhPassword") as? String

0 commit comments

Comments
 (0)