20
20
import java .util .Properties ;
21
21
import org .gradle .api .Plugin ;
22
22
import org .gradle .api .Project ;
23
- import org .gradle .api .artifacts .Configuration ;
24
- import org .gradle .api .artifacts .DependencySet ;
23
+ import org .gradle .api .artifacts .ConfigurationContainer ;
24
+ import org .gradle .api .artifacts .Dependency ;
25
25
import org .gradle .api .plugins .ReportingBasePlugin ;
26
26
import org .gradle .util .GradleVersion ;
27
27
@@ -45,7 +45,7 @@ public void apply(Project project) {
45
45
46
46
SpotBugsExtension extension = createExtension (project );
47
47
createConfiguration (project , extension );
48
- createPluginConfiguration (project );
48
+ createPluginConfiguration (project . getConfigurations () );
49
49
50
50
String enableWorkerApi = getPropertyOrDefault (project , FEATURE_FLAG_WORKER_API , "true" );
51
51
String enableHybridWorker = getPropertyOrDefault (project , FEATURE_FLAG_HYBRID_WORKER , "true" );
@@ -70,36 +70,39 @@ private SpotBugsExtension createExtension(Project project) {
70
70
private void createConfiguration (Project project , SpotBugsExtension extension ) {
71
71
Properties props = loadProperties ();
72
72
extension .getToolVersion ().convention (props .getProperty ("spotbugs-version" ));
73
-
74
- Configuration configuration =
75
- project
76
- .getConfigurations ()
77
- .create (SpotBugsPlugin .CONFIG_NAME )
78
- .setDescription ("configuration for the SpotBugs engine" )
79
- .setVisible (false )
80
- .setTransitive (true );
81
-
82
- configuration .defaultDependencies (
83
- (DependencySet dependencies ) ->
84
- dependencies .add (
85
- project
86
- .getDependencies ()
87
- .create ("com.github.spotbugs:spotbugs:" + extension .getToolVersion ().get ())));
88
-
89
- Configuration spotbugsSlf4j =
90
- project
91
- .getConfigurations ()
92
- .create (SpotBugsPlugin .SLF4J_CONFIG_NAME )
93
- .setDescription ("configuration for the SLF4J provider to run SpotBugs" )
94
- .setVisible (false )
95
- .setTransitive (true );
96
-
97
- spotbugsSlf4j .defaultDependencies (
98
- (DependencySet dependencies ) ->
99
- dependencies .add (
100
- project
101
- .getDependencies ()
102
- .create ("org.slf4j:slf4j-simple:" + props .getProperty ("slf4j-version" ))));
73
+ ConfigurationContainer configs = project .getConfigurations ();
74
+
75
+ configs .register (
76
+ SpotBugsPlugin .CONFIG_NAME ,
77
+ c -> {
78
+ c .setDescription ("configuration for the SpotBugs engine" );
79
+ c .setVisible (false );
80
+ c .setTransitive (true );
81
+ c .defaultDependencies (
82
+ d -> {
83
+ Dependency dep =
84
+ project
85
+ .getDependencies ()
86
+ .create ("com.github.spotbugs:spotbugs:" + extension .getToolVersion ().get ());
87
+ d .add (dep );
88
+ });
89
+ });
90
+
91
+ configs .register (
92
+ SpotBugsPlugin .SLF4J_CONFIG_NAME ,
93
+ c -> {
94
+ c .setDescription ("configuration for the SLF4J provider to run SpotBugs" );
95
+ c .setVisible (false );
96
+ c .setTransitive (true );
97
+ c .defaultDependencies (
98
+ d -> {
99
+ Dependency dep =
100
+ project
101
+ .getDependencies ()
102
+ .create ("org.slf4j:slf4j-simple:" + props .getProperty ("slf4j-version" ));
103
+ d .add (dep );
104
+ });
105
+ });
103
106
}
104
107
105
108
Properties loadProperties () {
@@ -114,13 +117,14 @@ Properties loadProperties() {
114
117
}
115
118
}
116
119
117
- private Configuration createPluginConfiguration (Project project ) {
118
- return project
119
- .getConfigurations ()
120
- .create (SpotBugsPlugin .PLUGINS_CONFIG_NAME )
121
- .setDescription ("configuration for the external SpotBugs plugins" )
122
- .setVisible (false )
123
- .setTransitive (false );
120
+ private void createPluginConfiguration (ConfigurationContainer configs ) {
121
+ configs .register (
122
+ SpotBugsPlugin .PLUGINS_CONFIG_NAME ,
123
+ c -> {
124
+ c .setDescription ("configuration for the external SpotBugs plugins" );
125
+ c .setVisible (false );
126
+ c .setTransitive (false );
127
+ });
124
128
}
125
129
126
130
void verifyGradleVersion (GradleVersion version ) {
0 commit comments