Skip to content

Commit

Permalink
build: Use spotless for license header checks (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
zml2008 authored May 7, 2022
1 parent daf19ea commit a6c23e5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
29 changes: 20 additions & 9 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import com.diffplug.gradle.spotless.SpotlessExtension
import net.kyori.indra.IndraExtension
import net.kyori.indra.gradle.IndraPluginPublishingExtension
import org.cadixdev.gradle.licenser.LicenseExtension

plugins {
id("com.gradle.plugin-publish") apply false
id("net.kyori.indra") apply false
id("net.kyori.indra.license-header") apply false
id("com.diffplug.spotless") apply false
id("net.kyori.indra.publishing.gradle-plugin") apply false
}

Expand All @@ -17,7 +17,7 @@ subprojects {
apply(JavaGradlePluginPlugin::class)
apply("com.gradle.plugin-publish")
apply("net.kyori.indra")
apply("net.kyori.indra.license-header")
apply("com.diffplug.spotless")
apply("net.kyori.indra.publishing.gradle-plugin")
apply("net.kyori.indra.git")
}
Expand Down Expand Up @@ -77,17 +77,28 @@ subprojects {
}
}

extensions.configure(LicenseExtension::class) {
extensions.configure(SpotlessExtension::class) {
val name: String by project
val organization: String by project
val projectUrl: String by project

properties {
this["name"] = name
this["organization"] = organization
this["url"] = projectUrl
java {
val lineSep = System.lineSeparator()
val contents = rootProject.file("HEADER.txt")
.readLines().asSequence()
.map { (" * " + it).trimEnd() }
.joinToString(prefix = "/*${lineSep}", postfix = "${lineSep} */", separator = lineSep)

val formattedContents = groovy.text.SimpleTemplateEngine()
.createTemplate(contents)
.make(mutableMapOf(
"name" to name,
"organization" to organization,
"url" to projectUrl
))

licenseHeader(formattedContents.toString())
}
header(rootProject.file("HEADER.txt"))
}

extensions.configure(SigningExtension::class) {
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ pluginManagement {
plugins {
val indraVersion = "2.1.1"
id("com.gradle.plugin-publish") version "0.21.0"
id("com.diffplug.spotless") version "6.5.2"
id("net.kyori.indra") version indraVersion
id("net.kyori.indra.license-header") version indraVersion
id("net.kyori.indra.publishing.gradle-plugin") version indraVersion
}
}
Expand Down

0 comments on commit a6c23e5

Please sign in to comment.