This is an automated email from the ASF dual-hosted git repository.
adutra pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/polaris.git
The following commit(s) were added to refs/heads/main by this push:
new f38ac8a42 feat(build): Add Checkstyle plugin and an IllegalImport rule
(#1880)
f38ac8a42 is described below
commit f38ac8a42930b9cfe0ca9ce0c59379b1cfa53f5c
Author: Alexandre Dutra <[email protected]>
AuthorDate: Mon Jun 16 10:51:11 2025 +0200
feat(build): Add Checkstyle plugin and an IllegalImport rule (#1880)
---
.../src/main/kotlin/polaris-java.gradle.kts | 19 ++++++--
.../src/main/kotlin/polaris-spotless.gradle.kts | 2 -
codestyle/checkstyle.xml | 51 ++++++++++++++++++++++
gradle/libs.versions.toml | 1 +
plugins/spark/v3.5/spark/build.gradle.kts | 38 ----------------
quarkus/test-commons/build.gradle.kts | 8 ++--
6 files changed, 73 insertions(+), 46 deletions(-)
diff --git a/build-logic/src/main/kotlin/polaris-java.gradle.kts
b/build-logic/src/main/kotlin/polaris-java.gradle.kts
index 2c45da15f..4370b5518 100644
--- a/build-logic/src/main/kotlin/polaris-java.gradle.kts
+++ b/build-logic/src/main/kotlin/polaris-java.gradle.kts
@@ -30,6 +30,7 @@ plugins {
`java-library`
`java-test-fixtures`
`jvm-test-suite`
+ checkstyle
id("polaris-spotless")
id("jacoco-report-aggregation")
id("net.ltgt.errorprone")
@@ -37,11 +38,23 @@ plugins {
apply<PublishingHelperPlugin>()
-if (project.extra.has("duplicated-project-sources")) {
- // skip the style check for duplicated projects
- tasks.withType<Checkstyle>().configureEach { enabled = false }
+checkstyle {
+ val checkstyleVersion =
+ versionCatalogs
+ .named("libs")
+ .findVersion("checkstyle")
+ .orElseThrow { GradleException("checkstyle version not found in
libs.versions.toml") }
+ .requiredVersion
+ toolVersion = checkstyleVersion
+ configFile = rootProject.file("codestyle/checkstyle.xml")
+ isIgnoreFailures = false
+ maxErrors = 0
+ maxWarnings = 0
}
+// Ensure Checkstyle runs after jandex to avoid task dependency issues
+tasks.withType<Checkstyle>().configureEach { tasks.findByName("jandex")?.let {
mustRunAfter(it) } }
+
tasks.withType(JavaCompile::class.java).configureEach {
options.compilerArgs.addAll(listOf("-Xlint:unchecked", "-Xlint:deprecation"))
options.errorprone.disableAllWarnings = true
diff --git a/build-logic/src/main/kotlin/polaris-spotless.gradle.kts
b/build-logic/src/main/kotlin/polaris-spotless.gradle.kts
index 7e878290e..78119b007 100644
--- a/build-logic/src/main/kotlin/polaris-spotless.gradle.kts
+++ b/build-logic/src/main/kotlin/polaris-spotless.gradle.kts
@@ -18,8 +18,6 @@
*/
import com.diffplug.spotless.FormatterFunc
-import gradle.kotlin.dsl.accessors._fa00c0b20184971a79f32516372275b9.java
-import gradle.kotlin.dsl.accessors._fa00c0b20184971a79f32516372275b9.spotless
import java.io.Serializable
import org.gradle.api.GradleException
diff --git a/codestyle/checkstyle.xml b/codestyle/checkstyle.xml
new file mode 100644
index 000000000..d3986dc3e
--- /dev/null
+++ b/codestyle/checkstyle.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0"?>
+<!--
+ 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.
+-->
+<!DOCTYPE module PUBLIC
+ "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
+ "https://checkstyle.org/dtds/configuration_1_3.dtd">
+
+<module name="Checker">
+ <property name="charset" value="UTF-8"/>
+ <property name="severity" value="warning"/>
+ <property name="fileExtensions" value="java, properties, xml"/>
+
+ <!-- Excludes all 'module-info.java' files -->
+ <!-- See https://checkstyle.org/config_filefilters.html -->
+ <module name="BeforeExecutionExclusionFileFilter">
+ <property name="fileNamePattern" value="module\-info\.java$"/>
+ </module>
+
+ <!-- https://checkstyle.org/config_filters.html#SuppressionFilter -->
+ <module name="SuppressionFilter">
+ <property name="file"
value="${org.checkstyle.google.suppressionfilter.config}"
+ default="checkstyle-suppressions.xml" />
+ <property name="optional" value="true"/>
+ </module>
+
+ <module name="TreeWalker">
+ <!-- Checks for imports -->
+ <!-- See http://checkstyle.org/config_imports.html -->
+ <module name="IllegalImport">
+ <property name="illegalPkgs" value=".*\.shaded\..*, .*\.relocated\..*"/>
+ <property name="regexp" value="true"/>
+ </module>
+
+ </module>
+</module>
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index 0409912ef..127a140d8 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -18,6 +18,7 @@
#
[versions]
+checkstyle = "10.25.0"
hadoop = "3.4.1"
iceberg = "1.9.0" # Ensure to update the iceberg version in regtests to keep
regtests up-to-date
quarkus = "3.21.4"
diff --git a/plugins/spark/v3.5/spark/build.gradle.kts
b/plugins/spark/v3.5/spark/build.gradle.kts
index 8e2f3a354..a2a54e26b 100644
--- a/plugins/spark/v3.5/spark/build.gradle.kts
+++ b/plugins/spark/v3.5/spark/build.gradle.kts
@@ -112,44 +112,6 @@ dependencies {
}
}
-// TODO: replace the check using gradlew checkstyle plugin
-tasks.register("checkNoDisallowedImports") {
- doLast {
- // List of disallowed imports. Right now, we disallow usage of shaded or
- // relocated libraries in the iceberg spark runtime jar.
- val disallowedImports =
- listOf("import org.apache.iceberg.shaded.",
"org.apache.iceberg.relocated.")
-
- // Directory to scan for Java files
- val sourceDirs = listOf(file("src/main/java"), file("src/test/java"))
-
- val violations = mutableListOf<String>()
- // Scan Java files in each directory
- sourceDirs.forEach { sourceDir ->
- fileTree(sourceDir)
- .matching {
- include("**/*.java") // Only include Java files
- }
- .forEach { file ->
- val content = file.readText()
- disallowedImports.forEach { importStatement ->
- if (content.contains(importStatement)) {
- violations.add(
- "Disallowed import found in ${file.relativeTo(projectDir)}:
$importStatement"
- )
- }
- }
- }
- }
-
- if (violations.isNotEmpty()) {
- throw GradleException("Disallowed imports found! $violations")
- }
- }
-}
-
-tasks.named("check") { dependsOn("checkNoDisallowedImports") }
-
tasks.register<ShadowJar>("createPolarisSparkJar") {
archiveClassifier = "bundle"
isZip64 = true
diff --git a/quarkus/test-commons/build.gradle.kts
b/quarkus/test-commons/build.gradle.kts
index 61d26d54c..cb6a40d45 100644
--- a/quarkus/test-commons/build.gradle.kts
+++ b/quarkus/test-commons/build.gradle.kts
@@ -24,9 +24,11 @@ plugins {
}
configurations.all {
- exclude(group = "org.antlr", module = "antlr4-runtime")
- exclude(group = "org.scala-lang", module = "scala-library")
- exclude(group = "org.scala-lang", module = "scala-reflect")
+ if (name != "checkstyle") {
+ exclude(group = "org.antlr", module = "antlr4-runtime")
+ exclude(group = "org.scala-lang", module = "scala-library")
+ exclude(group = "org.scala-lang", module = "scala-reflect")
+ }
}
dependencies {