35
35
import org .gradle .api .Action ;
36
36
import org .gradle .api .GradleException ;
37
37
import org .gradle .api .Project ;
38
+ import org .gradle .api .artifacts .Configuration ;
38
39
import org .gradle .api .artifacts .Dependency ;
39
40
import org .gradle .api .file .FileCollection ;
40
41
import org .gradle .api .plugins .JavaPlugin ;
@@ -95,7 +96,7 @@ public void givenProjectWithoutLicensesDirButWithDependenciesThenShouldThrowExce
95
96
expectedException .expect (GradleException .class );
96
97
expectedException .expectMessage (containsString ("does not exist, but there are dependencies" ));
97
98
98
- project .getDependencies ().add ("compileClasspath " , dependency );
99
+ project .getDependencies ().add ("someCompileConfiguration " , dependency );
99
100
task .get ().checkDependencies ();
100
101
}
101
102
@@ -113,7 +114,7 @@ public void givenProjectWithDependencyButNoShaFileThenShouldReturnException() th
113
114
createFileIn (licensesDir , "groovy-LICENSE.txt" , PERMISSIVE_LICENSE_TEXT );
114
115
createFileIn (licensesDir , "groovy-NOTICE.txt" , "" );
115
116
116
- project .getDependencies ().add ("compileClasspath " , project .getDependencies ().localGroovy ());
117
+ project .getDependencies ().add ("someCompileConfiguration " , project .getDependencies ().localGroovy ());
117
118
task .get ().checkDependencies ();
118
119
}
119
120
@@ -122,7 +123,7 @@ public void givenProjectWithDependencyButNoLicenseFileThenShouldReturnException(
122
123
expectedException .expect (GradleException .class );
123
124
expectedException .expectMessage (containsString ("Missing LICENSE for " ));
124
125
125
- project .getDependencies ().add ("compileClasspath " , project .getDependencies ().localGroovy ());
126
+ project .getDependencies ().add ("someCompileConfiguration " , project .getDependencies ().localGroovy ());
126
127
127
128
getLicensesDir (project ).mkdir ();
128
129
updateShas .updateShas ();
@@ -134,7 +135,7 @@ public void givenProjectWithDependencyButNoNoticeFileThenShouldReturnException()
134
135
expectedException .expect (GradleException .class );
135
136
expectedException .expectMessage (containsString ("Missing NOTICE for " ));
136
137
137
- project .getDependencies ().add ("compileClasspath " , dependency );
138
+ project .getDependencies ().add ("someCompileConfiguration " , dependency );
138
139
139
140
createFileIn (getLicensesDir (project ), "groovy-LICENSE.txt" , PERMISSIVE_LICENSE_TEXT );
140
141
@@ -147,7 +148,7 @@ public void givenProjectWithStrictDependencyButNoSourcesFileThenShouldReturnExce
147
148
expectedException .expect (GradleException .class );
148
149
expectedException .expectMessage (containsString ("Missing SOURCES for " ));
149
150
150
- project .getDependencies ().add ("compileClasspath " , dependency );
151
+ project .getDependencies ().add ("someCompileConfiguration " , dependency );
151
152
152
153
createFileIn (getLicensesDir (project ), "groovy-LICENSE.txt" , STRICT_LICENSE_TEXT );
153
154
createFileIn (getLicensesDir (project ), "groovy-NOTICE.txt" , "" );
@@ -158,7 +159,7 @@ public void givenProjectWithStrictDependencyButNoSourcesFileThenShouldReturnExce
158
159
159
160
@ Test
160
161
public void givenProjectWithStrictDependencyAndEverythingInOrderThenShouldReturnSilently () throws Exception {
161
- project .getDependencies ().add ("compileClasspath " , dependency );
162
+ project .getDependencies ().add ("someCompileConfiguration " , dependency );
162
163
163
164
createFileIn (getLicensesDir (project ), "groovy-LICENSE.txt" , STRICT_LICENSE_TEXT );
164
165
createFileIn (getLicensesDir (project ), "groovy-NOTICE.txt" , "" );
@@ -174,7 +175,7 @@ public void givenProjectWithStrictDependencyAndEverythingInOrderThenShouldReturn
174
175
175
176
@ Test
176
177
public void givenProjectWithDependencyAndEverythingInOrderThenShouldReturnSilently () throws Exception {
177
- project .getDependencies ().add ("compileClasspath " , dependency );
178
+ project .getDependencies ().add ("someCompileConfiguration " , dependency );
178
179
179
180
File licensesDir = getLicensesDir (project );
180
181
@@ -187,7 +188,7 @@ public void givenProjectWithALicenseButWithoutTheDependencyThenShouldThrowExcept
187
188
expectedException .expect (GradleException .class );
188
189
expectedException .expectMessage (containsString ("Unused license " ));
189
190
190
- project .getDependencies ().add ("compileClasspath " , dependency );
191
+ project .getDependencies ().add ("someCompileConfiguration " , dependency );
191
192
192
193
File licensesDir = getLicensesDir (project );
193
194
createAllDefaultDependencyFiles (licensesDir , "groovy" , "javaparser-core" );
@@ -201,7 +202,7 @@ public void givenProjectWithANoticeButWithoutTheDependencyThenShouldThrowExcepti
201
202
expectedException .expect (GradleException .class );
202
203
expectedException .expectMessage (containsString ("Unused notice " ));
203
204
204
- project .getDependencies ().add ("compileClasspath " , dependency );
205
+ project .getDependencies ().add ("someCompileConfiguration " , dependency );
205
206
206
207
File licensesDir = getLicensesDir (project );
207
208
createAllDefaultDependencyFiles (licensesDir , "groovy" , "javaparser-core" );
@@ -215,7 +216,7 @@ public void givenProjectWithAShaButWithoutTheDependencyThenShouldThrowException(
215
216
expectedException .expect (GradleException .class );
216
217
expectedException .expectMessage (containsString ("Unused sha files found: \n " ));
217
218
218
- project .getDependencies ().add ("compileClasspath " , dependency );
219
+ project .getDependencies ().add ("someCompileConfiguration " , dependency );
219
220
220
221
File licensesDir = getLicensesDir (project );
221
222
createAllDefaultDependencyFiles (licensesDir , "groovy" , "javaparser-core" );
@@ -229,7 +230,7 @@ public void givenProjectWithADependencyWithWrongShaThenShouldThrowException() th
229
230
expectedException .expect (GradleException .class );
230
231
expectedException .expectMessage (containsString ("SHA has changed! Expected " ));
231
232
232
- project .getDependencies ().add ("compileClasspath " , dependency );
233
+ project .getDependencies ().add ("someCompileConfiguration " , dependency );
233
234
234
235
File licensesDir = getLicensesDir (project );
235
236
createAllDefaultDependencyFiles (licensesDir , "groovy" );
@@ -243,7 +244,7 @@ public void givenProjectWithADependencyWithWrongShaThenShouldThrowException() th
243
244
244
245
@ Test
245
246
public void givenProjectWithADependencyMappingThenShouldReturnSilently () throws Exception {
246
- project .getDependencies ().add ("compileClasspath " , dependency );
247
+ project .getDependencies ().add ("someCompileConfiguration " , dependency );
247
248
248
249
File licensesDir = getLicensesDir (project );
249
250
createAllDefaultDependencyFiles (licensesDir , "groovy" , "javaparser" );
@@ -258,7 +259,7 @@ public void givenProjectWithADependencyMappingThenShouldReturnSilently() throws
258
259
259
260
@ Test
260
261
public void givenProjectWithAIgnoreShaConfigurationAndNoShaFileThenShouldReturnSilently () throws Exception {
261
- project .getDependencies ().add ("compileClasspath " , dependency );
262
+ project .getDependencies ().add ("someCompileConfiguration " , dependency );
262
263
263
264
File licensesDir = getLicensesDir (project );
264
265
createFileIn (licensesDir , "groovy-LICENSE.txt" , PERMISSIVE_LICENSE_TEXT );
@@ -297,6 +298,11 @@ private Project createProject() {
297
298
Project project = ProjectBuilder .builder ().build ();
298
299
project .getPlugins ().apply (JavaPlugin .class );
299
300
301
+ Configuration compileClasspath = project .getConfigurations ().getByName ("compileClasspath" );
302
+ Configuration someCompileConfiguration = project .getConfigurations ().create ("someCompileConfiguration" );
303
+ // Declare a configuration that is going to resolve the compile classpath of the application
304
+ project .getConfigurations ().add (compileClasspath .extendsFrom (someCompileConfiguration ));
305
+
300
306
return project ;
301
307
}
302
308
0 commit comments