Skip to content

Commit 72dd4e7

Browse files
committed
Add CheckProhibitedDependenciesLifecyclePlugin
Issue gh-10501
1 parent d146bcb commit 72dd4e7

File tree

4 files changed

+45
-15
lines changed

4 files changed

+45
-15
lines changed

build.gradle

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,3 @@ tasks.register('checkSamples') {
166166
s101 {
167167
configurationDirectory = project.file("etc/s101")
168168
}
169-
170-
tasks.register('checkForProhibitedDependencies', check -> {
171-
check.setGroup(LifecycleBasePlugin.VERIFICATION_GROUP)
172-
check.setDescription("Checks for prohibited dependencies")
173-
})

buildSrc/src/main/groovy/io/spring/gradle/convention/RootProjectPlugin.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import org.gradle.api.Plugin
2121
import org.gradle.api.Project
2222
import org.gradle.api.plugins.BasePlugin
2323
import org.gradle.api.plugins.PluginManager
24+
import org.springframework.gradle.classpath.CheckProhibitedDependenciesLifecyclePlugin
2425
import org.springframework.gradle.maven.SpringNexusPublishPlugin
2526

2627
class RootProjectPlugin implements Plugin<Project> {
@@ -32,6 +33,7 @@ class RootProjectPlugin implements Plugin<Project> {
3233
pluginManager.apply(SchemaPlugin)
3334
pluginManager.apply(NoHttpPlugin)
3435
pluginManager.apply(SpringNexusPublishPlugin)
36+
pluginManager.apply(CheckProhibitedDependenciesLifecyclePlugin)
3537
pluginManager.apply("org.sonarqube")
3638

3739
project.repositories.mavenCentral()

buildSrc/src/main/java/org/springframework/gradle/classpath/CheckClasspathForProhibitedDependenciesPlugin.java

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import org.gradle.api.Plugin;
2020
import org.gradle.api.Project;
21-
import org.gradle.api.Task;
2221
import org.gradle.api.artifacts.Configuration;
2322
import org.gradle.api.artifacts.ConfigurationContainer;
2423
import org.gradle.api.plugins.JavaBasePlugin;
@@ -32,23 +31,16 @@
3231
* @author Rob Winch
3332
*/
3433
public class CheckClasspathForProhibitedDependenciesPlugin implements Plugin<Project> {
35-
public static final String CHECK_PROHIBITED_DEPENDENCIES_TASK_NAME = "checkForProhibitedDependencies";
3634

3735
@Override
3836
public void apply(Project project) {
37+
project.getPlugins().apply(CheckProhibitedDependenciesLifecyclePlugin.class);
3938
project.getPlugins().withType(JavaBasePlugin.class, javaBasePlugin -> {
4039
configureProhibitedDependencyChecks(project);
4140
});
4241
}
4342

4443
private void configureProhibitedDependencyChecks(Project project) {
45-
TaskProvider<Task> checkProhibitedDependencies = project.getTasks().register(CHECK_PROHIBITED_DEPENDENCIES_TASK_NAME, task -> {
46-
task.setGroup(JavaBasePlugin.VERIFICATION_GROUP);
47-
task.setDescription("Checks both the compile/runtime classpath of every SourceSet for prohibited dependencies");
48-
});
49-
project.getTasks().named(JavaBasePlugin.CHECK_TASK_NAME, checkTask -> {
50-
checkTask.dependsOn(checkProhibitedDependencies);
51-
});
5244
SourceSetContainer sourceSets = project.getExtensions().getByType(SourceSetContainer.class);
5345
sourceSets.all((sourceSet) -> createProhibitedDependenciesChecks(project,
5446
sourceSet.getCompileClasspathConfigurationName(), sourceSet.getRuntimeClasspathConfigurationName()));
@@ -70,6 +62,6 @@ private void createProhibitedDependenciesCheck(Configuration classpath, Project
7062
checkClasspath.setDescription("Checks " + classpath.getName() + " for prohibited dependencies");
7163
checkClasspath.setClasspath(classpath);
7264
});
73-
project.getTasks().named(CHECK_PROHIBITED_DEPENDENCIES_TASK_NAME, checkProhibitedTask -> checkProhibitedTask.dependsOn(checkClasspathTask));
65+
project.getTasks().named(CheckProhibitedDependenciesLifecyclePlugin.CHECK_PROHIBITED_DEPENDENCIES_TASK_NAME, checkProhibitedTask -> checkProhibitedTask.dependsOn(checkClasspathTask));
7466
}
7567
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2012-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.gradle.classpath;
18+
19+
import org.gradle.api.Plugin;
20+
import org.gradle.api.Project;
21+
import org.gradle.api.Task;
22+
import org.gradle.api.plugins.JavaBasePlugin;
23+
import org.gradle.api.tasks.TaskProvider;
24+
25+
/**
26+
* @author Rob Winch
27+
*/
28+
public class CheckProhibitedDependenciesLifecyclePlugin implements Plugin<Project> {
29+
public static final String CHECK_PROHIBITED_DEPENDENCIES_TASK_NAME = "checkForProhibitedDependencies";
30+
31+
@Override
32+
public void apply(Project project) {
33+
TaskProvider<Task> checkProhibitedDependencies = project.getTasks().register(CheckProhibitedDependenciesLifecyclePlugin.CHECK_PROHIBITED_DEPENDENCIES_TASK_NAME, task -> {
34+
task.setGroup(JavaBasePlugin.VERIFICATION_GROUP);
35+
task.setDescription("Checks both the compile/runtime classpath of every SourceSet for prohibited dependencies");
36+
});
37+
project.getTasks().named(JavaBasePlugin.CHECK_TASK_NAME, checkTask -> {
38+
checkTask.dependsOn(checkProhibitedDependencies);
39+
});
40+
}
41+
}

0 commit comments

Comments
 (0)