1919import org .gradle .api .DefaultTask ;
2020import org .gradle .api .NamedDomainObjectContainer ;
2121import org .gradle .api .Project ;
22+ import org .gradle .api .artifacts .Dependency ;
2223import org .gradle .api .file .ConfigurableFileCollection ;
2324import org .gradle .api .file .RegularFileProperty ;
2425import org .gradle .api .model .ObjectFactory ;
2526import org .gradle .api .provider .ListProperty ;
2627import org .gradle .api .provider .MapProperty ;
2728import org .gradle .api .provider .Property ;
2829import org .gradle .api .provider .Provider ;
30+ import org .gradle .api .provider .ProviderConvertible ;
2931import org .gradle .api .tasks .Input ;
3032import org .gradle .api .tasks .InputFiles ;
3133import org .gradle .api .tasks .Optional ;
3840import java .io .IOException ;
3941import java .nio .charset .Charset ;
4042import java .nio .charset .StandardCharsets ;
43+ import java .util .ArrayList ;
4144import java .util .Arrays ;
4245import java .util .Collection ;
4346import java .util .List ;
@@ -51,6 +54,9 @@ public abstract class GenerateUserdevConfig extends DefaultTask {
5154 private DataFunction processor ;
5255 private final MapProperty <String , File > processorData ;
5356 private final Property <String > sourceFileEncoding ;
57+ private final ListProperty <String > extraRuntimeDeps ;
58+ private final ListProperty <String > extraCompileDeps ;
59+ private final ListProperty <String > extraAnnotationProcessorDeps ;
5460
5561 private boolean notchObf = false ;
5662
@@ -68,6 +74,10 @@ public GenerateUserdevConfig(final Project project) {
6874
6975 processorData = objects .mapProperty (String .class , File .class );
7076
77+ extraRuntimeDeps = objects .listProperty (String .class );
78+ extraCompileDeps = objects .listProperty (String .class );
79+ extraAnnotationProcessorDeps = objects .listProperty (String .class );
80+
7181 getOutput ().convention (getProject ().getLayout ().getBuildDirectory ().dir (getName ()).map (d -> d .file ("output.json" )));
7282 }
7383
@@ -103,6 +113,10 @@ public void apply() throws IOException {
103113 json .setNotchObf (notchObf );
104114 json .setSourceFileCharset (getSourceFileEncoding ().get ());
105115 getUniversalFilters ().get ().forEach (json ::addUniversalFilter );
116+ json .extraDependencies = new UserdevConfigV2 .ScopedDependencies ();
117+ json .extraDependencies .compileOnly = new ArrayList <>(getExtraCompileDeps ().get ());
118+ json .extraDependencies .runtimeOnly = new ArrayList <>(getExtraRuntimeDeps ().get ());
119+ json .extraDependencies .annotationProcessor = new ArrayList <>(getExtraAnnotationProcessorDeps ().get ());
106120 }
107121
108122 Files .write (Utils .GSON .toJson (json ).getBytes (StandardCharsets .UTF_8 ), getOutput ().get ().getAsFile ());
@@ -177,6 +191,72 @@ private boolean isV2() {
177191 @ Input
178192 @ Optional
179193 public abstract ListProperty <String > getSRGLines ();
194+
195+ private static String depToString (Dependency value ) {
196+ String group = value .getGroup ();
197+ if (group == null )
198+ throw new IllegalArgumentException ("Dependency group cannot be null" );
199+
200+ String version = value .getVersion ();
201+ if (version == null )
202+ throw new IllegalArgumentException ("Dependency version cannot be null" );
203+
204+ return group + ':' + value .getName () + ':' + version ;
205+ }
206+
207+ @ Input
208+ @ Optional
209+ public ListProperty <String > getExtraCompileDeps () {
210+ return this .extraCompileDeps ;
211+ }
212+
213+ public final void addCompileDependency (Dependency value ) {
214+ this .getExtraCompileDeps ().add (depToString (value ));
215+ }
216+
217+ public final void addCompileDependency (Provider <? extends Dependency > value ) {
218+ this .addCompileDependency (value .get ());
219+ }
220+
221+ public final void addCompileDependency (ProviderConvertible <? extends Dependency > value ) {
222+ this .addCompileDependency (value .asProvider ());
223+ }
224+
225+ @ Input
226+ @ Optional
227+ public ListProperty <String > getExtraRuntimeDeps () {
228+ return this .extraRuntimeDeps ;
229+ }
230+
231+ public final void addRuntimeDependency (Dependency value ) {
232+ this .getExtraRuntimeDeps ().add (depToString (value ));
233+ }
234+
235+ public final void addRuntimeDependency (Provider <? extends Dependency > value ) {
236+ this .addRuntimeDependency (value .get ());
237+ }
238+
239+ public final void addRuntimeDependency (ProviderConvertible <? extends Dependency > value ) {
240+ this .addRuntimeDependency (value .asProvider ());
241+ }
242+
243+ @ Input
244+ @ Optional
245+ public ListProperty <String > getExtraAnnotationProcessorDeps () {
246+ return this .extraAnnotationProcessorDeps ;
247+ }
248+
249+ public final void addAnnotationProcessorDependency (Dependency value ) {
250+ this .getExtraAnnotationProcessorDeps ().add (depToString (value ));
251+ }
252+
253+ public final void addAnnotationProcessorDependency (Provider <? extends Dependency > value ) {
254+ this .addAnnotationProcessorDependency (value .get ());
255+ }
256+
257+ public final void addAnnotationProcessorDependency (ProviderConvertible <? extends Dependency > value ) {
258+ this .addAnnotationProcessorDependency (value .asProvider ());
259+ }
180260
181261 public NamedDomainObjectContainer <RunConfig > runs (@ SuppressWarnings ("rawtypes" ) Closure closure ) {
182262 return runs .configure (closure );
0 commit comments