Skip to content

Commit d140576

Browse files
authored
Compatibility with Gradle 9 (#6308)
1 parent 3c29746 commit d140576

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

libraries/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo/gradle/internal/DefaultApolloExtension.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ abstract class DefaultApolloExtension(
5858
schemaFiles = service.schemaFilesSnapshot(project),
5959
graphqlSrcDirs = service.graphqlSourceDirectorySet.srcDirs,
6060
upstreamProjects = service.upstreamDependencies.filterIsInstance<ProjectDependency>().map { it.name }.toSet(),
61-
upstreamProjectPaths = service.upstreamDependencies.filterIsInstance<ProjectDependency>().map { it.dependencyProject.path }.toSet(),
61+
upstreamProjectPaths = service.upstreamDependencies.filterIsInstance<ProjectDependency>().map { it.getPathCompat() }.toSet(),
6262
endpointUrl = service.introspection?.endpointUrl?.orNull,
6363
endpointHeaders = service.introspection?.headers?.orNull,
6464
useSemanticNaming = service.useSemanticNaming.getOrElse(true),
@@ -239,7 +239,7 @@ abstract class DefaultApolloExtension(
239239
check(apolloMetadataConfiguration.dependencies.isEmpty()) {
240240
val projectLines = apolloMetadataConfiguration.dependencies.map {
241241
when (it) {
242-
is ProjectDependency -> "project(\"${it.dependencyProject.path}\")"
242+
is ProjectDependency -> "project(\"${it.getPathCompat()}\")"
243243
is ExternalModuleDependency -> "\"group:artifact:version\""
244244
else -> "project(\":foo\")"
245245

libraries/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo/gradle/internal/DefaultService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ abstract class DefaultService @Inject constructor(val project: Project, override
198198
upstreamDependencies.add(project.dependencies.create(dependencyNotation))
199199
if (bidirectional) {
200200
val upstreamProject = when (dependencyNotation) {
201-
is ProjectDependency -> project.rootProject.project(dependencyNotation.dependencyProject.path)
201+
is ProjectDependency -> project.rootProject.project(dependencyNotation.getPathCompat())
202202
is Project -> dependencyNotation
203203
else -> error("dependsOn(dependencyNotation, true) requires a Project or ProjectDependency")
204204
}

libraries/apollo-gradle-plugin-external/src/main/kotlin/com/apollographql/apollo/gradle/internal/utils.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.apollographql.apollo.gradle.internal
22

33
import com.apollographql.apollo.compiler.InputFile
4+
import org.gradle.api.artifacts.ProjectDependency
45
import org.gradle.api.file.FileCollection
56
import java.io.File
67

@@ -24,3 +25,15 @@ internal fun FileCollection.toInputFiles(): List<InputFile> {
2425
*/
2526
internal fun FileCollection.isolate(): List<Any> = toInputFiles().isolate()
2627
internal fun List<InputFile>.isolate(): List<Any> = flatMap { listOf(it.normalizedPath, it.file) }
28+
29+
30+
internal fun ProjectDependency.getPathCompat(): String {
31+
val method = this::class.java.getDeclaredMethod("getPath")
32+
return if (method != null) {
33+
// Gradle 8.11+ path
34+
// See https://docs.gradle.org/8.11/userguide/upgrading_version_8.html#deprecate_get_dependency_project
35+
method.invoke(this) as String
36+
} else {
37+
dependencyProject.path
38+
}
39+
}

0 commit comments

Comments
 (0)