Skip to content

Commit e81a2c4

Browse files
authored
Gradle / Kotlin + move common parts to project-plugin (apache#53)
Migrate Gradle/Groovy to Gradle/Kotlin-script. Gradle/Kotlin is a bit slower to compile, but has proper type-safety and really good support in at least IntelliJ, and actually makes debugging build scripts possible. Gradle/Groovy is not really type safe and often yields quite surprising behavior. Also moves the common project configuration to the project plugin `polaris-server` and the "boring" parts of `/build.gradle.kts` to the project plugin `polaris-root`.
1 parent 17ba407 commit e81a2c4

15 files changed

+725
-573
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ gradle/wrapper/gradle-wrapper-*.sha256
4545

4646
# Gradle
4747
/.gradle
48+
/build-logic/.gradle
4849
**/build/
4950
!src/**/build/
5051

extension/persistence/eclipselink/build.gradle renamed to build-logic/build.gradle.kts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,11 @@
1414
* limitations under the License.
1515
*/
1616

17-
dependencies {
18-
implementation(project(":polaris-core"))
19-
runtimeOnly(project(":polaris-service"))
20-
implementation(libs.eclipselink)
21-
implementation(platform(libs.dropwizard.bom))
22-
implementation("io.dropwizard:dropwizard-jackson")
23-
implementation(libs.h2) // Different dependencies will be needed for different backend databases
24-
25-
testImplementation(libs.h2)
26-
testImplementation(testFixtures(project(":polaris-core")))
17+
plugins { `kotlin-dsl` }
2718

28-
sourceSets {
29-
test {
30-
resources {
31-
srcDir 'src/test/data'
32-
}
33-
}
34-
}
19+
dependencies {
20+
implementation(gradleKotlinDsl())
21+
implementation(baselibs.errorprone)
22+
implementation(baselibs.idea.ext)
23+
implementation(baselibs.spotless)
3524
}

settings.gradle renamed to build-logic/settings.gradle.kts

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,14 @@
1414
* limitations under the License.
1515
*/
1616

17-
if (!JavaVersion.current().isCompatibleWith(JavaVersion.VERSION_21)) {
18-
throw new GradleException("""
19-
20-
Build aborted...
21-
22-
The Apache Polaris build requires Java 21.
23-
24-
25-
""")
17+
dependencyResolutionManagement {
18+
versionCatalogs { create("baselibs") { from(files("../gradle/baselibs.versions.toml")) } }
2619
}
2720

28-
rootProject.name = "polaris"
29-
30-
Properties projects = new Properties()
31-
file("gradle/projects.main.properties").withInputStream { projects.load(it) }
32-
projects.entrySet().forEach {
33-
final def name = it.key as String
34-
include(name)
35-
final def prj = project(":${name}")
36-
prj.name = name
37-
prj.projectDir = file(it.value)
21+
dependencyResolutionManagement {
22+
repositoriesMode = RepositoriesMode.FAIL_ON_PROJECT_REPOS
23+
repositories {
24+
mavenCentral()
25+
gradlePluginPortal()
26+
}
3827
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright (c) 2024 Snowflake Computing Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import org.jetbrains.gradle.ext.copyright
18+
import org.jetbrains.gradle.ext.encodings
19+
import org.jetbrains.gradle.ext.settings
20+
21+
plugins {
22+
id("com.diffplug.spotless")
23+
id("org.jetbrains.gradle.plugin.idea-ext")
24+
}
25+
26+
spotless {
27+
kotlinGradle {
28+
ktfmt().googleStyle()
29+
licenseHeaderFile(rootProject.file("codestyle/copyright-header-java.txt"), "$")
30+
target("*.gradle.kts", "build-logic/src/**/*.kts")
31+
}
32+
}
33+
34+
if (System.getProperty("idea.sync.active").toBoolean()) {
35+
idea {
36+
module {
37+
isDownloadJavadoc = false // was 'true', but didn't work
38+
isDownloadSources = false // was 'true', but didn't work
39+
inheritOutputDirs = true
40+
}
41+
42+
project.settings {
43+
copyright {
44+
useDefault = "ApacheLicense-v2"
45+
profiles.create("ApacheLicense-v2") {
46+
// strip trailing LF
47+
val copyrightText = rootProject.file("codestyle/copyright-header.txt").readText()
48+
notice = copyrightText
49+
}
50+
}
51+
52+
encodings.encoding = "UTF-8"
53+
encodings.properties.encoding = "UTF-8"
54+
}
55+
}
56+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
* Copyright (c) 2024 Snowflake Computing Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import net.ltgt.gradle.errorprone.errorprone
18+
import org.gradle.api.tasks.compile.JavaCompile
19+
import org.gradle.api.tasks.testing.Test
20+
import org.gradle.kotlin.dsl.named
21+
22+
plugins {
23+
id("jacoco")
24+
id("java")
25+
id("com.diffplug.spotless")
26+
id("jacoco-report-aggregation")
27+
id("net.ltgt.errorprone")
28+
}
29+
30+
tasks.withType(JavaCompile::class.java).configureEach {
31+
options.compilerArgs.addAll(listOf("-Xlint:unchecked", "-Xlint:deprecation"))
32+
options.errorprone.disableAllWarnings = true
33+
options.errorprone.disableWarningsInGeneratedCode = true
34+
options.errorprone.error("StringCaseLocaleUsage")
35+
36+
// TODO Disabled until the code is only Java 11/17/21, see #76
37+
// options.release = 17
38+
}
39+
40+
tasks.register("format").configure { dependsOn("spotlessApply") }
41+
42+
tasks.named<Test>("test").configure {
43+
useJUnitPlatform()
44+
jvmArgs("-Duser.language=en")
45+
}
46+
47+
spotless {
48+
val disallowWildcardImports = { text: String ->
49+
val regex = "~/import .*\\.\\*;/".toRegex()
50+
if (regex.matches(text)) {
51+
throw GradleException("Wildcard imports disallowed - ${regex.findAll(text)}")
52+
}
53+
text
54+
}
55+
java {
56+
target("src/main/java/**/*.java", "src/testFixtures/java/**/*.java", "src/test/java/**/*.java")
57+
googleJavaFormat()
58+
licenseHeaderFile(rootProject.file("codestyle/copyright-header-java.txt"))
59+
endWithNewline()
60+
custom("disallowWildcardImports", disallowWildcardImports)
61+
}
62+
kotlinGradle {
63+
ktfmt().googleStyle()
64+
licenseHeaderFile(rootProject.file("codestyle/copyright-header-java.txt"), "$")
65+
target("*.gradle.kts")
66+
}
67+
format("xml") {
68+
target("src/**/*.xml", "src/**/*.xsd")
69+
targetExclude("codestyle/copyright-header.xml")
70+
eclipseWtp(com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep.XML)
71+
.configFile(rootProject.file("codestyle/org.eclipse.wst.xml.core.prefs"))
72+
// getting the license-header delimiter right is a bit tricky.
73+
// licenseHeaderFile(rootProject.file("codestyle/copyright-header.xml"), '<^[!?].*$')
74+
}
75+
}
76+
77+
dependencies { errorprone(versionCatalogs.named("libs").findLibrary("errorprone").get()) }

build.gradle

Lines changed: 0 additions & 163 deletions
This file was deleted.

0 commit comments

Comments
 (0)