mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 22:30:54 +01:00
Use spotless to format remaining Kotlin files
Also: fix issue where some commented out Kotlin files are invalid.
This commit is contained in:
@@ -40,7 +40,7 @@ idea {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val clean by tasks.registering(Delete::class) {
|
val clean by tasks.existing {
|
||||||
delete(layout.buildDirectory)
|
delete(layout.buildDirectory)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,18 @@
|
|||||||
import org.jetbrains.kotlin.config.JvmTarget
|
/**
|
||||||
|
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
plugins {
|
plugins {
|
||||||
`kotlin-dsl`
|
`kotlin-dsl`
|
||||||
}
|
}
|
||||||
@@ -7,9 +20,7 @@ plugins {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation(libs.downloadTaskPlugin)
|
implementation(libs.downloadTaskPlugin)
|
||||||
implementation(libs.spotlessPlugin)
|
implementation(libs.spotlessPlugin)
|
||||||
implementation(libs.kotlinPlugin) {
|
implementation(libs.kotlinPlugin) { exclude(module = "kotlin-android-extensions") }
|
||||||
exclude(module = "kotlin-android-extensions")
|
|
||||||
}
|
|
||||||
implementation(libs.shadowPlugin)
|
implementation(libs.shadowPlugin)
|
||||||
|
|
||||||
// fix from the Gradle team: makes version catalog symbols available in build scripts
|
// fix from the Gradle team: makes version catalog symbols available in build scripts
|
||||||
@@ -22,12 +33,4 @@ java {
|
|||||||
targetCompatibility = JavaVersion.VERSION_17
|
targetCompatibility = JavaVersion.VERSION_17
|
||||||
}
|
}
|
||||||
|
|
||||||
kotlin {
|
kotlin { target { compilations.configureEach { kotlinOptions { jvmTarget = "17" } } } }
|
||||||
target {
|
|
||||||
compilations.configureEach {
|
|
||||||
kotlinOptions {
|
|
||||||
jvmTarget = "17"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,10 +1,27 @@
|
|||||||
|
/**
|
||||||
|
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
import com.diffplug.gradle.spotless.KotlinGradleExtension
|
||||||
|
import org.gradle.accessors.dm.LibrariesForLibs
|
||||||
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||||
|
|
||||||
|
plugins { id("com.diffplug.spotless") }
|
||||||
|
|
||||||
val buildInfo = extensions.create<BuildInfo>("buildInfo", project)
|
val buildInfo = extensions.create<BuildInfo>("buildInfo", project)
|
||||||
|
|
||||||
dependencyLocking {
|
dependencyLocking { lockAllConfigurations() }
|
||||||
lockAllConfigurations()
|
|
||||||
}
|
|
||||||
|
|
||||||
configurations {
|
configurations {
|
||||||
val rejectedVersionSuffix = Regex("-alpha|-beta|-eap|-m|-rc|-snapshot", RegexOption.IGNORE_CASE)
|
val rejectedVersionSuffix = Regex("-alpha|-beta|-eap|-m|-rc|-snapshot", RegexOption.IGNORE_CASE)
|
||||||
@@ -13,8 +30,10 @@ configurations {
|
|||||||
componentSelection {
|
componentSelection {
|
||||||
all {
|
all {
|
||||||
if (rejectedVersionSuffix.containsMatchIn(candidate.version)) {
|
if (rejectedVersionSuffix.containsMatchIn(candidate.version)) {
|
||||||
reject("Rejected dependency $candidate " +
|
reject(
|
||||||
"because it has a prelease version suffix matching `$rejectedVersionSuffix`.")
|
"Rejected dependency $candidate " +
|
||||||
|
"because it has a prelease version suffix matching `$rejectedVersionSuffix`."
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -36,24 +55,13 @@ tasks.withType<KotlinCompile>().configureEach {
|
|||||||
}
|
}
|
||||||
|
|
||||||
plugins.withType(IdeaPlugin::class).configureEach {
|
plugins.withType(IdeaPlugin::class).configureEach {
|
||||||
val errorMessage = "Use IntelliJ Gradle import instead of running the `idea` task. See README for more information."
|
val errorMessage =
|
||||||
|
"Use IntelliJ Gradle import instead of running the `idea` task. See README for more information."
|
||||||
|
|
||||||
tasks.named("idea") {
|
tasks.named("idea") { doFirst { throw GradleException(errorMessage) } }
|
||||||
doFirst {
|
tasks.named("ideaModule") { doFirst { throw GradleException(errorMessage) } }
|
||||||
throw GradleException(errorMessage)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
tasks.named("ideaModule") {
|
|
||||||
doFirst {
|
|
||||||
throw GradleException(errorMessage)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (project == rootProject) {
|
if (project == rootProject) {
|
||||||
tasks.named("ideaProject") {
|
tasks.named("ideaProject") { doFirst { throw GradleException(errorMessage) } }
|
||||||
doFirst {
|
|
||||||
throw GradleException(errorMessage)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,11 +80,7 @@ plugins.withType(MavenPublishPlugin::class).configureEach {
|
|||||||
// dependency versions in generated POMs
|
// dependency versions in generated POMs
|
||||||
publications {
|
publications {
|
||||||
withType(MavenPublication::class.java) {
|
withType(MavenPublication::class.java) {
|
||||||
versionMapping {
|
versionMapping { allVariants { fromResolutionResult() } }
|
||||||
allVariants {
|
|
||||||
fromResolutionResult()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -84,13 +88,10 @@ plugins.withType(MavenPublishPlugin::class).configureEach {
|
|||||||
|
|
||||||
// settings.gradle.kts sets `--write-locks`
|
// settings.gradle.kts sets `--write-locks`
|
||||||
// if Gradle command line contains this task name
|
// if Gradle command line contains this task name
|
||||||
val updateDependencyLocks by tasks.registering {
|
val updateDependencyLocks by
|
||||||
doLast {
|
tasks.registering {
|
||||||
configurations
|
doLast { configurations.filter { it.isCanBeResolved }.forEach { it.resolve() } }
|
||||||
.filter { it.isCanBeResolved }
|
|
||||||
.forEach { it.resolve() }
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
val allDependencies by tasks.registering(DependencyReportTask::class)
|
val allDependencies by tasks.registering(DependencyReportTask::class)
|
||||||
|
|
||||||
@@ -118,3 +119,36 @@ tasks.withType(JavaExec::class).configureEach {
|
|||||||
server = true
|
server = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Version Catalog library symbols.
|
||||||
|
private val libs = the<LibrariesForLibs>()
|
||||||
|
|
||||||
|
private val licenseHeaderFile by lazy {
|
||||||
|
rootProject.file("buildSrc/src/main/resources/license-header.star-block.txt")
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun KotlinGradleExtension.configureFormatter() {
|
||||||
|
ktfmt(libs.versions.ktfmt.get()).googleStyle()
|
||||||
|
targetExclude("**/generated/**", "**/build/**")
|
||||||
|
licenseHeaderFile(licenseHeaderFile, "([a-zA-Z]|@file|//)")
|
||||||
|
}
|
||||||
|
|
||||||
|
spotless {
|
||||||
|
// When building root project, format buildSrc files too.
|
||||||
|
// We need this because buildSrc is not a subproject of the root project, so a top-level
|
||||||
|
// `spotlessApply` will not trigger `buildSrc:spotlessApply`.
|
||||||
|
if (project === rootProject) {
|
||||||
|
kotlinGradle {
|
||||||
|
configureFormatter()
|
||||||
|
target("*.kts", "buildSrc/**/*.kts")
|
||||||
|
}
|
||||||
|
kotlin {
|
||||||
|
ktfmt(libs.versions.ktfmt.get()).googleStyle()
|
||||||
|
targetExclude("**/generated/**", "**/build/**")
|
||||||
|
target("buildSrc/**/*.kt")
|
||||||
|
licenseHeaderFile(licenseHeaderFile)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
kotlinGradle { configureFormatter() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,3 +1,18 @@
|
|||||||
|
/**
|
||||||
|
* Copyright © 2024 Apple Inc. and the Pkl project authors. All rights reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
@file:Suppress("HttpUrlsUsage")
|
@file:Suppress("HttpUrlsUsage")
|
||||||
|
|
||||||
import org.gradle.accessors.dm.LibrariesForLibs
|
import org.gradle.accessors.dm.LibrariesForLibs
|
||||||
@@ -30,11 +45,14 @@ spotless {
|
|||||||
targetExclude("**/generated/**", "**/build/**")
|
targetExclude("**/generated/**", "**/build/**")
|
||||||
licenseHeaderFile(rootProject.file("buildSrc/src/main/resources/license-header.star-block.txt"))
|
licenseHeaderFile(rootProject.file("buildSrc/src/main/resources/license-header.star-block.txt"))
|
||||||
}
|
}
|
||||||
|
kotlin {
|
||||||
|
ktfmt(libs.versions.ktfmt.get()).googleStyle()
|
||||||
|
targetExclude("**/generated/**", "**/build/**")
|
||||||
|
licenseHeaderFile(rootProject.file("buildSrc/src/main/resources/license-header.star-block.txt"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.compileKotlin {
|
tasks.compileKotlin { enabled = false }
|
||||||
enabled = false
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.jar {
|
tasks.jar {
|
||||||
manifest {
|
manifest {
|
||||||
@@ -49,15 +67,18 @@ tasks.javadoc {
|
|||||||
(options as StandardJavadocDocletOptions).addStringOption("Xdoclint:none", "-quiet")
|
(options as StandardJavadocDocletOptions).addStringOption("Xdoclint:none", "-quiet")
|
||||||
}
|
}
|
||||||
|
|
||||||
val workAroundKotlinGradlePluginBug by tasks.registering {
|
val workAroundKotlinGradlePluginBug by
|
||||||
doLast {
|
tasks.registering {
|
||||||
// Works around this problem, which sporadically appears and disappears in different subprojects:
|
doLast {
|
||||||
// A problem was found with the configuration of task ':pkl-executor:compileJava' (type 'JavaCompile').
|
// Works around this problem, which sporadically appears and disappears in different
|
||||||
// > Directory '[...]/pkl/pkl-executor/build/classes/kotlin/main'
|
// subprojects:
|
||||||
// specified for property 'compileKotlinOutputClasses' does not exist.
|
// A problem was found with the configuration of task ':pkl-executor:compileJava' (type
|
||||||
layout.buildDirectory.dir("classes/kotlin/main").get().asFile.mkdirs()
|
// 'JavaCompile').
|
||||||
|
// > Directory '[...]/pkl/pkl-executor/build/classes/kotlin/main'
|
||||||
|
// specified for property 'compileKotlinOutputClasses' does not exist.
|
||||||
|
layout.buildDirectory.dir("classes/kotlin/main").get().asFile.mkdirs()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
tasks.compileJava {
|
tasks.compileJava {
|
||||||
dependsOn(workAroundKotlinGradlePluginBug)
|
dependsOn(workAroundKotlinGradlePluginBug)
|
||||||
|
|||||||
@@ -23,11 +23,3 @@ dependencies {
|
|||||||
tasks.compileKotlin {
|
tasks.compileKotlin {
|
||||||
enabled = true // disabled by pklJavaLibrary
|
enabled = true // disabled by pklJavaLibrary
|
||||||
}
|
}
|
||||||
|
|
||||||
spotless {
|
|
||||||
kotlin {
|
|
||||||
ktfmt(libs.versions.ktfmt.get()).googleStyle()
|
|
||||||
targetExclude("**/generated/**", "**/build/**")
|
|
||||||
licenseHeaderFile(rootProject.file("buildSrc/src/main/resources/license-header.star-block.txt"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//package org.pkl.core.runtime;
|
package org.pkl.core.runtime;
|
||||||
//
|
//
|
||||||
//import java.io.IOException;
|
//import java.io.IOException;
|
||||||
//import java.net.URI;
|
//import java.net.URI;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
//package org.pkl.core.runtime;
|
package org.pkl.core.runtime;
|
||||||
//
|
//
|
||||||
//import java.io.File;
|
//import java.io.File;
|
||||||
//import java.io.IOException;
|
//import java.io.IOException;
|
||||||
|
|||||||
Reference in New Issue
Block a user