Skip to content

Commit 141de5e

Browse files
authored
Cleanup build configuration (#6717)
* ./gradlew build now passes out of the box * remove cross-project configuration * remove checking modified files in CI * ./gradlew ctng is kept as a shorthand during development
1 parent 41dcf45 commit 141de5e

File tree

15 files changed

+100
-111
lines changed

15 files changed

+100
-111
lines changed

.github/workflows/build-pull-request.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ concurrency:
1616
cancel-in-progress: true
1717

1818
jobs:
19-
tests-gradle:
19+
tests-no-gradle:
2020
if: "!startsWith(github.head_ref, 'release-')"
2121
runs-on: macos-15
2222
steps:
@@ -25,9 +25,9 @@ jobs:
2525
with:
2626
gradle-home-cache-cleanup: true
2727
- run: |
28-
./gradlew ciTestsGradle
28+
./gradlew build -x :apollo-gradle-plugin:test
2929
30-
tests-no-gradle:
30+
tests-gradle:
3131
if: "!startsWith(github.head_ref, 'release-')"
3232
runs-on: macos-15
3333
steps:
@@ -36,7 +36,7 @@ jobs:
3636
with:
3737
gradle-home-cache-cleanup: true
3838
- run: |
39-
./gradlew ciTestsNoGradle --stacktrace
39+
./gradlew :apollo-gradle-plugin:test
4040
4141
tests-integration:
4242
if: "!startsWith(github.head_ref, 'release-')"
@@ -48,7 +48,6 @@ jobs:
4848
gradle-home-cache-cleanup: true
4949
- run: |
5050
./gradlew -p tests build
51-
./gradlew -p tests checkGitStatus
5251
5352
swift-tests:
5453
runs-on: macos-15

build-logic/build.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ dependencies {
5555
runtimeOnly(libs.atomicfu.plugin)
5656

5757
runtimeOnly(libs.sqldelight.plugin)
58-
runtimeOnly(libs.benmanes.versions)
5958
runtimeOnly(libs.gratatouille)
6059
runtimeOnly(libs.kotlinx.binarycompatibilityvalidator)
6160
}

build-logic/src/main/kotlin/GitStatus.kt

Lines changed: 0 additions & 19 deletions
This file was deleted.

build-logic/src/main/kotlin/RootProject.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ fun Project.rootSetup() {
2323
}
2424
}
2525

26-
allprojects.forEach {
27-
dependencies.add("apolloTestAggregationConsumer", it)
26+
allprojects {
27+
val rootProject = this@rootSetup
28+
rootProject.dependencies.add("apolloTestAggregationConsumer", rootProject.dependencies.project(mapOf("path" to path)))
2829
}
2930

3031
val task = tasks.register("apolloTestAggregation", GenerateApolloTestAggregation::class.java) {
31-
binaryTestResults.from(apolloTestAggregationConsumer)
32+
binaryTestResults.from(apolloTestAggregationConsumer.incoming.artifactView { lenient(true) }.files)
3233

3334
output = file("build/apolloTestAggregation.txt")
3435
}

build-logic/src/main/kotlin/TestConventionPlugin.kt

Whitespace-only changes.

build-logic/src/main/kotlin/api.kt

Lines changed: 84 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@ import app.cash.licensee.UnusedAction
33
import com.gradleup.librarian.gradle.Librarian
44
import nmcp.NmcpAggregationExtension
55
import org.gradle.api.Project
6-
import org.gradle.api.Task
7-
import org.gradle.api.tasks.TaskProvider
86
import org.gradle.jvm.tasks.Jar
7+
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmExtension
98
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
109
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
10+
import org.jetbrains.kotlin.gradle.plugin.ExecutionTaskHolder
11+
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
12+
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithSimulatorTests
13+
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinNativeTargetWithTests
14+
import org.jetbrains.kotlin.gradle.plugin.mpp.NativeOutputKind
15+
import org.jetbrains.kotlin.gradle.targets.js.ir.KotlinJsIrTarget
1116
import kotlin.time.Duration.Companion.hours
1217
import kotlin.time.Duration.Companion.minutes
1318
import kotlin.time.toJavaDuration
@@ -31,6 +36,8 @@ fun Project.apolloLibrary(
3136
androidOptions: AndroidOptions? = null,
3237
publish: Boolean = true,
3338
kotlinCompilerOptions: KotlinCompilerOptions = KotlinCompilerOptions(),
39+
contributesCtng: Boolean = true,
40+
enableWasmJsTests: Boolean = true
3441
) {
3542
group = property("GROUP")!!
3643
version = version()
@@ -73,6 +80,61 @@ fun Project.apolloLibrary(
7380
}
7481

7582
configureTesting()
83+
project.kotlinTargets.forEach { target ->
84+
/**
85+
* Disable every native test except the KotlinNativeTargetWithHostTests to save some time
86+
*/
87+
if (target is KotlinNativeTargetWithSimulatorTests || target is KotlinNativeTargetWithTests<*>) {
88+
target.testRuns.configureEach {
89+
this as ExecutionTaskHolder<*>
90+
executionTask.configure {
91+
enabled = false
92+
}
93+
}
94+
target.binaries.configureEach {
95+
if (outputKind == NativeOutputKind.TEST) {
96+
linkTaskProvider.configure {
97+
enabled = false
98+
}
99+
compilation.compileTaskProvider.configure {
100+
enabled = false
101+
}
102+
}
103+
}
104+
}
105+
/**
106+
* Disable wasmJs tests because they are not ready yet
107+
*/
108+
if (!enableWasmJsTests && target is KotlinJsIrTarget && target.wasmTargetType != null) {
109+
target.subTargets.configureEach {
110+
testRuns.configureEach {
111+
executionTask.configure {
112+
enabled = false
113+
}
114+
}
115+
}
116+
target.testRuns.configureEach {
117+
executionTask.configure {
118+
enabled = false
119+
}
120+
}
121+
target.binaries.configureEach {
122+
compilation.compileTaskProvider.configure {
123+
enabled = false
124+
}
125+
}
126+
}
127+
}
128+
/**
129+
* `ctng` is short for CiTestNoGradle. It's a shorthand task that runs all the `build`
130+
* tasks except the Gradle plugin one because it is slow.
131+
* the name is for historical reasons.
132+
*/
133+
tasks.register("ctng") {
134+
if (contributesCtng) {
135+
dependsOn("build")
136+
}
137+
}
76138

77139
tasks.withType(Jar::class.java).configureEach {
78140
manifest {
@@ -98,6 +160,15 @@ fun Project.apolloLibrary(
98160
}
99161
}
100162

163+
private val Project.kotlinTargets: Collection<KotlinTarget>
164+
get() {
165+
when (val kotlin = extensions.getByName("kotlin")) {
166+
is KotlinJvmExtension -> return listOf(kotlin.target)
167+
is KotlinMultiplatformExtension -> return kotlin.targets
168+
else -> return emptyList()
169+
}
170+
}
171+
101172
fun Project.apolloLibrary(
102173
namespace: String,
103174
jvmTarget: Int? = null,
@@ -109,6 +180,8 @@ fun Project.apolloLibrary(
109180
androidOptions: AndroidOptions? = null,
110181
publish: Boolean = true,
111182
kotlinCompilerOptions: KotlinCompilerOptions = KotlinCompilerOptions(),
183+
contributesCtng: Boolean = true,
184+
enableWasmJsTests: Boolean = true,
112185
) {
113186
val defaultTargets = defaultTargets(
114187
withJvm = withJvm,
@@ -120,12 +193,14 @@ fun Project.apolloLibrary(
120193
)
121194

122195
apolloLibrary(
123-
namespace,
124-
jvmTarget,
125-
defaultTargets,
126-
androidOptions,
127-
publish,
128-
kotlinCompilerOptions
196+
namespace = namespace,
197+
jvmTarget = jvmTarget,
198+
defaultTargets = defaultTargets,
199+
androidOptions = androidOptions,
200+
publish = publish,
201+
kotlinCompilerOptions = kotlinCompilerOptions,
202+
contributesCtng = contributesCtng,
203+
enableWasmJsTests = enableWasmJsTests
129204
)
130205
}
131206

@@ -134,7 +209,7 @@ fun Project.apolloTest(
134209
withJvm: Boolean = true,
135210
appleTargets: Set<String> = setOf(hostTarget),
136211
kotlinCompilerOptions: KotlinCompilerOptions = KotlinCompilerOptions(),
137-
jvmTarget: Int? = null
212+
jvmTarget: Int? = null,
138213
) {
139214
apolloTest(
140215
kotlinCompilerOptions = kotlinCompilerOptions,

build.gradle.kts

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import kotlinx.validation.ExperimentalBCVApi
2-
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeHostTest
32

43
plugins {
54
id("base")
@@ -11,70 +10,10 @@ buildscript {
1110
}
1211
}
1312

14-
apply(plugin = "com.github.ben-manes.versions")
1513
apply(plugin = "org.jetbrains.kotlinx.binary-compatibility-validator")
1614

1715
version = property("VERSION_NAME")!!
1816

19-
fun subprojectTasks(name: String): List<Task> {
20-
return subprojects.flatMap { subproject ->
21-
subproject.tasks.matching { it.name == name }
22-
}
23-
}
24-
25-
tasks.register("ciTestsGradle") {
26-
description = "Execute the Gradle tests (slow)"
27-
dependsOn(":apollo-gradle-plugin:test")
28-
}
29-
30-
tasks.register("ciTestsNoGradle") {
31-
description = """Execute all tests from the root project except:
32-
| - the Gradle ones
33-
| - most of the Apple tests. Instead it just executes macosX64 tests to save time
34-
| - the IntelliJ plugin tests - they are run in a dedicated job
35-
""".trimMargin()
36-
37-
38-
subprojects {
39-
if (name !in setOf("apollo-gradle-plugin")) {
40-
dependsOn(tasks.matching { it.name == "test" })
41-
}
42-
dependsOn(tasks.matching { it.name == "jvmTest" })
43-
dependsOn(tasks.matching { it.name == "jsNodeTest" })
44-
dependsOn(tasks.withType(KotlinNativeHostTest::class.java))
45-
dependsOn(tasks.matching { it.name == "apiCheck" })
46-
dependsOn(tasks.matching { it.name == "licensee" })
47-
}
48-
49-
/**
50-
* Update the database schemas in CI
51-
*/
52-
dependsOn(":apollo-normalized-cache-sqlite:generateCommonMainJsonDatabaseSchema")
53-
54-
doLast {
55-
if (isCIBuild()) {
56-
checkGitStatus()
57-
}
58-
}
59-
}
60-
61-
/**
62-
* Shorthands for less typing during development
63-
*/
64-
tasks.register("ctng") {
65-
dependsOn("ciTestsNoGradle")
66-
}
67-
tasks.register("ctg") {
68-
dependsOn("ciTestsGradle")
69-
}
70-
71-
tasks.named("dependencyUpdates").configure {
72-
(this as com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask)
73-
rejectVersionIf {
74-
listOf("alpha", "beta", "rc").any { candidate.version.lowercase().contains(it) }
75-
}
76-
}
77-
7817
configure<kotlinx.validation.ApiValidationExtension> {
7918
@OptIn(ExperimentalBCVApi::class)
8019
klib.enabled = true

gradle/libraries.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ assertj = { group = "org.assertj", name = "assertj-core", version = "3.27.4" }
9090
atomicfu-library = { group = "org.jetbrains.kotlinx", name = "atomicfu", version.ref = "atomicfu" }
9191
atomicfu-plugin = { group = "org.jetbrains.kotlinx", name = "atomicfu-gradle-plugin", version.ref = "atomicfu" }
9292

93-
benmanes-versions = { group = "com.github.ben-manes", name = "gradle-versions-plugin", version = "0.33.0" }
9493
compat-patrouille = { module = "com.gradleup.compat.patrouille:compat-patrouille-gradle-plugin", version.ref = "compat-patrouille" }
9594
compose-runtime = { group = "androidx.compose.runtime", name = "runtime", version.ref = "compose" }
9695
compose-ui = { group = "androidx.compose.ui", name = "ui", version.ref = "compose" }

gradle/repositories.gradle.kts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ listOf(pluginManagement.repositories, dependencyResolutionManagement.repositorie
5050
forRepository(::gradlePluginPortal)
5151
filter {
5252
includeModule("org.jetbrains.kotlinx", "kotlinx-benchmark-plugin")
53-
includeModule("com.github.ben-manes", "gradle-versions-plugin")
5453
includeModule("com.gradle", "develocity-gradle-plugin")
5554
}
5655
}

libraries/apollo-ast/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ plugins {
99

1010
apolloLibrary(
1111
namespace = "com.apollographql.apollo.ast",
12+
enableWasmJsTests = false
1213
)
1314

1415
kotlin {

0 commit comments

Comments
 (0)