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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
`kotlin-dsl`
|
||||
}
|
||||
@@ -7,9 +20,7 @@ plugins {
|
||||
dependencies {
|
||||
implementation(libs.downloadTaskPlugin)
|
||||
implementation(libs.spotlessPlugin)
|
||||
implementation(libs.kotlinPlugin) {
|
||||
exclude(module = "kotlin-android-extensions")
|
||||
}
|
||||
implementation(libs.kotlinPlugin) { exclude(module = "kotlin-android-extensions") }
|
||||
implementation(libs.shadowPlugin)
|
||||
|
||||
// fix from the Gradle team: makes version catalog symbols available in build scripts
|
||||
@@ -22,12 +33,4 @@ java {
|
||||
targetCompatibility = JavaVersion.VERSION_17
|
||||
}
|
||||
|
||||
kotlin {
|
||||
target {
|
||||
compilations.configureEach {
|
||||
kotlinOptions {
|
||||
jvmTarget = "17"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
kotlin { 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
|
||||
|
||||
plugins { id("com.diffplug.spotless") }
|
||||
|
||||
val buildInfo = extensions.create<BuildInfo>("buildInfo", project)
|
||||
|
||||
dependencyLocking {
|
||||
lockAllConfigurations()
|
||||
}
|
||||
dependencyLocking { lockAllConfigurations() }
|
||||
|
||||
configurations {
|
||||
val rejectedVersionSuffix = Regex("-alpha|-beta|-eap|-m|-rc|-snapshot", RegexOption.IGNORE_CASE)
|
||||
@@ -13,8 +30,10 @@ configurations {
|
||||
componentSelection {
|
||||
all {
|
||||
if (rejectedVersionSuffix.containsMatchIn(candidate.version)) {
|
||||
reject("Rejected dependency $candidate " +
|
||||
"because it has a prelease version suffix matching `$rejectedVersionSuffix`.")
|
||||
reject(
|
||||
"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 {
|
||||
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") {
|
||||
doFirst {
|
||||
throw GradleException(errorMessage)
|
||||
}
|
||||
}
|
||||
tasks.named("ideaModule") {
|
||||
doFirst {
|
||||
throw GradleException(errorMessage)
|
||||
}
|
||||
}
|
||||
tasks.named("idea") { doFirst { throw GradleException(errorMessage) } }
|
||||
tasks.named("ideaModule") { doFirst { throw GradleException(errorMessage) } }
|
||||
if (project == rootProject) {
|
||||
tasks.named("ideaProject") {
|
||||
doFirst {
|
||||
throw GradleException(errorMessage)
|
||||
}
|
||||
}
|
||||
tasks.named("ideaProject") { doFirst { throw GradleException(errorMessage) } }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,11 +80,7 @@ plugins.withType(MavenPublishPlugin::class).configureEach {
|
||||
// dependency versions in generated POMs
|
||||
publications {
|
||||
withType(MavenPublication::class.java) {
|
||||
versionMapping {
|
||||
allVariants {
|
||||
fromResolutionResult()
|
||||
}
|
||||
}
|
||||
versionMapping { allVariants { fromResolutionResult() } }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -84,12 +88,9 @@ plugins.withType(MavenPublishPlugin::class).configureEach {
|
||||
|
||||
// settings.gradle.kts sets `--write-locks`
|
||||
// if Gradle command line contains this task name
|
||||
val updateDependencyLocks by tasks.registering {
|
||||
doLast {
|
||||
configurations
|
||||
.filter { it.isCanBeResolved }
|
||||
.forEach { it.resolve() }
|
||||
}
|
||||
val updateDependencyLocks by
|
||||
tasks.registering {
|
||||
doLast { configurations.filter { it.isCanBeResolved }.forEach { it.resolve() } }
|
||||
}
|
||||
|
||||
val allDependencies by tasks.registering(DependencyReportTask::class)
|
||||
@@ -118,3 +119,36 @@ tasks.withType(JavaExec::class).configureEach {
|
||||
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")
|
||||
|
||||
import org.gradle.accessors.dm.LibrariesForLibs
|
||||
@@ -30,11 +45,14 @@ spotless {
|
||||
targetExclude("**/generated/**", "**/build/**")
|
||||
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 {
|
||||
enabled = false
|
||||
}
|
||||
tasks.compileKotlin { enabled = false }
|
||||
|
||||
tasks.jar {
|
||||
manifest {
|
||||
@@ -49,10 +67,13 @@ tasks.javadoc {
|
||||
(options as StandardJavadocDocletOptions).addStringOption("Xdoclint:none", "-quiet")
|
||||
}
|
||||
|
||||
val workAroundKotlinGradlePluginBug by tasks.registering {
|
||||
val workAroundKotlinGradlePluginBug by
|
||||
tasks.registering {
|
||||
doLast {
|
||||
// Works around this problem, which sporadically appears and disappears in different subprojects:
|
||||
// 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
|
||||
// subprojects:
|
||||
// A problem was found with the configuration of task ':pkl-executor:compileJava' (type
|
||||
// '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()
|
||||
|
||||
@@ -23,11 +23,3 @@ dependencies {
|
||||
tasks.compileKotlin {
|
||||
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.net.URI;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
//package org.pkl.core.runtime;
|
||||
package org.pkl.core.runtime;
|
||||
//
|
||||
//import java.io.File;
|
||||
//import java.io.IOException;
|
||||
|
||||
Reference in New Issue
Block a user