title: Executing command with input in custom gradle task
body: <p>I'm writing a custom Gradle task that should execute a bash command. Simple enough, however, I need to pass input arguments from the task to the executed script.</p>
  <p>I have tried a few approaches so far (simplified examples)</p>
  <pre><code>class MyAwesomeTask extends Exec {
      @Input
      @Option(option=&quot;myArg1&quot;, description=&quot;Argument 1&quot;)
      String myArg1
      @Input
      @Option(option=&quot;myArg2&quot;, description=&quot;Argument 2&quot;)
      String myArg2
      @Input
      String otherArg
  
      /*
       * APPROACH #1: Use the task constructor
       */
      MyAwesomeTask() {
          commandLine 'sh', './my_script.sh', '-a', &quot;${myArg1}&quot;, '-b', &quot;${myArg2}&quot;, '-z', &quot;${otherArg}&quot;
      }
  
      /*
       * APPROACH #2: Use a TaskAction
       */
      @TaskAction
      void doWork() {
          commandLine 'sh', './my_script.sh', '-a', &quot;${myArg1}&quot;, '-b', &quot;${myArg2}&quot;, '-z', &quot;${otherArg}&quot;
      }
  }
  </code></pre>
  <pre><code>task runMyTask(type: MyAwesomeTask) {
      otherArg &quot;${some_variable}&quot;
  }
  </code></pre>
  <p>When I try to execute it this way...</p>
  <pre><code>./gradlew runMyTask --myArg1=foo --myArg2=bar
  </code></pre>
  <p>... both approaches go wrong.</p>
  <p>In approach #1, <code>myArg1</code>, <code>myArg2</code> and <code>otherArg</code> all are <code>null</code>.</p>
  <p>In approach #2, the arguments have the correct values, but the task fails with error message <code>execCommand == null!</code></p>
  <p>As you can see, <code>myArg1</code> and <code>myArg2</code> should be populated with the arguments provided when calling the task. <code>otherArg</code> is populated from a variable in the project. My goal with this is that anything that can be derived from project variables, does not have to be typed in by whoever is going to execute this task. Only the arguments that are different for each execution have to be entered,</p>
  <p>How can I achieve what I'm trying to achieve?</p>