Skip to content

Commit

Permalink
GenerateLockTask: configuration cache support
Browse files Browse the repository at this point in the history
  • Loading branch information
rpalcolea committed Aug 21, 2020
1 parent 316e50b commit c2f155b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,9 @@ class DependencyLockTaskConfigurer {
private void setupLockConventionMapping(TaskProvider<GenerateLockTask> task, DependencyLockExtension extension, Map overrideMap) {
task.configure { generateTask ->
generateTask.conventionMapping.with {
ignoreDependencyLock = shouldIgnoreDependencyLock(project)
projectDir = project.projectDir
dependencyLockExtension = extension
skippedDependencies = { extension.skippedDependencies }
includeTransitives = {
project.hasProperty('dependencyLock.includeTransitives') ? Boolean.parseBoolean(project['dependencyLock.includeTransitives'] as String) : extension.includeTransitives
Expand All @@ -263,6 +266,9 @@ class DependencyLockTaskConfigurer {
project.subprojects.each { sub -> sub.repositories.each { repo -> project.repositories.add(repo) } }
}
globalGenerateTask.conventionMapping.with {
ignoreDependencyLock = shouldIgnoreDependencyLock(project)
projectDir = project.projectDir
dependencyLockExtension = extension
dependenciesLock = { globalLockFileInBuildDir }
configurations = {
def subprojects = project.subprojects.collect { subproject ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import org.gradle.api.artifacts.ResolvedDependency
import org.gradle.api.logging.Logger
import org.gradle.api.logging.Logging
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.InputFiles
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.TaskAction
Expand Down Expand Up @@ -70,11 +71,19 @@ class GenerateLockTask extends AbstractLockTask {
@Optional
Boolean includeTransitives = false

@Internal
DependencyLockExtension dependencyLockExtension

@InputFiles
File projectDir

@Input
Boolean ignoreDependencyLock

@TaskAction
void lock() {
if (CoreLocking.isCoreLockingEnabled()) {
def dependencyLockExtension = project.extensions.findByType(DependencyLockExtension)
def globalLockFile = new File(project.projectDir, dependencyLockExtension.globalLockFile)
def globalLockFile = new File(projectDir, dependencyLockExtension.globalLockFile)
if (globalLockFile.exists()) {
throw new BuildCancelledException("Legacy global locks are not supported with core locking.\n" +
"Please remove global locks.\n" +
Expand All @@ -85,7 +94,7 @@ class GenerateLockTask extends AbstractLockTask {
"Please use $WRITE_CORE_LOCK_TASK_TO_RUN\n" +
"or do a one-time migration with `./gradlew $MIGRATE_TO_CORE_LOCK_TASK_NAME` to preserve the current lock state")
}
if (DependencyLockTaskConfigurer.shouldIgnoreDependencyLock(project)) {
if (ignoreDependencyLock) {
throw new DependencyLockException("Dependency locks cannot be generated. The plugin is disabled for this project (dependencyLock.ignore is set to true)")
}
Collection<Configuration> confs = getConfigurations() ?: lockableConfigurations(project, project, getConfigurationNames(), getSkippedConfigurationNames())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1982,4 +1982,18 @@ class DependencyLockLauncherSpec extends IntegrationSpec {
new File(projectDir, 'global.lock').text == globalLockText
}

@Ignore
def 'works with configuration cache'() {
def dependenciesLock = new File(projectDir, 'dependencies.lock')
dependenciesLock << OLD_FOO_LOCK

buildFile << SPECIFIC_BUILD_GRADLE

when:
def result = runTasksSuccessfully('--configuration-cache', 'generateLock', 'saveLock')

then:
result.standardOutput
}

}

0 comments on commit c2f155b

Please sign in to comment.