title: How do I call a static Java method from Gradle
body: <p>I have a gradle build script which currently works by simply executing a Java class through it's main method. What I want to know is, how can I call a static method in the same class but not have to go through the main method. The current gradle code is as follows:</p>
  
  <pre><code>import org.apache.tools.ant.taskdefs.condition.Os
  apply plugin: 'java'
  
  defaultTasks 'runSimple'
  
  project.ext.set("artifactId", "test-java")
  
  File rootDir = project.getProjectDir()
  File targetDir = file("${rootDir}/target")
  FileCollection javaClasspath = files("${targetDir}/tools.jar")
  
  task(runSimple, dependsOn: 'classes', type: JavaExec) {
      main = 'com.test.model.JavaTest'
      classpath = javaClasspath
      args 'arg1'
      args 'arg2'
  }
  </code></pre>
  
  <p>And my Java class as follows:</p>
  
  <pre><code>package com.test.model;
  
  public class JavaTest {
  
      public static void main(String[] args) throws Exception {
          System.out.println("In main");
          anotherMethod(args[0], args[1]);
      }
  
      public static void anotherMethod(String arg1, String arg2) {
          System.out.println("In anotherMethod");
          System.out.println(arg1 + " " + arg2);
      }
  }
  </code></pre>
  
  <p>This gives me the output:</p>
  
  <pre><code>:compileJava UP-TO-DATE
  :processResources UP-TO-DATE
  :classes UP-TO-DATE
  :runSimple
  In main
  In anotherMethod
  arg1 arg2
  
  BUILD SUCCESSFUL
  
  Total time: 2.344 secs
  </code></pre>
  
  <p>My question is simply how can I skip the main method, and call the method "anotherMethod" directly from the gradle script? The output would then simply be:</p>
  
  <pre><code>In anotherMethod
  arg1 arg2
  </code></pre>
  
  <p>Thanks</p>