Skip to content

Commit 1bb1e74

Browse files
committed
Add Gradle Lock Plugin
Issue gh-7788
1 parent 06d7443 commit 1bb1e74

File tree

5 files changed

+65
-0
lines changed

5 files changed

+65
-0
lines changed

build.gradle

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ buildscript {
1111
}
1212
}
1313
apply plugin: 'io.spring.nohttp'
14+
apply plugin: 'locks'
1415
apply plugin: 'io.spring.convention.root'
1516

1617
group = 'org.springframework.security'

buildSrc/build.gradle

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ gradlePlugin {
1010
id = "trang"
1111
implementationClass = "trang.TrangPlugin"
1212
}
13+
locks {
14+
id = "locks"
15+
implementationClass = "lock.GlobalLockPlugin"
16+
}
1317
}
1418
}
1519

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package lock;
2+
3+
import org.gradle.api.Plugin;
4+
import org.gradle.api.Project;
5+
6+
/**
7+
* @author Rob Winch
8+
*/
9+
public class GlobalLockPlugin implements Plugin<Project> {
10+
@Override
11+
public void apply(Project project) {
12+
project.getTasks().register("writeLocks", GlobalLockTask.class, writeAll -> {
13+
writeAll.setDescription("Writes the locks for all projects");
14+
});
15+
}
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package lock;
2+
3+
import org.gradle.api.Action;
4+
import org.gradle.api.DefaultTask;
5+
import org.gradle.api.Project;
6+
import org.gradle.api.artifacts.Configuration;
7+
import org.gradle.api.tasks.TaskAction;
8+
9+
import java.util.function.Consumer;
10+
11+
/**
12+
* @author Rob Winch
13+
*/
14+
public class GlobalLockTask extends DefaultTask {
15+
@TaskAction
16+
public void lock() {
17+
Project taskProject = getProject();
18+
if (!taskProject.getGradle().getStartParameter().isWriteDependencyLocks()) {
19+
throw new IllegalStateException("You just specify --write-locks argument");
20+
}
21+
writeLocksFor(taskProject);
22+
taskProject.getSubprojects().forEach(new Consumer<Project>() {
23+
@Override
24+
public void accept(Project subproject) {
25+
writeLocksFor(subproject);
26+
}
27+
});
28+
}
29+
30+
private void writeLocksFor(Project project) {
31+
project.getConfigurations().configureEach(new Action<Configuration>() {
32+
@Override
33+
public void execute(Configuration configuration) {
34+
if (configuration.isCanBeResolved()) {
35+
configuration.resolve();
36+
}
37+
}
38+
});
39+
}
40+
}

gradle/dependency-management.gradle

+4
Original file line numberDiff line numberDiff line change
@@ -117,3 +117,7 @@ dependencies {
117117
management "org.thymeleaf:thymeleaf-spring5:3.0.11.RELEASE"
118118
}
119119
}
120+
121+
dependencyLocking {
122+
lockAllConfigurations()
123+
}

0 commit comments

Comments
 (0)