Skip to content

Commit a52b658

Browse files
committed
feat: enhance dependency resolution and add R2DBC/Redis relocations, update version to 1.8.2
1 parent 7660a1b commit a52b658

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

surf-api-gradle-plugin/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ plugins {
2020
group = groupId
2121
version = buildString {
2222
append(mcVersion)
23-
append("-1.8.1")
23+
append("-1.8.2")
2424
if (snapshot) append("-SNAPSHOT")
2525
}
2626

surf-api-gradle-plugin/src/main/kotlin/dev/slne/surf/surfapi/gradle/platform/common/CommonSurfPlugin.kt

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
44
import dev.slne.surf.surfapi.gradle.SurfCloudModules
55
import dev.slne.surf.surfapi.gradle.generated.Constants
66
import dev.slne.surf.surfapi.gradle.platform.SurfApiPlatform
7+
import dev.slne.surf.surfapi.gradle.platform.core.CoreSurfExtension
78
import dev.slne.surf.surfapi.gradle.platform.core.tasks.generateExposedMigrationScript
89
import dev.slne.surf.surfapi.gradle.util.slnePublic
910
import org.gradle.api.Plugin
1011
import org.gradle.api.Project
12+
import org.gradle.api.artifacts.component.ProjectComponentIdentifier
13+
import org.gradle.api.artifacts.result.ResolvedDependencyResult
1114
import org.gradle.api.model.ObjectFactory
1215
import org.gradle.api.plugins.JavaPluginExtension
1316
import org.gradle.api.publish.PublishingExtension
@@ -116,27 +119,52 @@ abstract class CommonSurfPlugin<E : CommonSurfExtension>(
116119

117120
tasks.withType<ShadowJar>().configureEach {
118121
val depsProvider = project.provider {
119-
project.configurations
122+
val deps = project.configurations
120123
.asSequence()
121124
.filter { it.isCanBeResolved }
122-
.flatMap { cfg ->
123-
cfg.incoming.resolutionResult.allDependencies.asSequence()
124-
}
125-
.map { it.requested.displayName }
126-
.toSet()
125+
.flatMap { cfg -> cfg.incoming.resolutionResult.allDependencies.asSequence() }
126+
.toList()
127+
128+
val artifactNames = deps.map { it.requested.displayName }.toSet()
129+
130+
val projectPaths = deps.mapNotNull { dep ->
131+
(dep as? ResolvedDependencyResult)?.selected?.id
132+
?.let { id -> if (id is ProjectComponentIdentifier) id.projectPath else null }
133+
}.toSet()
134+
135+
Pair(artifactNames, projectPaths)
127136
}
128137

129138
doFirst {
130-
val deps = depsProvider.get()
139+
val (artifactNames, projectPaths) = depsProvider.get()
131140
dependencyDependentRelocations.forEach { (needle, relos) ->
132-
if (deps.any { it.contains(needle) }) {
141+
if (artifactNames.any { it.contains(needle) }) {
133142
logger.lifecycle("Dependency $needle found — applying relocations.")
134143
relos.forEach { (from, to) ->
135144
logger.lifecycle("Relocating $from to $to")
136145
relocate(from, to)
137146
}
138147
}
139148
}
149+
150+
projectPaths.forEach { projPath ->
151+
val depProject = rootProject.findProject(projPath) ?: return@forEach
152+
val coreExt = depProject.extensions.findByType(CoreSurfExtension::class.java)
153+
if (coreExt != null) {
154+
if (coreExt.withSurfDatabaseR2dbc.orNull == true) {
155+
coreExt.surfDatabaseR2dbcRelocation.orNull?.let { relocation ->
156+
logger.lifecycle("Project dependency $projPath requests DB R2DBC relocation -> $relocation")
157+
relocate("dev.slne.surf.database", relocation)
158+
}
159+
}
160+
if (coreExt.withSurfRedis.orNull == true) {
161+
coreExt.surfRedisRelocation.orNull?.let { relocation ->
162+
logger.lifecycle("Project dependency $projPath requests Redis relocation -> $relocation")
163+
relocate("dev.slne.surf.redis", relocation)
164+
}
165+
}
166+
}
167+
}
140168
}
141169
}
142170

0 commit comments

Comments
 (0)