Skip to content

Commit 31868ce

Browse files
Merge pull request #292 from nebula-plugins/modernization
Modernization, Phase 4: Configuration avoidance (lazy APIs)
2 parents 480b93e + e7854f4 commit 31868ce

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

src/main/groovy/nebula/plugin/dependencylock/tasks/GenerateLockTask.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ abstract class GenerateLockTask extends AbstractLockTask {
131131
lockableConfigurations.addAll project.configurations.asList()
132132
}
133133
} else {
134-
lockableConfigurations.addAll configurationNames.collect { project.configurations.getByName(it) }
134+
// Use named() for lazy lookup (though we resolve with .get() since we need the actual Configuration)
135+
lockableConfigurations.addAll configurationNames.collect { project.configurations.named(it).get() }
135136
}
136137

137138
lockableConfigurations.removeAll {

src/main/groovy/nebula/plugin/dependencylock/utils/CoreLockingHelper.groovy

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,12 @@ class CoreLockingHelper {
9595

9696
private void findAndLockAdditionalConfigurations(Set<String> configurationNames, Closure closure) {
9797
def additionalConfigNames = gatherAdditionalConfigurationsToLock()
98+
// Use configureEach for lazy configuration (avoids configuring unused configurations)
9899
project.configurations.matching { // returns a live collection
99100
additionalConfigNames.findAll { additionalConfigName ->
100101
it.name == additionalConfigName
101102
}
102-
}.all { it ->
103+
}.configureEach { it ->
103104
runClosureOnConfigurations(configurationNames, closure, additionalConfigNames)
104105
}
105106
}
@@ -142,14 +143,15 @@ class CoreLockingHelper {
142143

143144
void disableCachingWhenUpdatingDependencies() {
144145
if (isUpdatingDependencies) {
145-
project.configurations.all({ Configuration configuration ->
146+
// Use configureEach for lazy configuration (avoids configuring unused configurations)
147+
project.configurations.configureEach { Configuration configuration ->
146148
if (configuration.state == Configuration.State.UNRESOLVED) {
147149
configuration.resolutionStrategy {
148150
cacheDynamicVersionsFor(0, 'seconds')
149151
cacheChangingModulesFor(0, 'seconds')
150152
}
151153
}
152-
})
154+
}
153155
}
154156
}
155157

src/main/kotlin/nebula/plugin/dependencylock/DependencyLockPlugin.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,28 +161,30 @@ class DependencyLockPlugin @Inject constructor(val buildFeatures: BuildFeatures)
161161
disableCachingForGenerateLock()
162162
}
163163

164-
project.configurations.all({ conf ->
164+
// Use configureEach for lazy configuration (avoids configuring unused configurations)
165+
project.configurations.configureEach { conf ->
165166
if (lockAfterEvaluating) {
166167
conf.onResolve {
167168
maybeApplyLock(conf, extension, overrides, globalLockFilename, lockFilename)
168169
}
169170
} else {
170171
maybeApplyLock(conf, extension, overrides, globalLockFilename, lockFilename)
171172
}
172-
})
173+
}
173174
}
174175
}
175176

176177
private fun disableCachingForGenerateLock() {
177178
if (hasGenerationTask(project.gradle.startParameter.taskNames)) {
178-
project.configurations.all({ configuration ->
179+
// Use configureEach for lazy configuration (avoids configuring unused configurations)
180+
project.configurations.configureEach { configuration ->
179181
if (configuration.state == Configuration.State.UNRESOLVED) {
180182
with(configuration.resolutionStrategy) {
181183
cacheDynamicVersionsFor(0, "seconds")
182184
cacheChangingModulesFor(0, "seconds")
183185
}
184186
}
185-
})
187+
}
186188
}
187189
}
188190

src/main/kotlin/nebula/plugin/dependencylock/diff/PathAwareDiffReportGenerator.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ class PathAwareDiffReportGenerator : DiffReportGenerator {
5555

5656
//build paths for all dependencies
5757
val pathStack: Deque<DependencyPathElement> = LinkedList()
58-
val root = DependencyPathElement(project.configurations.getByName(configurationName).incoming.resolutionResult.root, null, null)
58+
// Use named() for lazy lookup (though we resolve with .get() since we need the actual Configuration)
59+
val root = DependencyPathElement(project.configurations.named(configurationName).get().incoming.resolutionResult.root, null, null)
5960
pathStack.add(root)
6061
val visited = mutableSetOf<ResolvedDependencyResult>()
6162
while (!pathStack.isEmpty()) {

src/main/kotlin/nebula/plugin/dependencyverifier/DependencyResolutionVerifier.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,10 @@ class DependencyResolutionVerifier {
165165
val lockedDepsOutOfDate = lockedDepsOutOfDatePerProject[uniqueProjectKey(project)]
166166
val configurationsToExclude = if (configurationsToExcludeOverride.isNotEmpty()) configurationsToExcludeOverride else extension.configurationsToExclude.get()
167167

168+
// Use configureEach for lazy configuration (avoids configuring unused configurations)
168169
task.project.configurations.matching { // returns a live collection
169170
configurationIsResolvedAndMatches(it, configurationsToExclude)
170-
}.all { conf ->
171+
}.configureEach { conf ->
171172
logger.debug("$conf in ${project.name} has state ${conf.state}. Starting dependency resolution verification after task '${task.name}'.")
172173
try {
173174
conf.resolvedConfiguration.rethrowFailure()
@@ -187,10 +188,10 @@ class DependencyResolutionVerifier {
187188
}
188189
}
189190
}
190-
return@all
191+
return@configureEach
191192
} catch (e : Exception) {
192193
logger.warn("Received an unhandled exception: {}", e.message)
193-
return@all
194+
return@configureEach
194195
}
195196

196197
validateThatResolvedVersionIsLockedVersion(conf)

0 commit comments

Comments
 (0)