Skip to content

Avoid adding duplicated projects for Intelij IDE usage #1333

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

Merged
merged 3 commits into from
Apr 11, 2025
Merged
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
5 changes: 5 additions & 0 deletions build-logic/src/main/kotlin/polaris-java.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@snazy : WDYT? Could this be handled better?

Copy link
Contributor Author

@gh-yzou gh-yzou Apr 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is handled in a similar way as nessie here https://github.com/projectnessie/nessie/blob/efeb22d7982abaa2febcbdce742409e0018780f7/build-logic/src/main/kotlin/nessie-common-src.gradle.kts#L36. I will be happy to accommodate the change if there is a better way to skip the unnecessary checks

}

tasks.withType(JavaCompile::class.java).configureEach {
options.compilerArgs.addAll(listOf("-Xlint:unchecked", "-Xlint:deprecation"))
options.errorprone.disableAllWarnings = true
Expand Down
12 changes: 7 additions & 5 deletions build-logic/src/main/kotlin/polaris-root.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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*")
}
}
}

Expand Down
65 changes: 34 additions & 31 deletions build-logic/src/main/kotlin/polaris-spotless.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"), '<^[!?].*$')
}
}
}
29 changes: 25 additions & 4 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down