This is an automated email from the ASF dual-hosted git repository.

yufei 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 6dc114924 Build: Avoid adding duplicated projects for Intelij IDE 
usage (#1333)
6dc114924 is described below

commit 6dc114924af120367b6b61f8c4ed2f7deface70e
Author: gh-yzou <[email protected]>
AuthorDate: Fri Apr 11 16:53:17 2025 -0700

    Build: Avoid adding duplicated projects for Intelij IDE usage (#1333)
---
 .../src/main/kotlin/polaris-java.gradle.kts        |  5 ++
 .../src/main/kotlin/polaris-root.gradle.kts        | 12 ++--
 .../src/main/kotlin/polaris-spotless.gradle.kts    | 65 +++++++++++-----------
 settings.gradle.kts                                | 29 ++++++++--
 4 files changed, 71 insertions(+), 40 deletions(-)

diff --git a/build-logic/src/main/kotlin/polaris-java.gradle.kts 
b/build-logic/src/main/kotlin/polaris-java.gradle.kts
index 06a60a395..63475383a 100644
--- a/build-logic/src/main/kotlin/polaris-java.gradle.kts
+++ b/build-logic/src/main/kotlin/polaris-java.gradle.kts
@@ -37,6 +37,11 @@ plugins {
 
 apply<PublishingHelperPlugin>()
 
+if (project.extra.has("duplicated-project-sources")) {
+  // skip the style check for duplicated projects
+  tasks.withType<Checkstyle>().configureEach { enabled = false }
+}
+
 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-root.gradle.kts 
b/build-logic/src/main/kotlin/polaris-root.gradle.kts
index 96faa07b8..4f7400589 100644
--- a/build-logic/src/main/kotlin/polaris-root.gradle.kts
+++ b/build-logic/src/main/kotlin/polaris-root.gradle.kts
@@ -33,11 +33,13 @@ apply<PublishingHelperPlugin>()
 
 apply<CopiedCodeCheckerPlugin>()
 
-spotless {
-  kotlinGradle {
-    ktfmt().googleStyle()
-    licenseHeaderFile(rootProject.file("codestyle/copyright-header-java.txt"), 
"$")
-    target("*.gradle.kts", "build-logic/*.gradle.kts", 
"build-logic/src/**/*.kt*")
+if (!project.extra.has("duplicated-project-sources")) {
+  spotless {
+    kotlinGradle {
+      ktfmt().googleStyle()
+      
licenseHeaderFile(rootProject.file("codestyle/copyright-header-java.txt"), "$")
+      target("*.gradle.kts", "build-logic/*.gradle.kts", 
"build-logic/src/**/*.kt*")
+    }
   }
 }
 
diff --git a/build-logic/src/main/kotlin/polaris-spotless.gradle.kts 
b/build-logic/src/main/kotlin/polaris-spotless.gradle.kts
index 96f6af87b..86a99fa70 100644
--- a/build-logic/src/main/kotlin/polaris-spotless.gradle.kts
+++ b/build-logic/src/main/kotlin/polaris-spotless.gradle.kts
@@ -25,37 +25,40 @@ import org.gradle.api.GradleException
 
 plugins { id("com.diffplug.spotless") }
 
-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)}")
+// skip spotless check for duplicated projects
+if (!project.extra.has("duplicated-project-sources")) {
+  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()
+    }
+    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"), 
'<^[!?].*$')
+    }
   }
 }
diff --git a/settings.gradle.kts b/settings.gradle.kts
index 3884bea5b..3d658130d 100644
--- a/settings.gradle.kts
+++ b/settings.gradle.kts
@@ -57,18 +57,39 @@ 
loadProperties(file("gradle/projects.main.properties")).forEach { name, director
   polarisProject(name as String, file(directory as String))
 }
 
+val ideaActive = System.getProperty("idea.active").toBoolean()
+
 // load the polaris spark plugin projects
 val polarisSparkDir = "plugins/spark"
 val sparkScalaVersions = 
loadProperties(file("${polarisSparkDir}/spark-scala.properties"))
 val sparkVersions = 
sparkScalaVersions["sparkVersions"].toString().split(",").map { it.trim() }
 
+// records the spark projects that maps to the same project dir
+val noSourceChecksProjects = mutableSetOf<String>()
+
 for (sparkVersion in sparkVersions) {
   val scalaVersions = 
sparkScalaVersions["scalaVersions"].toString().split(",").map { it.trim() }
+  var first = true
   for (scalaVersion in scalaVersions) {
-    polarisProject(
-      "polaris-spark-${sparkVersion}_${scalaVersion}",
-      file("${polarisSparkDir}/v${sparkVersion}"),
-    )
+    val artifactId = "polaris-spark-${sparkVersion}_${scalaVersion}"
+    polarisProject(artifactId, file("${polarisSparkDir}/v${sparkVersion}"))
+    if (first) {
+      first = false
+    } else {
+      noSourceChecksProjects.add(":$artifactId")
+    }
+    // Skip all duplicated spark client projects while using Intelij IDE.
+    // This is to avoid problems during dependency analysis and sync when
+    // using Intelij, like "Multiple projects in this build have project 
directory".
+    if (ideaActive) {
+      break
+    }
+  }
+}
+
+gradle.beforeProject {
+  if (noSourceChecksProjects.contains(this.path)) {
+    project.extra["duplicated-project-sources"] = true
   }
 }
 

Reply via email to