36
36
import org .gradle .api .DefaultTask ;
37
37
import org .gradle .api .GradleException ;
38
38
import org .gradle .api .InvalidUserDataException ;
39
+ import org .gradle .api .Project ;
39
40
import org .gradle .api .file .FileCollection ;
40
41
import org .gradle .api .logging .Logger ;
41
42
import org .gradle .api .logging .Logging ;
48
49
import org .gradle .api .tasks .OutputDirectory ;
49
50
import org .gradle .api .tasks .TaskAction ;
50
51
52
+ import javax .inject .Inject ;
53
+
51
54
import java .io .File ;
52
55
import java .io .IOException ;
53
56
import java .nio .charset .StandardCharsets ;
@@ -127,7 +130,7 @@ public class DependencyLicensesTask extends DefaultTask {
127
130
/**
128
131
* The directory to find the license and sha files in.
129
132
*/
130
- private File licensesDir = new File ( getProject (). getProjectDir (), "licenses" ) ;
133
+ private File licensesDir ;
131
134
132
135
/**
133
136
* A map of patterns to prefix, used to find the LICENSE and NOTICE file.
@@ -139,6 +142,14 @@ public class DependencyLicensesTask extends DefaultTask {
139
142
*/
140
143
private Set <String > ignoreShas = new HashSet <>();
141
144
145
+ private final Project project ;
146
+
147
+ @ Inject
148
+ public DependencyLicensesTask (Project project ) {
149
+ this .project = project ;
150
+ this .licensesDir = new File (project .getProjectDir (), "licenses" );
151
+ }
152
+
142
153
/**
143
154
* Add a mapping from a regex pattern for the jar name, to a prefix to find
144
155
* the LICENSE and NOTICE file for that jar.
@@ -161,7 +172,7 @@ public void mapping(Map<String, String> props) {
161
172
@ InputFiles
162
173
public Property <FileCollection > getDependencies () {
163
174
if (dependenciesProvider == null ) {
164
- dependenciesProvider = getProject () .getObjects ().property (FileCollection .class );
175
+ dependenciesProvider = project .getObjects ().property (FileCollection .class );
165
176
}
166
177
return dependenciesProvider ;
167
178
}
@@ -250,7 +261,7 @@ public void checkDependencies() throws IOException, NoSuchAlgorithmException {
250
261
// by this output but when successful we can safely mark the task as up-to-date.
251
262
@ OutputDirectory
252
263
public File getOutputMarker () {
253
- return new File (getProject () .getBuildDir (), "dependencyLicense" );
264
+ return new File (project .getBuildDir (), "dependencyLicense" );
254
265
}
255
266
256
267
private void failIfAnyMissing (String item , Boolean exists , String type ) {
0 commit comments