99import org .gradle .api .file .FileSystemLocation ;
1010import org .gradle .api .file .FileSystemLocationProperty ;
1111import org .gradle .api .file .ProjectLayout ;
12+ import org .gradle .api .provider .ListProperty ;
1213import org .gradle .api .provider .Provider ;
1314import org .gradle .api .specs .Spec ;
15+ import org .gradle .api .tasks .Input ;
1416import org .gradle .api .tasks .Internal ;
1517import org .gradle .api .tasks .JavaExec ;
18+ import org .gradle .api .tasks .Optional ;
1619import org .jetbrains .annotations .MustBeInvokedByOverriders ;
1720import org .jetbrains .annotations .Nullable ;
1821
1922import javax .inject .Inject ;
2023import java .io .File ;
24+ import java .util .Collections ;
25+ import java .util .List ;
2126import java .util .Locale ;
2227import java .util .Objects ;
2328
@@ -34,6 +39,11 @@ public abstract class ToolExecBase<P extends EnhancedProblems> extends JavaExec
3439 /// The default tool directory (usage is not required).
3540 protected final DirectoryProperty defaultToolDir ;
3641
42+ /// Additional arguments to use when invoking the tool. Use in configuration instead of [#args].
43+ ///
44+ /// @return The list property for the additional arguments
45+ abstract @ Input @ Optional ListProperty <String > getAdditionalArgs ();
46+
3747 /// The project layout provided by Gradle services.
3848 ///
3949 /// @return The project layout
@@ -98,17 +108,19 @@ private <T extends FileSystemLocation> Transformer<T, T> ensureFileLocationInter
98108 /// This method should be overridden by subclasses to add arguments to this task via [JavaExec#args]. To preserve
99109 /// arguments added by superclasses, this method [must be invoked by overriders][MustBeInvokedByOverriders].
100110 @ MustBeInvokedByOverriders
101- protected void addArguments () { }
111+ protected void addArguments () {
112+ this .args (this .getAdditionalArgs ().getOrElse (Collections .emptyList ()));
113+ }
102114
103115 /// @implNote Not invoking this method from an overriding method *will* result in the tool never being executed and
104116 /// [#addArguments()] never being run.
105117 @ Override
106118 public void exec () {
107- if (this .getArgs ().isEmpty ())
108- this .addArguments ();
109- else
119+ if (!this .getArgs ().isEmpty ())
110120 this .getProblems ().reportToolExecEagerArgs (this );
111121
122+ this .addArguments ();
123+
112124 this .getLogger ().info ("{} {}" , this .getClasspath ().getAsPath (), String .join (" " , this .getArgs ()));
113125
114126 super .exec ();
0 commit comments