Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing parameter to custom Gradle task

I've written simple custom Gradle task that extends DefaultTask and does some action and I would like to pass it some parameter(s) using command line. At the bottom is code for adding task to list of available tasks and "implementation" of the task.

Now, when I execute: ./gradlew customTask -PcustomParam="value" how can I retrieve customParam value in doAction method?

project.tasks.create("customTask", CustomTask::class.java

open class CustomTask : DefaultTask() {
  @TaskAction
  fun doAction() {
    // retrieve passed parameter
  }
}
like image 456
Sven Vidak Avatar asked Jun 20 '26 10:06

Sven Vidak


1 Answers

if (project.hasProperty('customParam')) {
    println project.property('customParam')
}

@see project.property(String name)

like image 77
lance-java Avatar answered Jun 23 '26 13:06

lance-java