diff --git a/build-logic/src/main/kotlin/polaris-java.gradle.kts b/build-logic/src/main/kotlin/polaris-java.gradle.kts index 06a60a395e..63475383a2 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() +if (project.extra.has("duplicated-project-sources")) { + // skip the style check for duplicated projects + tasks.withType().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 96faa07b82..4f74005891 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() apply() -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 96f6af87b0..86a99fa706 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 3884bea5bc..3d658130d8 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() + 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 } }