Skip to content

Commit 1914140

Browse files
First run of Gradle 9 support (#300)
* First run of Gradle 9 support * Update sample app version * More version upgrades * Cleanup * Whoops * Add logger being passed to project graph
1 parent 5d8e193 commit 1914140

File tree

16 files changed

+58
-54
lines changed

16 files changed

+58
-54
lines changed

.github/workflows/ci_test_and_publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
uses: actions/setup-java@v3
2424
with:
2525
distribution: 'zulu'
26-
java-version: '17'
26+
java-version: '21'
2727

2828
- name: Upload Artifacts
2929
run: ./gradlew publishAllPublicationsToMavenCentralRepository --no-daemon --no-parallel
@@ -60,7 +60,7 @@ jobs:
6060
uses: actions/setup-java@v3
6161
with:
6262
distribution: 'zulu'
63-
java-version: '17'
63+
java-version: '21'
6464
- name: Run tests
6565
uses: reactivecircus/android-emulator-runner@v2
6666
with:

.github/workflows/sample_app.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
uses: actions/setup-java@v3
2121
with:
2222
distribution: 'zulu'
23-
java-version: '17'
23+
java-version: '21'
2424
- name: Build sample
2525
run: |
2626
./gradlew :affectedmoduledetector:publishToMavenLocal

affectedmoduledetector/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ plugins {
99
apply from: rootProject.file("gradle/jacoco.gradle")
1010

1111
java {
12-
sourceCompatibility = JavaVersion.VERSION_11
13-
targetCompatibility = JavaVersion.VERSION_11
12+
sourceCompatibility = JavaVersion.VERSION_21
13+
targetCompatibility = JavaVersion.VERSION_21
1414
}
1515

1616
kotlin {
17-
jvmToolchain(11)
17+
jvmToolchain(21)
1818
}
1919

2020
jacoco {

affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetector.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ abstract class AffectedModuleDetector(protected val logger: Logger?) {
213213
)
214214

215215
logger.lifecycle("projects evaluated")
216-
val projectGraph = ProjectGraph(rootProject)
216+
val projectGraph = ProjectGraph(rootProject, logger.toLogger())
217217
val dependencyTracker = DependencyTracker(rootProject, logger.toLogger())
218218
val provider = setupWithParams(rootProject) { spec ->
219219
val parameters = spec.parameters
@@ -265,7 +265,8 @@ abstract class AffectedModuleDetector(protected val logger: Logger?) {
265265
}
266266

267267
internal fun isProjectEnabled(project: Project): Boolean {
268-
return project.hasProperty(ENABLE_ARG)
268+
val enabledProvider = project.providers.gradleProperty(ENABLE_ARG)
269+
return enabledProvider.isPresent && enabledProvider.get() != "false"
269270
}
270271

271272
private fun getModulesProperty(project: Project): Set<String>? {
@@ -656,7 +657,7 @@ class AffectedModuleDetectorImpl(
656657
}
657658

658659
private fun findContainingProject(filePath: String): ProjectPath? {
659-
return projectGraph.findContainingProject(filePath).also {
660+
return projectGraph.findContainingProject(filePath, logger).also {
660661
logger?.info("search result for $filePath resulted in ${it?.path}")
661662
}
662663
}

affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/DependencyTracker.kt

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,41 @@ import java.io.Serializable
2828
* Utility class that traverses all project dependencies and discover which modules depend on each
2929
* other. This is mainly used by [AffectedModuleDetector] to find out which projects should be run.
3030
*/
31-
class DependencyTracker(rootProject: Project, logger: Logger?) : Serializable {
32-
val dependentList: Map<ProjectPath, Set<ProjectPath>>
31+
class DependencyTracker(private val rootProject: Project, private val logger: Logger?) : Serializable {
3332

34-
init {
33+
private val dependentList: Map<ProjectPath, Set<ProjectPath>> by lazy {
3534
val result = mutableMapOf<ProjectPath, MutableSet<ProjectPath>>()
36-
val stringBuilder = StringBuilder()
3735
rootProject.subprojects.forEach { project ->
36+
logger?.info("checking ${project.path} for dependencies")
3837
project.configurations.forEach { config ->
39-
config.dependencies.filterIsInstance<ProjectDependency>().forEach {
40-
stringBuilder.append(
41-
"there is a dependency from ${project.path} (${config.name}) to " +
42-
it.dependencyProject.path +
43-
"\n"
44-
)
45-
result.getOrPut(it.dependencyProject.projectPath) { mutableSetOf() }.add(project.projectPath)
46-
}
38+
logger?.info("checking config ${project.path}/$config for dependencies")
39+
config
40+
.dependencies
41+
.filterIsInstance<ProjectDependency>()
42+
.forEach {
43+
logger?.info(
44+
"there is a dependency from ${project.projectPath} to " +
45+
it.path,
46+
)
47+
result.getOrPut(ProjectPath(it.path)) { mutableSetOf() }
48+
.add(project.projectPath)
49+
}
4750
}
4851
}
49-
logger?.info(stringBuilder.toString())
50-
dependentList = result
52+
result
5153
}
5254

5355
fun findAllDependents(projectPath: ProjectPath): Set<ProjectPath> {
56+
logger?.info("finding dependents of $projectPath")
5457
val result = mutableSetOf<ProjectPath>()
5558
fun addAllDependents(projectPath: ProjectPath) {
5659
if (result.add(projectPath)) {
5760
dependentList[projectPath]?.forEach(::addAllDependents)
5861
}
5962
}
6063
addAllDependents(projectPath)
61-
// the projectPath isn't a dependent of itself
64+
logger?.info("dependents of $projectPath is $result")
65+
// the project isn't a dependent of itself
6266
return result.minus(projectPath)
6367
}
6468
}

affectedmoduledetector/src/main/kotlin/com/dropbox/affectedmoduledetector/ProjectGraph.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ class ProjectGraph(project: Project, logger: Logger? = null) : Serializable {
7070
return rootNode.find(sections, 0, logger)
7171
}
7272

73-
fun getRootProjectPath(): ProjectPath? {
74-
return rootNode.projectPath
75-
}
76-
7773
val allProjects by lazy {
7874
val result = mutableSetOf<ProjectPath>()
7975
rootNode.addAllProjectPaths(result)
@@ -109,6 +105,10 @@ class ProjectGraph(project: Project, logger: Logger? = null) : Serializable {
109105
}
110106
}
111107
}
108+
109+
fun getRootProjectPath(): ProjectPath? {
110+
return rootNode.projectPath
111+
}
112112
}
113113

114114
fun Project.getSupportRootFolder(): File = project.rootDir

affectedmoduledetector/src/test/kotlin/com/dropbox/affectedmoduledetector/AffectedModuleDetectorIntegrationTest.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,10 @@ class AffectedModuleDetectorIntegrationTest {
5757
"""buildscript {
5858
| repositories {
5959
| google()
60-
| jcenter()
6160
| }
6261
| dependencies {
63-
| classpath "com.android.tools.build:gradle:7.4.0"
64-
| classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.25"
62+
| classpath "com.android.tools.build:gradle:8.6.1"
63+
| classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:2.2.0"
6564
| }
6665
|}
6766
|plugins {
@@ -70,7 +69,6 @@ class AffectedModuleDetectorIntegrationTest {
7069
|allprojects {
7170
| repositories {
7271
| google()
73-
| jcenter()
7472
| }
7573
|}""".trimMargin()
7674
)
@@ -151,11 +149,10 @@ class AffectedModuleDetectorIntegrationTest {
151149
"""buildscript {
152150
| repositories {
153151
| google()
154-
| jcenter()
155152
| }
156153
| dependencies {
157-
| classpath "com.android.tools.build:gradle:7.4.0"
158-
| classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.25"
154+
| classpath "com.android.tools.build:gradle:8.6.1"
155+
| classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:2.2.0"
159156
| }
160157
|}
161158
|plugins {
@@ -167,7 +164,6 @@ class AffectedModuleDetectorIntegrationTest {
167164
|allprojects {
168165
| repositories {
169166
| google()
170-
| jcenter()
171167
| }
172168
|}""".trimMargin()
173169
)

build.gradle

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22
buildscript {
3-
ext.kotlin_version = "1.9.25"
3+
ext.kotlin_version = "2.2.0"
44
repositories {
55
google()
66
mavenCentral()
@@ -13,7 +13,7 @@ buildscript {
1313
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1414
classpath("org.jlleitschuh.gradle:ktlint-gradle:11.4.2")
1515
classpath("org.jacoco:org.jacoco.core:0.8.10")
16-
classpath "com.vanniktech:gradle-maven-publish-plugin:0.19.0"
16+
classpath "com.vanniktech:gradle-maven-publish-plugin:0.34.0"
1717
}
1818
}
1919

@@ -28,8 +28,11 @@ allprojects {
2828

2929
allprojects {
3030
plugins.withId("com.vanniktech.maven.publish") {
31-
mavenPublish {
32-
sonatypeHost = "S01"
31+
mavenPublishing {
32+
// sonatypeHost = "CENTRAL_PORTAL"
33+
publishToMavenCentral()
34+
35+
signAllPublications()
3336
}
3437
}
3538
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ kotlin.code.style=official
2222

2323
# POM
2424
GROUP = com.dropbox.affectedmoduledetector
25-
VERSION_NAME=0.5.1-SNAPSHOT
25+
VERSION_NAME=0.6.0-SNAPSHOT
2626

2727
POM_ARTIFACT_ID = affectedmoduledetector
2828
POM_NAME = Affected Module Detector

gradle/jacoco.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ project.afterEvaluate {
4848

4949
reports {
5050
xml.required = true
51-
xml.destination = file("${buildDir}/reports/jacoco/report.xml")
51+
xml.outputLocation = file("${buildDir}/reports/jacoco/report.xml")
5252
html.required = true
5353
}
5454
}

0 commit comments

Comments
 (0)