title: Read gradle script and find the tasks defined in it
body: <p>I have a requirement where a gradle script (or gradle plugin) has to parse a gradle file and print all tasks of certain type; I tried referring the gradle tooling api, but did not succeed.</p>
  
  <p>Here is what I tried :</p>
  
  <pre><code>ProjectConnection connection = GradleConnector.newConnector().forProjectDirectory(new File(System.env.REPO_ROOT)).connect()
  try {
      BuildEnvironment environment = connection.model(BuildEnvironment.class).get()
      connection.model(GradleProject.class).get().getTasks().each {
          if (it instanceof EMTest) {
              println it
          }
      }
  } finally {
      connection.close()
  }
  </code></pre>
  
  <p>This prints the list of tasks in my current build.gradle, which is expected because nowhere I specified the target gradle file. </p>
  
  <p>When I tried to run (and not print/find tasks in it) with below code. It works. </p>
  
  <pre><code>ProjectConnection connection = GradleConnector.newConnector().forProjectDirectory(new File(System.env.REPO_ROOT)).connect()
  try {
      BuildEnvironment environment = connection.model(BuildEnvironment.class).get()
      def build = connection.newBuild()
      /* This is where the gradle script location is provided */
      build.withArguments("--continue", "-b", System.env.REPO_ROOT + "/tests/suites/${project.lrgs}.gradle",
              "-PlrgName=${project.lrgs}", "-PlrgMetadataLoc=${lrgMetadataLoc}")
      build.forTasks(project.lrgs)
      build.setStandardOutput(System.out)
      build.run()
  } finally {
      connection.close()
  }
  </code></pre>
  
  <p>I checked the gradle tooling api but no success. Please help. </p>