Skip to content

Commit 30788df

Browse files
authored
[build] Simplify build logic (#6645)
* Simplify build logic * fix typo
1 parent 77d2fd7 commit 30788df

File tree

9 files changed

+27
-56
lines changed

9 files changed

+27
-56
lines changed

.github/workflows/pr.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ jobs:
7878
gradle-home-cache-cleanup: true
7979
- name: Build with Gradle
8080
run: |
81-
./gradlew -p tests ciBuild
81+
./gradlew -p tests build
82+
./gradlew -p tests checkGitStatus
8283
- name: Collect Diagnostics
8384
if: always()
8485
run: ./scripts/collect-diagnostics.main.kts

build-logic/build.gradle.kts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ plugins {
55
alias(libs.plugins.kotlin.jvm)
66
alias(libs.plugins.kotlin.sam)
77
alias(libs.plugins.compat.patrouille)
8-
id("java-gradle-plugin")
98
}
109

1110
plugins.apply(SamWithReceiverGradleSubplugin::class.java)
1211
extensions.configure(SamWithReceiverExtension::class.java) {
1312
annotations(HasImplicitReceiver::class.qualifiedName!!)
1413
}
1514

16-
group = "com.apollographql.apollo.build"
15+
group = "com.apollographql.apollo"
1716

1817
dependencies {
1918
compileOnly(gradleApi())
@@ -54,19 +53,7 @@ dependencies {
5453
runtimeOnly(libs.kotlinx.binarycompatibilityvalidator)
5554
}
5655

57-
5856
compatPatrouille {
5957
java(17)
6058
kotlin(embeddedKotlinVersion)
6159
}
62-
63-
gradlePlugin {
64-
plugins {
65-
register("build.logic") {
66-
id = "build.logic"
67-
// This plugin is only used for loading the jar using the Marker but never applied
68-
// We don't need it.
69-
implementationClass = "build.logic.Unused"
70-
}
71-
}
72-
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import org.gradle.api.tasks.TaskAction
1313
import org.gradle.api.tasks.TaskProvider
1414
import java.io.File
1515

16-
fun Project.rootSetup(ciBuild: TaskProvider<Task>) {
16+
fun Project.rootSetup() {
1717
val apolloTestAggregationConsumer = configurations.create("apolloTestAggregationConsumer") {
1818
isCanBeConsumed = false
1919
isCanBeResolved = true
@@ -33,7 +33,7 @@ fun Project.rootSetup(ciBuild: TaskProvider<Task>) {
3333
output = file("build/apolloTestAggregation.txt")
3434
}
3535

36-
ciBuild.configure {
36+
tasks.named("build").configure {
3737
dependsOn(task)
3838
}
3939
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,9 @@ fun Project.apolloTest(
137137
configureTesting()
138138
}
139139

140-
fun Project.apolloRoot(ciBuild: TaskProvider<Task>) {
140+
fun Project.apolloRoot() {
141141
configureNode()
142-
rootSetup(ciBuild)
142+
rootSetup()
143143

144144
pluginManager.apply("com.gradleup.nmcp.aggregation")
145145
val nmcpAggregation = extensions.getByType(NmcpAggregationExtension::class.java)

build.gradle.kts

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@ import kotlinx.validation.ExperimentalBCVApi
22
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeHostTest
33

44
plugins {
5-
id("build.logic") apply false
5+
id("base")
6+
}
7+
8+
buildscript {
9+
dependencies {
10+
classpath("com.apollographql.apollo:build-logic")
11+
}
612
}
713

814
apply(plugin = "com.github.ben-manes.versions")
@@ -16,20 +22,6 @@ fun subprojectTasks(name: String): List<Task> {
1622
}
1723
}
1824

19-
fun isTag(): Boolean {
20-
val ref = System.getenv("GITHUB_REF")
21-
22-
return ref?.startsWith("refs/tags/") == true
23-
}
24-
25-
fun shouldPublishSnapshots(): Boolean {
26-
val eventName = System.getenv("GITHUB_EVENT_NAME")
27-
val ref = System.getenv("GITHUB_REF")
28-
29-
return eventName == "push" && (ref == "refs/heads/main")
30-
}
31-
32-
3325
tasks.register("ciTestsGradle") {
3426
description = "Execute the Gradle tests (slow)"
3527
dependsOn(":apollo-gradle-plugin:test")
@@ -76,11 +68,6 @@ tasks.register("ctg") {
7668
dependsOn("ciTestsGradle")
7769
}
7870

79-
val ciBuild = tasks.register("ciBuild") {
80-
description = "Execute the 'build' task in each subproject"
81-
dependsOn(subprojectTasks("build"))
82-
}
83-
8471
tasks.named("dependencyUpdates").configure {
8572
(this as com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask)
8673
rejectVersionIf {
@@ -125,4 +112,4 @@ tasks.register("rmbuild") {
125112
}
126113
}
127114

128-
apolloRoot(ciBuild)
115+
apolloRoot()

settings.gradle.kts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
pluginManagement {
2-
includeBuild("build-logic")
3-
}
4-
51
plugins {
62
id("com.gradle.develocity") version "4.1" // sync with libraries.toml
73
id("com.gradle.common-custom-user-data-gradle-plugin") version "2.3"
@@ -34,5 +30,7 @@ dependencyResolutionManagement {
3430
}
3531
}
3632

33+
includeBuild("build-logic")
34+
3735
apply(from = "./gradle/repositories.gradle.kts")
3836
apply(from = "./gradle/ge.gradle")

tests/build.gradle.kts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
plugins {
2-
id("build.logic") apply false
2+
id("base")
33
}
44

55
buildscript {
66
dependencies {
7+
classpath("com.apollographql.apollo:build-logic")
78
classpath("com.apollographql.apollo:apollo-gradle-plugin")
89
}
910
}
10-
val ciBuild = tasks.register("ciBuild") {
11-
description = """Execute the 'build' task in subprojects and the `termination:run` task too"""
12-
subprojects {
13-
this@register.dependsOn(tasks.matching { it.name == "build" })
14-
}
15-
dependsOn(":termination:run")
11+
12+
tasks.register("checkGitStatus") {
1613
doLast {
1714
checkGitStatus()
1815
}
1916
}
2017

21-
apolloRoot(ciBuild)
18+
apolloRoot()

tests/settings.gradle.kts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
pluginManagement {
2-
includeBuild("../build-logic")
3-
}
4-
51
plugins {
62
id("com.gradle.develocity") version "4.1" // sync with libraries.toml
73
id("com.gradle.common-custom-user-data-gradle-plugin") version "2.3"
@@ -90,6 +86,7 @@ listOf(
9086
project(":$project").projectDir = rootProject.projectDir.resolve(it)
9187
}
9288

89+
includeBuild("../build-logic")
9390
includeBuild("../")
9491

9592
dependencyResolutionManagement {

tests/termination/build.gradle.kts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ apollo {
2020
application {
2121
mainClass.set("termination.MainKt")
2222
}
23+
24+
tasks.named("build").configure {
25+
dependsOn("run")
26+
}

0 commit comments

Comments
 (0)