9
9
import org .gradle .api .file .FileSystemLocation ;
10
10
import org .gradle .api .file .FileSystemLocationProperty ;
11
11
import org .gradle .api .file .ProjectLayout ;
12
+ import org .gradle .api .provider .ListProperty ;
12
13
import org .gradle .api .provider .Provider ;
13
14
import org .gradle .api .specs .Spec ;
15
+ import org .gradle .api .tasks .Input ;
14
16
import org .gradle .api .tasks .Internal ;
15
17
import org .gradle .api .tasks .JavaExec ;
18
+ import org .gradle .api .tasks .Optional ;
16
19
import org .jetbrains .annotations .MustBeInvokedByOverriders ;
17
20
import org .jetbrains .annotations .Nullable ;
18
21
19
22
import javax .inject .Inject ;
20
23
import java .io .File ;
24
+ import java .util .Collections ;
25
+ import java .util .List ;
21
26
import java .util .Locale ;
22
27
import java .util .Objects ;
23
28
@@ -34,6 +39,11 @@ public abstract class ToolExecBase<P extends EnhancedProblems> extends JavaExec
34
39
/// The default tool directory (usage is not required).
35
40
protected final DirectoryProperty defaultToolDir ;
36
41
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
+
37
47
/// The project layout provided by Gradle services.
38
48
///
39
49
/// @return The project layout
@@ -98,17 +108,19 @@ private <T extends FileSystemLocation> Transformer<T, T> ensureFileLocationInter
98
108
/// This method should be overridden by subclasses to add arguments to this task via [JavaExec#args]. To preserve
99
109
/// arguments added by superclasses, this method [must be invoked by overriders][MustBeInvokedByOverriders].
100
110
@ MustBeInvokedByOverriders
101
- protected void addArguments () { }
111
+ protected void addArguments () {
112
+ this .args (this .getAdditionalArgs ().getOrElse (Collections .emptyList ()));
113
+ }
102
114
103
115
/// @implNote Not invoking this method from an overriding method *will* result in the tool never being executed and
104
116
/// [#addArguments()] never being run.
105
117
@ Override
106
118
public void exec () {
107
- if (this .getArgs ().isEmpty ())
108
- this .addArguments ();
109
- else
119
+ if (!this .getArgs ().isEmpty ())
110
120
this .getProblems ().reportToolExecEagerArgs (this );
111
121
122
+ this .addArguments ();
123
+
112
124
this .getLogger ().info ("{} {}" , this .getClasspath ().getAsPath (), String .join (" " , this .getArgs ()));
113
125
114
126
super .exec ();
0 commit comments