How can I pass properties to gradle custom task? In ant It will look like this:
public class MyCustomTask extends Task {
private String name;
private String version;
@Override
public void execute() throws BuildException {
// do the job
}
public void setName(String name) {
this.name = name;
}
public void setVersion(String version) {
this.version = version;
}
}
How to do it in gradle?
class MyCustomTask extends DefaultTask {
private String name
private String version
@TaskAction
def build() {
// do the job
}
}
Properties name and version are required and user needs to pass them to task.
Using the -D command-line option, you can pass a system property to the JVM which runs Gradle. The -D option of the gradle command has the same effect as the -D option of the java command. You can also set system properties in gradle.
Try to use ./gradlew -Dorg. gradle. jvmargs=-Xmx16g wrapper , pay attention on -D , this marks the property to be passed to gradle and jvm. Using -P a property is passed as gradle project property.
I found the solution:
class MyCustomTask extends DefaultTask {
@Input
String name
@Input
String version
@TaskAction
def build() {
// do the job
println name
println version
}
}
Example use:
task exampleTask(type: MyCustomTask) {
name = "MyName"
version = "1.0"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With