Skip to content

Commit

Permalink
Switch from Spotless to ktlint-gradle for Kotlin code
Browse files Browse the repository at this point in the history
due to diffplug/spotless#409 and diffplug/spotless#419

Update to Ktlint 0.34.2 and enable experimental rules.
  • Loading branch information
tbroyer committed Sep 29, 2019
1 parent 6318e83 commit 3f932c0
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 22 deletions.
13 changes: 8 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down Expand Up @@ -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)
}
}

/*
Expand Down
20 changes: 10 additions & 10 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
}
}
}
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/local/GwtTestExtension.kt
Original file line number Diff line number Diff line change
@@ -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<String>()
Expand Down
4 changes: 3 additions & 1 deletion buildSrc/src/main/kotlin/local/gwt-test.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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()}"; }"""
)
Expand Down
14 changes: 9 additions & 5 deletions buildSrc/src/main/kotlin/local/maven-publish.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3f932c0

Please sign in to comment.