@@ -4,10 +4,13 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
44import dev.slne.surf.surfapi.gradle.SurfCloudModules
55import dev.slne.surf.surfapi.gradle.generated.Constants
66import dev.slne.surf.surfapi.gradle.platform.SurfApiPlatform
7+ import dev.slne.surf.surfapi.gradle.platform.core.CoreSurfExtension
78import dev.slne.surf.surfapi.gradle.platform.core.tasks.generateExposedMigrationScript
89import dev.slne.surf.surfapi.gradle.util.slnePublic
910import org.gradle.api.Plugin
1011import org.gradle.api.Project
12+ import org.gradle.api.artifacts.component.ProjectComponentIdentifier
13+ import org.gradle.api.artifacts.result.ResolvedDependencyResult
1114import org.gradle.api.model.ObjectFactory
1215import org.gradle.api.plugins.JavaPluginExtension
1316import 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