# Can a plugin turn on --write-locks?

**URL:** <https://discuss.gradle.org/t/can-a-plugin-turn-on-write-locks/39570>\
**Category:** Help/Discuss\
**Created:** [April 8, 2021, 6:09pm UTC](https://discuss.gradle.org/t/can-a-plugin-turn-on-write-locks/39570 "2021-04-08T18:09:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![whodevil](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/whodevil/32/9834_2.png) [@whodevil](https://discuss.gradle.org/u/whodevil)\
**Post date:** [April 8, 2021, 6:09pm UTC](https://discuss.gradle.org/t/can-a-plugin-turn-on-write-locks/39570/1 "2021-04-08T18:09:50Z")

</div>

I’d like to be able to have a plugin enable --write-locks dynamically. The api appears to support it, but at the time of writing this, appears to not work for me.

I have something along these lines:

```gradle
public class DependencyLocking implements Plugin<Project> {

  public static final String RESOLVE_AND_LOCK_ALL = "resolveAndLockAll";
  public static final String COMPILE_CLASSPATH = "compileClasspath";
  public static final String RUNTIME_CLASSPATH = "runtimeClasspath";

  @Override
  public void apply(Project project) {
    if(!project.hasProperty("CI")) {
      project.getGradle().getStartParameter().setWriteDependencyLocks(true);
    }
    project.getConfigurations().getByName(COMPILE_CLASSPATH).resolutionStrategy(ResolutionStrategy::activateDependencyLocking);
    project.getConfigurations().getByName(RUNTIME_CLASSPATH).resolutionStrategy(ResolutionStrategy::activateDependencyLocking);
    project.getTasks().register(RESOLVE_AND_LOCK_ALL);

    Task resolveAndLockAll = project.getTasks().getByName(RESOLVE_AND_LOCK_ALL);
    resolveAndLockAll.doFirst((task)-> {
      assert task.getProject().getGradle().getStartParameter().isWriteDependencyLocks();
    });
    resolveAndLockAll.doLast((task) -> {
      resolveConfiguration(project, COMPILE_CLASSPATH);
      resolveConfiguration(project, RUNTIME_CLASSPATH);
    });
  }

  private void resolveConfiguration(Project project, String configurationName) {
    Configuration configuration = project.getConfigurations().getByName(configurationName);
    if(configuration.isCanBeResolved()) {
      configuration.resolve();
    }
  }
}

```

The weird thing is that the assert passes, but the lockfiles are not written.
