Skip to content

Commit 78c861c

Browse files
committed
avoid adding duplicated projects for IDE
1 parent 1daf749 commit 78c861c

File tree

4 files changed

+71
-40
lines changed

4 files changed

+71
-40
lines changed

build-logic/src/main/kotlin/polaris-java.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ plugins {
3737

3838
apply<PublishingHelperPlugin>()
3939

40+
if (project.extra.has("duplicated-project-sources")) {
41+
// skip the style check for duplicated projects
42+
tasks.withType<Checkstyle>().configureEach { enabled = false }
43+
}
44+
4045
tasks.withType(JavaCompile::class.java).configureEach {
4146
options.compilerArgs.addAll(listOf("-Xlint:unchecked", "-Xlint:deprecation"))
4247
options.errorprone.disableAllWarnings = true

build-logic/src/main/kotlin/polaris-root.gradle.kts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ apply<PublishingHelperPlugin>()
3333

3434
apply<CopiedCodeCheckerPlugin>()
3535

36-
spotless {
37-
kotlinGradle {
38-
ktfmt().googleStyle()
39-
licenseHeaderFile(rootProject.file("codestyle/copyright-header-java.txt"), "$")
40-
target("*.gradle.kts", "build-logic/*.gradle.kts", "build-logic/src/**/*.kt*")
36+
if (!project.extra.has("duplicated-project-sources")) {
37+
spotless {
38+
kotlinGradle {
39+
ktfmt().googleStyle()
40+
licenseHeaderFile(rootProject.file("codestyle/copyright-header-java.txt"), "$")
41+
target("*.gradle.kts", "build-logic/*.gradle.kts", "build-logic/src/**/*.kt*")
42+
}
4143
}
4244
}
4345

build-logic/src/main/kotlin/polaris-spotless.gradle.kts

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,37 +25,40 @@ import org.gradle.api.GradleException
2525

2626
plugins { id("com.diffplug.spotless") }
2727

28-
spotless {
29-
java {
30-
target("src/*/java/**/*.java")
31-
googleJavaFormat()
32-
licenseHeaderFile(rootProject.file("codestyle/copyright-header-java.txt"))
33-
endWithNewline()
34-
custom(
35-
"disallowWildcardImports",
36-
object : Serializable, FormatterFunc {
37-
override fun apply(text: String): String {
38-
val regex = "~/import .*\\.\\*;/".toRegex()
39-
if (regex.matches(text)) {
40-
throw GradleException("Wildcard imports disallowed - ${regex.findAll(text)}")
28+
// skip spotless check for duplicated projects
29+
if (!project.extra.has("duplicated-project-sources")) {
30+
spotless {
31+
java {
32+
target("src/*/java/**/*.java")
33+
googleJavaFormat()
34+
licenseHeaderFile(rootProject.file("codestyle/copyright-header-java.txt"))
35+
endWithNewline()
36+
custom(
37+
"disallowWildcardImports",
38+
object : Serializable, FormatterFunc {
39+
override fun apply(text: String): String {
40+
val regex = "~/import .*\\.\\*;/".toRegex()
41+
if (regex.matches(text)) {
42+
throw GradleException("Wildcard imports disallowed - ${regex.findAll(text)}")
43+
}
44+
return text
4145
}
42-
return text
43-
}
44-
},
45-
)
46-
toggleOffOn()
47-
}
48-
kotlinGradle {
49-
ktfmt().googleStyle()
50-
licenseHeaderFile(rootProject.file("codestyle/copyright-header-java.txt"), "$")
51-
target("*.gradle.kts")
52-
}
53-
format("xml") {
54-
target("src/**/*.xml", "src/**/*.xsd")
55-
targetExclude("codestyle/copyright-header.xml")
56-
eclipseWtp(com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep.XML)
57-
.configFile(rootProject.file("codestyle/org.eclipse.wst.xml.core.prefs"))
58-
// getting the license-header delimiter right is a bit tricky.
59-
// licenseHeaderFile(rootProject.file("codestyle/copyright-header.xml"), '<^[!?].*$')
46+
},
47+
)
48+
toggleOffOn()
49+
}
50+
kotlinGradle {
51+
ktfmt().googleStyle()
52+
licenseHeaderFile(rootProject.file("codestyle/copyright-header-java.txt"), "$")
53+
target("*.gradle.kts")
54+
}
55+
format("xml") {
56+
target("src/**/*.xml", "src/**/*.xsd")
57+
targetExclude("codestyle/copyright-header.xml")
58+
eclipseWtp(com.diffplug.spotless.extra.wtp.EclipseWtpFormatterStep.XML)
59+
.configFile(rootProject.file("codestyle/org.eclipse.wst.xml.core.prefs"))
60+
// getting the license-header delimiter right is a bit tricky.
61+
// licenseHeaderFile(rootProject.file("codestyle/copyright-header.xml"), '<^[!?].*$')
62+
}
6063
}
6164
}

settings.gradle.kts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,39 @@ loadProperties(file("gradle/projects.main.properties")).forEach { name, director
5757
polarisProject(name as String, file(directory as String))
5858
}
5959

60+
val ideActive = System.getProperty("idea.active").toBoolean()
61+
6062
// load the polaris spark plugin projects
6163
val polarisSparkDir = "plugins/spark"
6264
val sparkScalaVersions = loadProperties(file("${polarisSparkDir}/spark-scala.properties"))
6365
val sparkVersions = sparkScalaVersions["sparkVersions"].toString().split(",").map { it.trim() }
6466

67+
// records the spark projects that maps to the same project dir
68+
val noSourceChecksProjects = mutableSetOf<String>()
69+
6570
for (sparkVersion in sparkVersions) {
6671
val scalaVersions = sparkScalaVersions["scalaVersions"].toString().split(",").map { it.trim() }
72+
var first = true
6773
for (scalaVersion in scalaVersions) {
68-
polarisProject(
69-
"polaris-spark-${sparkVersion}_${scalaVersion}",
70-
file("${polarisSparkDir}/v${sparkVersion}"),
71-
)
74+
val artifactId = "polaris-spark-${sparkVersion}_${scalaVersion}"
75+
polarisProject(artifactId, file("${polarisSparkDir}/v${sparkVersion}"))
76+
if (first) {
77+
first = false
78+
} else {
79+
noSourceChecksProjects.add(":$artifactId")
80+
}
81+
// skip all duplicated spark client projects in IDE to avoid problems
82+
// during Intelij dependency analysis and sync. For example:
83+
// "Multiple projects in this build have project directory".
84+
if (ideActive) {
85+
break
86+
}
87+
}
88+
}
89+
90+
gradle.beforeProject {
91+
if (noSourceChecksProjects.contains(this.path)) {
92+
project.extra["duplicated-project-sources"] = true
7293
}
7394
}
7495

0 commit comments

Comments
 (0)