From a8ef7878ed5495e97362b4ab56d62b5e9618a006 Mon Sep 17 00:00:00 2001 From: Roberto Perez Alcolea Date: Fri, 10 Nov 2023 15:45:19 -0800 Subject: [PATCH 1/2] Enable configuration cache in tests --- .../plugin/dependencylock/DependencyLockTaskConfigurer.groovy | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/groovy/nebula/plugin/dependencylock/DependencyLockTaskConfigurer.groovy b/src/main/groovy/nebula/plugin/dependencylock/DependencyLockTaskConfigurer.groovy index cae9c24..c779be5 100644 --- a/src/main/groovy/nebula/plugin/dependencylock/DependencyLockTaskConfigurer.groovy +++ b/src/main/groovy/nebula/plugin/dependencylock/DependencyLockTaskConfigurer.groovy @@ -217,9 +217,7 @@ class DependencyLockTaskConfigurer { private TaskProvider configureGlobalLockTask(TaskProvider globalLockTask, String lockFilename, DependencyLockExtension extension, Map overridesMap) { globalLockTask.configure { globalGenerateTask -> - globalGenerateTask.doFirst { - project.subprojects.each { sub -> sub.repositories.each { repo -> project.repositories.add(repo) } } - } + project.subprojects.each { sub -> sub.repositories.each { repo -> project.repositories.add(repo) } } includeTransitives.set( project.hasProperty('dependencyLock.includeTransitives') ? Boolean.parseBoolean(project['dependencyLock.includeTransitives'] as String) : extension.includeTransitives.get() ) From 60fba75c06c08b7cdb3f4417accc180c1a9e811c Mon Sep 17 00:00:00 2001 From: Roberto Perez Alcolea Date: Fri, 10 Nov 2023 15:59:47 -0800 Subject: [PATCH 2/2] Enable configuration cache for locking related tests --- .../plugin/BaseIntegrationTestKitSpec.groovy | 10 + ...DependencyLockAlignmentLauncherSpec.groovy | 3 + .../DependencyLockCommitLauncherSpec.groovy | 5 +- .../DependencyLockLauncherSpec.groovy | 8 +- .../tasks/GenerateLockTaskSpec.groovy | 253 +++++++++--------- .../DependencyResolutionVerifierTest.groovy | 3 + 6 files changed, 152 insertions(+), 130 deletions(-) diff --git a/src/test/groovy/nebula/plugin/BaseIntegrationTestKitSpec.groovy b/src/test/groovy/nebula/plugin/BaseIntegrationTestKitSpec.groovy index 6414a14..1e7dd6b 100644 --- a/src/test/groovy/nebula/plugin/BaseIntegrationTestKitSpec.groovy +++ b/src/test/groovy/nebula/plugin/BaseIntegrationTestKitSpec.groovy @@ -4,6 +4,16 @@ import nebula.test.IntegrationTestKitSpec abstract class BaseIntegrationTestKitSpec extends IntegrationTestKitSpec { def setup() { + // Enable configuration cache :) + new File(projectDir, 'gradle.properties') << '''org.gradle.configuration-cache=true'''.stripIndent() + } + void disableConfigurationCache() { + def propertiesFile = new File(projectDir, 'gradle.properties') + if(propertiesFile.exists()) { + propertiesFile.delete() + } + propertiesFile.createNewFile() + propertiesFile << '''org.gradle.configuration-cache=false'''.stripIndent() } } diff --git a/src/test/groovy/nebula/plugin/dependencylock/DependencyLockAlignmentLauncherSpec.groovy b/src/test/groovy/nebula/plugin/dependencylock/DependencyLockAlignmentLauncherSpec.groovy index cdf87df..0c1dedf 100644 --- a/src/test/groovy/nebula/plugin/dependencylock/DependencyLockAlignmentLauncherSpec.groovy +++ b/src/test/groovy/nebula/plugin/dependencylock/DependencyLockAlignmentLauncherSpec.groovy @@ -32,6 +32,9 @@ class DependencyLockAlignmentLauncherSpec extends BaseIntegrationTestKitSpec { def setup() { definePluginOutsideOfPluginBlock = true keepFiles = true + + //TODO make task listener changes for config cache + disableConfigurationCache() } @Unroll diff --git a/src/test/groovy/nebula/plugin/dependencylock/DependencyLockCommitLauncherSpec.groovy b/src/test/groovy/nebula/plugin/dependencylock/DependencyLockCommitLauncherSpec.groovy index 6f036c7..e50723d 100644 --- a/src/test/groovy/nebula/plugin/dependencylock/DependencyLockCommitLauncherSpec.groovy +++ b/src/test/groovy/nebula/plugin/dependencylock/DependencyLockCommitLauncherSpec.groovy @@ -15,13 +15,13 @@ */ package nebula.plugin.dependencylock -import nebula.plugin.BaseIntegrationTestKitSpec import nebula.plugin.dependencylock.dependencyfixture.Fixture +import nebula.test.IntegrationTestKitSpec import org.ajoberstar.grgit.Grgit import java.nio.file.Files -class DependencyLockCommitLauncherSpec extends BaseIntegrationTestKitSpec { +class DependencyLockCommitLauncherSpec extends IntegrationTestKitSpec { protected Grgit git protected Grgit originGit @@ -53,7 +53,6 @@ class DependencyLockCommitLauncherSpec extends BaseIntegrationTestKitSpec { build/ gradle.properties'''.stripIndent() def gradleProperties = new File(projectDir, "gradle.properties") - gradleProperties.createNewFile() gradleProperties << "systemProp.nebula.features.coreLockingSupport=false" // Enable configuration cache :) gradleProperties << '''org.gradle.configuration-cache=true'''.stripIndent() diff --git a/src/test/groovy/nebula/plugin/dependencylock/DependencyLockLauncherSpec.groovy b/src/test/groovy/nebula/plugin/dependencylock/DependencyLockLauncherSpec.groovy index a61ddb4..c92a2e3 100644 --- a/src/test/groovy/nebula/plugin/dependencylock/DependencyLockLauncherSpec.groovy +++ b/src/test/groovy/nebula/plugin/dependencylock/DependencyLockLauncherSpec.groovy @@ -18,7 +18,6 @@ import nebula.plugin.BaseIntegrationTestKitSpec import nebula.plugin.dependencylock.dependencyfixture.Fixture import nebula.plugin.dependencylock.util.LockGenerator import nebula.plugin.dependencylock.utils.GradleVersionUtils -import nebula.test.IntegrationTestKitSpec import nebula.test.dependencies.DependencyGraphBuilder import nebula.test.dependencies.GradleDependencyGenerator import nebula.test.dependencies.ModuleBuilder @@ -446,6 +445,9 @@ class DependencyLockLauncherSpec extends BaseIntegrationTestKitSpec { dependenciesLock << PRE_DIFF_FOO_LOCK buildFile << BUILD_GRADLE + //TODO make diff lock config cache compatible + disableConfigurationCache() + when: runTasks('generateLock', 'diffLock') @@ -1056,6 +1058,8 @@ class DependencyLockLauncherSpec extends BaseIntegrationTestKitSpec { } '''.stripIndent()) + //TODO make diff lock config cache compatible + disableConfigurationCache() when: runTasks('generateLock', 'diffLock') @@ -1071,6 +1075,8 @@ class DependencyLockLauncherSpec extends BaseIntegrationTestKitSpec { } def 'diffLock in multiproject with no locks'() { + //TODO make diff lock config cache compatible + disableConfigurationCache() setupCommonMultiproject() when: diff --git a/src/test/groovy/nebula/plugin/dependencylock/tasks/GenerateLockTaskSpec.groovy b/src/test/groovy/nebula/plugin/dependencylock/tasks/GenerateLockTaskSpec.groovy index b81a1ef..9943a1f 100644 --- a/src/test/groovy/nebula/plugin/dependencylock/tasks/GenerateLockTaskSpec.groovy +++ b/src/test/groovy/nebula/plugin/dependencylock/tasks/GenerateLockTaskSpec.groovy @@ -45,15 +45,16 @@ class GenerateLockTaskSpec extends ProjectSpec { task.dependenciesLock.set new File(project.layout.buildDirectory.getAsFile().get(), 'dependencies.lock') task.configurationNames.set(['testRuntimeClasspath']) task.configure { generateLockTask -> - generateLockTask.conventionMapping.with { - configurationResolutionData = lockableConfigurations(project, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { - new ConfigurationResolutionData( - it.name, - it.incoming.resolutionResult.getAllDependencies(), - it.incoming.resolutionResult.rootComponent - ) - } - } + generateLockTask.configurationResolutionData.set( + lockableConfigurations(project, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { + new ConfigurationResolutionData( + it.name, + it.incoming.resolutionResult.getAllDependencies(), + it.incoming.resolutionResult.rootComponent + ) + } + ) + } when: @@ -92,15 +93,15 @@ class GenerateLockTaskSpec extends ProjectSpec { task.configurationNames.set configurationNames task.configure { generateLockTask -> - generateLockTask.conventionMapping.with { - configurationResolutionData = lockableConfigurations(project, configurationNames).findAll { it.isCanBeResolved() }.collect { - new ConfigurationResolutionData( - it.name, - it.incoming.resolutionResult.getAllDependencies(), - it.incoming.resolutionResult.rootComponent - ) - } - } + generateLockTask.configurationResolutionData.set( + lockableConfigurations(project, configurationNames).findAll { it.isCanBeResolved() }.collect { + new ConfigurationResolutionData( + it.name, + it.incoming.resolutionResult.getAllDependencies(), + it.incoming.resolutionResult.rootComponent + ) + } + ) } when: @@ -140,15 +141,15 @@ class GenerateLockTaskSpec extends ProjectSpec { def skippedConfigurationNames = ['zinc', 'incrementalAnalysis'] as Set task.skippedConfigurationNames.set(skippedConfigurationNames) task.configure { generateLockTask -> - generateLockTask.conventionMapping.with { - configurationResolutionData = lockableConfigurations(project, configurationNames, skippedConfigurationNames).findAll { it.isCanBeResolved() }.collect { - new ConfigurationResolutionData( - it.name, - it.incoming.resolutionResult.getAllDependencies(), - it.incoming.resolutionResult.rootComponent - ) - } - } + generateLockTask.configurationResolutionData.set( + lockableConfigurations(project,configurationNames, skippedConfigurationNames).findAll { it.isCanBeResolved() }.collect { + new ConfigurationResolutionData( + it.name, + it.incoming.resolutionResult.getAllDependencies(), + it.incoming.resolutionResult.rootComponent + ) + } + ) } when: @@ -178,15 +179,15 @@ class GenerateLockTaskSpec extends ProjectSpec { task.skippedDependencies.set(['test.example:foo']) task.includeTransitives.set(true) task.configure { generateLockTask -> - generateLockTask.conventionMapping.with { - configurationResolutionData = lockableConfigurations(project, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { - new ConfigurationResolutionData( - it.name, - it.incoming.resolutionResult.getAllDependencies(), - it.incoming.resolutionResult.rootComponent - ) - } - } + generateLockTask.configurationResolutionData.set( + lockableConfigurations(project, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { + new ConfigurationResolutionData( + it.name, + it.incoming.resolutionResult.getAllDependencies(), + it.incoming.resolutionResult.rootComponent + ) + } + ) } String lockText = '''\ @@ -232,15 +233,15 @@ class GenerateLockTaskSpec extends ProjectSpec { task.dependenciesLock.set(new File(app.layout.buildDirectory.getAsFile().get(), 'dependencies.lock')) task.configurationNames.set( ['testRuntimeClasspath']) task.configure { generateLockTask -> - generateLockTask.conventionMapping.with { - configurationResolutionData = lockableConfigurations(app, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { - new ConfigurationResolutionData( - it.name, - it.incoming.resolutionResult.getAllDependencies(), - it.incoming.resolutionResult.rootComponent - ) - } - } + generateLockTask.configurationResolutionData.set( + lockableConfigurations(project, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { + new ConfigurationResolutionData( + it.name, + it.incoming.resolutionResult.getAllDependencies(), + it.incoming.resolutionResult.rootComponent + ) + } + ) } task.peers.set(app.rootProject.allprojects.collect { new LockKey(group: it.group, artifact: it.name) }) @@ -289,15 +290,15 @@ class GenerateLockTaskSpec extends ProjectSpec { task.configurationNames.set(['testRuntimeClasspath']) task.includeTransitives.set(true) task.configure { generateLockTask -> - generateLockTask.conventionMapping.with { - configurationResolutionData = lockableConfigurations(app, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { - new ConfigurationResolutionData( - it.name, - it.incoming.resolutionResult.getAllDependencies(), - it.incoming.resolutionResult.rootComponent - ) - } - } + generateLockTask.configurationResolutionData.set( + lockableConfigurations(project, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { + new ConfigurationResolutionData( + it.name, + it.incoming.resolutionResult.getAllDependencies(), + it.incoming.resolutionResult.rootComponent + ) + } + ) } task.peers.set(app.rootProject.allprojects.collect { new LockKey(group: it.group, artifact: it.name) }) @@ -354,15 +355,15 @@ class GenerateLockTaskSpec extends ProjectSpec { task.dependenciesLock.set new File(app.layout.buildDirectory.getAsFile().get(), 'dependencies.lock') task.configurationNames.set(['testRuntimeClasspath']) task.configure { generateLockTask -> - generateLockTask.conventionMapping.with { - configurationResolutionData = lockableConfigurations(app, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { - new ConfigurationResolutionData( - it.name, - it.incoming.resolutionResult.getAllDependencies(), - it.incoming.resolutionResult.rootComponent - ) - } - } + generateLockTask.configurationResolutionData.set( + lockableConfigurations(project, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { + new ConfigurationResolutionData( + it.name, + it.incoming.resolutionResult.getAllDependencies(), + it.incoming.resolutionResult.rootComponent + ) + } + ) } task.peers.set(app.rootProject.allprojects.collect { new LockKey(group: it.group, artifact: it.name) }) @@ -440,15 +441,15 @@ class GenerateLockTaskSpec extends ProjectSpec { task.dependenciesLock.set new File(app.layout.buildDirectory.getAsFile().get(), 'dependencies.lock') task.configurationNames.set(['testRuntimeClasspath']) task.configure { generateLockTask -> - generateLockTask.conventionMapping.with { - configurationResolutionData = lockableConfigurations(app, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { - new ConfigurationResolutionData( - it.name, - it.incoming.resolutionResult.getAllDependencies(), - it.incoming.resolutionResult.rootComponent - ) - } - } + generateLockTask.configurationResolutionData.set( + lockableConfigurations(project, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { + new ConfigurationResolutionData( + it.name, + it.incoming.resolutionResult.getAllDependencies(), + it.incoming.resolutionResult.rootComponent + ) + } + ) } task.peers.set(app.rootProject.allprojects.collect { new LockKey(group: it.group, artifact: it.name) }) @@ -499,15 +500,15 @@ class GenerateLockTaskSpec extends ProjectSpec { task.configurationNames.set(['testRuntimeClasspath']) task.includeTransitives.set true task.configure { generateLockTask -> - generateLockTask.conventionMapping.with { - configurationResolutionData = lockableConfigurations(project, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { - new ConfigurationResolutionData( - it.name, - it.incoming.resolutionResult.getAllDependencies(), - it.incoming.resolutionResult.rootComponent - ) - } - } + generateLockTask.configurationResolutionData.set( + lockableConfigurations(project, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { + new ConfigurationResolutionData( + it.name, + it.incoming.resolutionResult.getAllDependencies(), + it.incoming.resolutionResult.rootComponent + ) + } + ) } when: @@ -544,15 +545,15 @@ class GenerateLockTaskSpec extends ProjectSpec { task.configurationNames.set(['testRuntimeClasspath']) task.includeTransitives.set true task.configure { generateLockTask -> - generateLockTask.conventionMapping.with { - configurationResolutionData = lockableConfigurations(project, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { - new ConfigurationResolutionData( - it.name, - it.incoming.resolutionResult.getAllDependencies(), - it.incoming.resolutionResult.rootComponent - ) - } - } + generateLockTask.configurationResolutionData.set( + lockableConfigurations(project, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { + new ConfigurationResolutionData( + it.name, + it.incoming.resolutionResult.getAllDependencies(), + it.incoming.resolutionResult.rootComponent + ) + } + ) } when: @@ -592,15 +593,15 @@ class GenerateLockTaskSpec extends ProjectSpec { task.configurationNames.set(['testRuntimeClasspath']) task.includeTransitives.set true task.configure { generateLockTask -> - generateLockTask.conventionMapping.with { - configurationResolutionData = lockableConfigurations(project, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { - new ConfigurationResolutionData( - it.name, - it.incoming.resolutionResult.getAllDependencies(), - it.incoming.resolutionResult.rootComponent - ) - } - } + generateLockTask.configurationResolutionData.set( + lockableConfigurations(project, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { + new ConfigurationResolutionData( + it.name, + it.incoming.resolutionResult.getAllDependencies(), + it.incoming.resolutionResult.rootComponent + ) + } + ) } when: @@ -645,15 +646,15 @@ class GenerateLockTaskSpec extends ProjectSpec { task.configurationNames.set(['testRuntimeClasspath']) task.includeTransitives.set true task.configure { generateLockTask -> - generateLockTask.conventionMapping.with { - configurationResolutionData = lockableConfigurations(project, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { - new ConfigurationResolutionData( - it.name, - it.incoming.resolutionResult.getAllDependencies(), - it.incoming.resolutionResult.rootComponent - ) - } - } + generateLockTask.configurationResolutionData.set( + lockableConfigurations(project, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { + new ConfigurationResolutionData( + it.name, + it.incoming.resolutionResult.getAllDependencies(), + it.incoming.resolutionResult.rootComponent + ) + } + ) } when: task.lock() @@ -699,15 +700,15 @@ class GenerateLockTaskSpec extends ProjectSpec { task.configurationNames.set(['testRuntimeClasspath']) task.includeTransitives.set true task.configure { generateLockTask -> - generateLockTask.conventionMapping.with { - configurationResolutionData = lockableConfigurations(project, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { - new ConfigurationResolutionData( - it.name, - it.incoming.resolutionResult.getAllDependencies(), - it.incoming.resolutionResult.rootComponent - ) - } - } + generateLockTask.configurationResolutionData.set( + lockableConfigurations(project, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { + new ConfigurationResolutionData( + it.name, + it.incoming.resolutionResult.getAllDependencies(), + it.incoming.resolutionResult.rootComponent + ) + } + ) } when: task.lock() @@ -764,15 +765,15 @@ class GenerateLockTaskSpec extends ProjectSpec { task.configurationNames.set(['testRuntimeClasspath']) task.filter.set(filter as Closure) task.configure { generateLockTask -> - generateLockTask.conventionMapping.with { - configurationResolutionData = lockableConfigurations(project, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { - new ConfigurationResolutionData( - it.name, - it.incoming.resolutionResult.getAllDependencies(), - it.incoming.resolutionResult.rootComponent - ) - } - } + generateLockTask.configurationResolutionData.set( + lockableConfigurations(project, ['testRuntimeClasspath'] as Set).findAll { it.isCanBeResolved() }.collect { + new ConfigurationResolutionData( + it.name, + it.incoming.resolutionResult.getAllDependencies(), + it.incoming.resolutionResult.rootComponent + ) + } + ) } when: diff --git a/src/test/groovy/nebula/plugin/dependencyverifier/DependencyResolutionVerifierTest.groovy b/src/test/groovy/nebula/plugin/dependencyverifier/DependencyResolutionVerifierTest.groovy index 35fc1be..0cd6dc0 100644 --- a/src/test/groovy/nebula/plugin/dependencyverifier/DependencyResolutionVerifierTest.groovy +++ b/src/test/groovy/nebula/plugin/dependencyverifier/DependencyResolutionVerifierTest.groovy @@ -46,6 +46,9 @@ class DependencyResolutionVerifierTest extends BaseIntegrationTestKitSpec { def transitiveNotAvailableDep = new File(mavenrepo.getMavenRepoDir(), "transitive/not/available/a") transitiveNotAvailableDep.deleteDir() // to create a missing transitive dependency + + //TODO make task listener changes for config cache + disableConfigurationCache() } @Unroll