title: Problems passing system properties and parameters when running Java class via Gradle
body: <p>I am trying to run a command-line Java app via Gradle as part of a quick integration test. I am porting my build scripts from Maven, where this was easily done via <code>exec-maven-plugin</code>. My two big requirements are:</p>
  
  <ul>
  <li>Being able to pass system properties to the executable Java code </li>
  <li>Being able to pass command-line args to the executable Java code</li>
  </ul>
  
  <p>Please note that I am not trying to read these properties in the build script, I'm trying to read them in the Java program that the script builds and executes.</p>
  
  <p>I have found two other SO posts that address Java program execution via Gradle: <a href="https://stackoverflow.com/questions/16350757/what-is-the-gradle-equivalent-of-mavens-exec-plugin-for-running-java-apps">one with an answer that advocates using <code>apply plugin: "application"</code> in the build file and <code>gradle run</code> at the command line</a>, and <a href="https://stackoverflow.com/questions/21358466/gradle-to-execute-java-class-without-modifying-build-gradle">another with answers advocating that approach as well as using <code>task execute(type:JavaExec)</code> in the build file and <code>gradle execute</code> at the command line</a>.  I have tried both approaches and have not succeeded.</p>
  
  <p>I have two problems:</p>
  
  <p><strong>(1) I cannot get the Java executable to read the system properties</strong> </p>
  
  <p>Whether I do this:</p>
  
  <p><strong>build.gradle</strong>:</p>
  
  <pre><code>apply plugin: 'application'
  mainClassName = "com.mycompany.MyMain"
  </code></pre>
  
  <p><strong>Command line</strong>:</p>
  
  <pre><code>gradle run -Dmyproperty=myvalue
  </code></pre>
  
  <p>Or this:</p>
  
  <p><strong>build.gradle</strong>:</p>
  
  <pre><code>task execute (type:JavaExec) {
      main = "com.mycompany.MyMain"
      classpath = sourceSets.main.runtimeClasspath 
  }
  </code></pre>
  
  <p><strong>Command line</strong>:</p>
  
  <pre><code>gradle execute -Dmyproperty=myvalue
  </code></pre>
  
  <p>In either case, <code>myproperty</code> does not make it through.  The code that begins running from <code>MyMain.main (...)</code> reads the <code>myproperty</code> system property as null/missing.</p>
  
  <p><strong>(2) I cannot pass command line arguments</strong> </p>
  
  <p>This is probably related to the first problem.  In <code>exec-maven-plugin</code>, for example, command line args were themselves passed in via a system property.  Is that the case with Gradle, or is there another way to pass command line arguments?</p>
  
  <p>How do I get these variables through?  Also, is it better to use <code>apply plugin: 'application'</code> or <code>task execute (type:JavaExec)</code>?</p>