Skip to content

ALTERNATIVE: Spark/Scala build infra #1203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 63 additions & 46 deletions build-logic/src/main/kotlin/polaris-java.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import com.diffplug.spotless.FormatterFunc
import gradle.kotlin.dsl.accessors._610c9322e0f6ac91715e46c62199c37f.spotless
import java.io.Serializable
import net.ltgt.gradle.errorprone.errorprone
import org.gradle.api.tasks.compile.JavaCompile
Expand All @@ -39,20 +40,25 @@ apply<PublishingHelperPlugin>()

tasks.withType(JavaCompile::class.java).configureEach {
options.compilerArgs.addAll(listOf("-Xlint:unchecked", "-Xlint:deprecation"))
options.errorprone.disableAllWarnings = true
options.errorprone.disableWarningsInGeneratedCode = true
options.errorprone.excludedPaths =
".*/${project.layout.buildDirectory.get().asFile.relativeTo(projectDir)}/generated/.*"
options.errorprone.error(
"DefaultCharset",
"FallThrough",
"MissingCasesInEnumSwitch",
"MissingOverride",
"ModifiedButNotUsed",
"OrphanedFormatString",
"PatternMatchingInstanceof",
"StringCaseLocaleUsage",
)

if (project.extra.has("reused-project-dir")) {
options.errorprone.disableAllChecks = true
} else {
options.errorprone.disableAllWarnings = true
options.errorprone.disableWarningsInGeneratedCode = true
options.errorprone.excludedPaths =
".*/${project.layout.buildDirectory.get().asFile.relativeTo(projectDir)}/generated/.*"
options.errorprone.error(
"DefaultCharset",
"FallThrough",
"MissingCasesInEnumSwitch",
"MissingOverride",
"ModifiedButNotUsed",
"OrphanedFormatString",
"PatternMatchingInstanceof",
"StringCaseLocaleUsage",
)
}
}

tasks.register("compileAll").configure {
Expand Down Expand Up @@ -150,42 +156,53 @@ tasks.withType(Jar::class).configureEach {
}
}

spotless {
java {
target("src/*/java/**/*.java")
googleJavaFormat()
licenseHeaderFile(rootProject.file("codestyle/copyright-header-java.txt"))
endWithNewline()
custom(
"disallowWildcardImports",
object : Serializable, FormatterFunc {
override fun apply(text: String): String {
val regex = "~/import .*\\.\\*;/".toRegex()
if (regex.matches(text)) {
throw GradleException("Wildcard imports disallowed - ${regex.findAll(text)}")
if (!project.extra.has("reused-project-dir") && !gradle.ideSyncActive()) {
spotless {
java {
target("src/*/java/**/*.java")
googleJavaFormat()
licenseHeaderFile(rootProject.file("codestyle/copyright-header-java.txt"))
endWithNewline()
custom(
"disallowWildcardImports",
object : Serializable, FormatterFunc {
override fun apply(text: String): String {
val regex = "~/import .*\\.\\*;/".toRegex()
if (regex.matches(text)) {
throw GradleException("Wildcard imports disallowed - ${regex.findAll(text)}")
}
return text
}
return text
}
},
)
toggleOffOn()
}
kotlinGradle {
ktfmt().googleStyle()
licenseHeaderFile(rootProject.file("codestyle/copyright-header-java.txt"), "$")
target("*.gradle.kts")
}
format("xml") {
target("src/**/*.xml", "src/**/*.xsd")
targetExclude("codestyle/copyright-header.xml")
eclipseWtp(com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep.XML)
.configFile(rootProject.file("codestyle/org.eclipse.wst.xml.core.prefs"))
// getting the license-header delimiter right is a bit tricky.
// licenseHeaderFile(rootProject.file("codestyle/copyright-header.xml"), '<^[!?].*$')
},
)
toggleOffOn()
}
scala {
scalafmt(requiredDependencyVersion("scalafmt"))
.configFile(rootProject.file("codestyle/scalafmt.conf").toString())
licenseHeaderFile(
rootProject.file("codestyle/copyright-header-java.txt"),
"^(package|import) .*$",
)
target("src/**/scala/**/*.scala")
}
kotlinGradle {
ktfmt().googleStyle()
licenseHeaderFile(rootProject.file("codestyle/copyright-header-java.txt"), "$")
target("*.gradle.kts")
}
format("xml") {
target("src/**/*.xml", "src/**/*.xsd")
targetExclude("codestyle/copyright-header.xml")
eclipseWtp(com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep.XML)
.configFile(rootProject.file("codestyle/org.eclipse.wst.xml.core.prefs"))
// getting the license-header delimiter right is a bit tricky.
// licenseHeaderFile(rootProject.file("codestyle/copyright-header.xml"), '<^[!?].*$')
}
}
}

dependencies { errorprone(versionCatalogs.named("libs").findLibrary("errorprone").get()) }
dependencies { errorprone(requiredDependency("errorprone")) }

java {
withJavadocJar()
Expand Down
2 changes: 1 addition & 1 deletion build-logic/src/main/kotlin/polaris-root.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ spotless {
}
}

if (System.getProperty("idea.sync.active").toBoolean()) {
if (gradle.ideSyncActive()) {
idea {
module {
isDownloadJavadoc = false // was 'true', but didn't work
Expand Down
66 changes: 66 additions & 0 deletions build-logic/src/main/kotlin/polaris-scala.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* http://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 org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.bundling.Jar
import org.gradle.api.tasks.scala.ScalaCompile
import org.gradle.api.tasks.scala.ScalaDoc
import org.gradle.kotlin.dsl.*
import org.gradle.language.scala.tasks.KeepAliveMode

plugins {
id("polaris-server")
scala
}

tasks.withType<ScalaCompile>().configureEach {
options.release = 21
scalaCompileOptions.additionalParameters.add("-release:21")
sourceCompatibility = "21"
targetCompatibility = "21"
}

tasks.withType<ScalaCompile>().configureEach {
scalaCompileOptions.keepAliveMode = KeepAliveMode.DAEMON
scalaCompileOptions.encoding = "UTF-8"
}

val scaladoc = tasks.named<ScalaDoc>("scaladoc")
val scaladocJar = tasks.register<Jar>("scaladocJar")

scaladocJar.configure {
dependsOn(scaladoc)
val baseJar = tasks.getByName<Jar>("jar")
from(scaladoc.get().destinationDir)
destinationDirectory = baseJar.destinationDirectory
archiveClassifier = "scaladoc"
}

tasks.named("assemble").configure { dependsOn(scaladocJar) }

configure<PublishingExtension> {
publications {
withType(MavenPublication::class.java) {
if (name == "maven") {
artifact(scaladocJar)
}
}
}
}
62 changes: 62 additions & 0 deletions build-logic/src/main/kotlin/polaris-spark.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you 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
*
* http://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 {
id("polaris-client")
scala
}

tasks.withType<ScalaCompile>().configureEach {
options.release = 11
scalaCompileOptions.additionalParameters.add("-release:11")
sourceCompatibility = "11"
targetCompatibility = "11"
}

tasks.withType<ScalaCompile>().configureEach {
scalaCompileOptions.keepAliveMode = KeepAliveMode.DAEMON
scalaCompileOptions.encoding = "UTF-8"
}

val scaladoc = tasks.named<ScalaDoc>("scaladoc")
val scaladocJar = tasks.register<Jar>("scaladocJar")

scaladocJar.configure {
dependsOn(scaladoc)
val baseJar = tasks.getByName<Jar>("jar")
from(scaladoc.get().destinationDir)
destinationDirectory = baseJar.destinationDirectory
archiveClassifier = "scaladoc"
}

tasks.named("assemble").configure { dependsOn(scaladocJar) }

configure<PublishingExtension> {
publications {
withType(MavenPublication::class.java) {
if (name == "maven") {
artifact(scaladocJar)
}
}
}
}

val versions = sparkScalaVersionsForProject()

scala { scalaVersion.set(versions.scalaFullVersion) }
Loading