title: Pass command line parameters into run task
body: <p><a href="https://stackoverflow.com/a/23689696/1757491">https://stackoverflow.com/a/23689696/1757491</a></p>
  
  <p>I started using some info from the proposed solution from the above answer:
  Application Plugin Approach</p>
  
  <p>(build.gradle) </p>
  
  <pre><code> apply plugin: 'application'
  
   mainClassName = "com.mycompany.MyMain"
   run { 
      /* Need to split the space-delimited value in the exec.args */
     args System.getProperty("exec.args").split()    
  }
  </code></pre>
  
  <p>Command Line:</p>
  
  <pre><code>gradle run -Dexec.args="arg1 arg2 arg3"
  </code></pre>
  
  <p>it works great for its intended purpose but seems to have a side effect.  It makes sense to pass in the command line arguments for run but I have to pass them in for every task for example:</p>
  
  <pre><code>gradle tasks -Dexec.args="arg1 arg2 arg3"
  </code></pre>
  
  <p>If I leave out the </p>
  
  <pre><code>-Dexec.args="arg1 arg2 arg3"
  </code></pre>
  
  <p>I get </p>
  
  <pre><code>"build failed with an exception"
  Where:path\build.gradle line:18 which if where my run{ } is.
  </code></pre>