From b5e414ef64c18c92eb6e8c784747b0706c0e33cb Mon Sep 17 00:00:00 2001 From: Roberto Perez Alcolea Date: Fri, 11 Oct 2019 15:48:35 -0700 Subject: [PATCH 1/3] introduce skippedConfigurationNamesPrefixes to skip configurations such as zinc or incrementalAnalysis* --- .../DependencyLockExtension.groovy | 1 + .../DependencyLockTaskConfigurer.groovy | 5 ++- .../tasks/GenerateLockTask.groovy | 22 ++++++++--- .../tasks/GenerateLockTaskSpec.groovy | 38 +++++++++++++++++++ 4 files changed, 59 insertions(+), 7 deletions(-) diff --git a/src/main/groovy/nebula/plugin/dependencylock/DependencyLockExtension.groovy b/src/main/groovy/nebula/plugin/dependencylock/DependencyLockExtension.groovy index ed14caec..1b15396c 100644 --- a/src/main/groovy/nebula/plugin/dependencylock/DependencyLockExtension.groovy +++ b/src/main/groovy/nebula/plugin/dependencylock/DependencyLockExtension.groovy @@ -19,6 +19,7 @@ class DependencyLockExtension { String lockFile = 'dependencies.lock' String globalLockFile = 'global.lock' Set configurationNames = [] as Set + Set skippedConfigurationNamesPrefixes = [] as Set Closure dependencyFilter = { String group, String name, String version -> true } Set updateDependencies = [] as Set Set skippedDependencies = [] as Set diff --git a/src/main/groovy/nebula/plugin/dependencylock/DependencyLockTaskConfigurer.groovy b/src/main/groovy/nebula/plugin/dependencylock/DependencyLockTaskConfigurer.groovy index 77383ffc..5e2a8595 100644 --- a/src/main/groovy/nebula/plugin/dependencylock/DependencyLockTaskConfigurer.groovy +++ b/src/main/groovy/nebula/plugin/dependencylock/DependencyLockTaskConfigurer.groovy @@ -205,6 +205,7 @@ class DependencyLockTaskConfigurer { new File(project.buildDir, clLockFileName ?: extension.lockFile) } configurationNames = { extension.configurationNames } + skippedConfigurationNames = { extension.skippedConfigurationNamesPrefixes } } lockTask @@ -234,7 +235,7 @@ class DependencyLockTaskConfigurer { def subprojects = project.subprojects.collect { subproject -> def ext = subproject.getExtensions().findByType(DependencyLockExtension) if (ext != null) { - Collection lockableConfigurations = lockableConfigurations(project, subproject, ext.configurationNames) + Collection lockableConfigurations = lockableConfigurations(project, subproject, ext.configurationNames, extension.skippedConfigurationNamesPrefixes) Collection configurations = filterNonLockableConfigurationsAndProvideWarningsForGlobalLockSubproject(subproject, ext.configurationNames, lockableConfigurations) configurations @@ -252,7 +253,7 @@ class DependencyLockTaskConfigurer { def conf = project.configurations.detachedConfiguration(subprojectsArray) project.allprojects.each { it.configurations.add(conf) } - [conf] + lockableConfigurations(project, project, extension.configurationNames) + [conf] + lockableConfigurations(project, project, extension.configurationNames, extension.skippedConfigurationNamesPrefixes) } } diff --git a/src/main/groovy/nebula/plugin/dependencylock/tasks/GenerateLockTask.groovy b/src/main/groovy/nebula/plugin/dependencylock/tasks/GenerateLockTask.groovy index 79fa4b79..9fa55e09 100644 --- a/src/main/groovy/nebula/plugin/dependencylock/tasks/GenerateLockTask.groovy +++ b/src/main/groovy/nebula/plugin/dependencylock/tasks/GenerateLockTask.groovy @@ -40,6 +40,7 @@ class GenerateLockTask extends AbstractLockTask { private String WRITE_CORE_LOCK_TASK_TO_RUN = "`./gradlew dependencies --write-locks`" private String MIGRATE_TO_CORE_LOCK_TASK_NAME = "migrateToCoreLocks" private static final Logger LOGGER = Logging.getLogger(GenerateLockTask) + private static final List DEFAULT_NON_LOCKABLE_CONFIGURATIONS = ['zinc'] @Internal String description = 'Create a lock file in build/' @@ -50,6 +51,9 @@ class GenerateLockTask extends AbstractLockTask { @Internal Set configurationNames + @Internal + Set skippedConfigurationNames + @Internal Closure filter = { group, name, version -> true } @@ -85,15 +89,16 @@ class GenerateLockTask extends AbstractLockTask { if (DependencyLockTaskConfigurer.shouldIgnoreDependencyLock(project)) { throw new DependencyLockException("Dependency locks cannot be generated. The plugin is disabled for this project (dependencyLock.ignore is set to true)") } - Collection confs = getConfigurations() ?: lockableConfigurations(project, project, getConfigurationNames()) + Collection confs = getConfigurations() ?: lockableConfigurations(project, project, getConfigurationNames(), getSkippedConfigurationNames()) Map dependencyMap = new GenerateLockFromConfigurations().lock(confs) new DependencyLockWriter(getDependenciesLock(), getSkippedDependencies()).writeLock(dependencyMap) } - static Collection lockableConfigurations(Project taskProject, Project project, Set configurationNames) { + static Collection lockableConfigurations(Project taskProject, Project project, Set configurationNames, Set skippedConfigurationNamesPrefixes = []) { + List lockableConfigurations = [] if (configurationNames.empty) { if (Configuration.class.declaredMethods.any { it.name == 'isCanBeResolved' }) { - project.configurations.findAll { + lockableConfigurations = project.configurations.findAll { if (taskProject == project) { it.canBeResolved && !ConfigurationFilters.safelyHasAResolutionAlternative(it) } else { @@ -101,11 +106,18 @@ class GenerateLockTask extends AbstractLockTask { } } } else { - project.configurations.asList() + lockableConfigurations = project.configurations.asList() } } else { - configurationNames.collect { project.configurations.getByName(it) } + lockableConfigurations = configurationNames.collect { project.configurations.getByName(it) } + } + + lockableConfigurations.removeAll { + Configuration configuration -> skippedConfigurationNamesPrefixes.any { + String prefix -> configuration.name.startsWith(prefix) + } } + return lockableConfigurations } static Collection filterNonLockableConfigurationsAndProvideWarningsForGlobalLockSubproject(Project subproject, Set configurationNames, Collection lockableConfigurations) { diff --git a/src/test/groovy/nebula/plugin/dependencylock/tasks/GenerateLockTaskSpec.groovy b/src/test/groovy/nebula/plugin/dependencylock/tasks/GenerateLockTaskSpec.groovy index 571b3bed..45b9e595 100644 --- a/src/test/groovy/nebula/plugin/dependencylock/tasks/GenerateLockTaskSpec.groovy +++ b/src/test/groovy/nebula/plugin/dependencylock/tasks/GenerateLockTaskSpec.groovy @@ -89,6 +89,44 @@ class GenerateLockTaskSpec extends ProjectSpec { task.dependenciesLock.text == lockText } + def 'simple lock for all lockable configurations - without skippedConfigurationsPrefixes'() { + project.apply plugin: 'java' + + project.repositories { maven { url Fixture.repo } } + project.configurations { + zinc + incrementalAnalysisTest + } + project.dependencies { + zinc 'test.example:foo:2.+' + incrementalAnalysisTest 'test.example:foo:2.+' + implementation 'test.example:foo:2.+' + } + + GenerateLockTask task = project.tasks.create(taskName, GenerateLockTask) + task.dependenciesLock = new File(project.buildDir, 'dependencies.lock') + task.configurationNames = project.configurations + .stream() + .filter { it.isCanBeResolved() } + .collect { it.name } + .toSet() + task.skippedConfigurationNames = ['zinc', 'incrementalAnalysis'] + + when: + task.lock() + + then: + String lockText = LockGenerator.duplicateIntoConfigsWhenUsingImplementationConfigurationOnly( + '''\ + "test.example:foo": { + "locked": "2.0.1", + "requested": "2.+" + }'''.stripIndent()) + task.dependenciesLock.text == lockText + !task.dependenciesLock.text.contains('"zinc"') + !task.dependenciesLock.text.contains('"incrementalAnalysisTest"') + } + def 'skip dependencies via transitives when configured'() { project.apply plugin: 'java' project.repositories { maven { url Fixture.repo } } From 52d68dd5b277069a16f440e0525032feb3a508ff Mon Sep 17 00:00:00 2001 From: Roberto Perez Alcolea Date: Fri, 11 Oct 2019 16:07:21 -0700 Subject: [PATCH 2/3] GenerateLockTask: make lockableConfigurations a Set --- .../nebula/plugin/dependencylock/tasks/GenerateLockTask.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/groovy/nebula/plugin/dependencylock/tasks/GenerateLockTask.groovy b/src/main/groovy/nebula/plugin/dependencylock/tasks/GenerateLockTask.groovy index 9fa55e09..f0adc605 100644 --- a/src/main/groovy/nebula/plugin/dependencylock/tasks/GenerateLockTask.groovy +++ b/src/main/groovy/nebula/plugin/dependencylock/tasks/GenerateLockTask.groovy @@ -95,7 +95,7 @@ class GenerateLockTask extends AbstractLockTask { } static Collection lockableConfigurations(Project taskProject, Project project, Set configurationNames, Set skippedConfigurationNamesPrefixes = []) { - List lockableConfigurations = [] + Set lockableConfigurations = [] if (configurationNames.empty) { if (Configuration.class.declaredMethods.any { it.name == 'isCanBeResolved' }) { lockableConfigurations = project.configurations.findAll { From 1ac0d6f31b80da8efeec8b76b10c559c460fcaea Mon Sep 17 00:00:00 2001 From: Roberto Perez Alcolea Date: Fri, 11 Oct 2019 16:07:55 -0700 Subject: [PATCH 3/3] GenerateLockTask: make lockableConfigurations a Set --- .../plugin/dependencylock/tasks/GenerateLockTask.groovy | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/groovy/nebula/plugin/dependencylock/tasks/GenerateLockTask.groovy b/src/main/groovy/nebula/plugin/dependencylock/tasks/GenerateLockTask.groovy index f0adc605..fdf7f305 100644 --- a/src/main/groovy/nebula/plugin/dependencylock/tasks/GenerateLockTask.groovy +++ b/src/main/groovy/nebula/plugin/dependencylock/tasks/GenerateLockTask.groovy @@ -98,7 +98,7 @@ class GenerateLockTask extends AbstractLockTask { Set lockableConfigurations = [] if (configurationNames.empty) { if (Configuration.class.declaredMethods.any { it.name == 'isCanBeResolved' }) { - lockableConfigurations = project.configurations.findAll { + lockableConfigurations.addAll project.configurations.findAll { if (taskProject == project) { it.canBeResolved && !ConfigurationFilters.safelyHasAResolutionAlternative(it) } else { @@ -106,10 +106,10 @@ class GenerateLockTask extends AbstractLockTask { } } } else { - lockableConfigurations = project.configurations.asList() + lockableConfigurations.addAll project.configurations.asList() } } else { - lockableConfigurations = configurationNames.collect { project.configurations.getByName(it) } + lockableConfigurations.addAll configurationNames.collect { project.configurations.getByName(it) } } lockableConfigurations.removeAll {