3

I'm trying to use the tooling API to run a gradle task from groovy code. The following works:

ProjectConnection connection = GradleConnector.newConnector()
            .forProjectDirectory(new File(System.properties.getProperty('user.dir')))
            .connect()    

connection.newBuild()
            .forTasks('deploy')
            .setStandardOutput(System.out)
            .run()

But the task I want to run depends on project properties. For example, if I was running it from the command line, I'd use

 gradle -Penv=local deploy

I can't figure out how, using the tooling API, to set those project values.

Steve Anderson
  • 334
  • 1
  • 7
  • 1
    Can't you add `.withArguments('-Penv=local')` before the `.forTasks` line? – tim_yates Mar 14 '17 at 22:45
  • Color me embarrassed. I tried that, repeatedly, before posting, but was unsuccessful because of a typo. After your comment, I went back and retyped the line and it suddenly started working. – Steve Anderson Mar 14 '17 at 22:53

1 Answers1

2

You can do:

connection.newBuild()
            .withArguments('-Penv=local')
            .forTasks('deploy')
            .setStandardOutput(System.out)
            .run()
tim_yates
  • 167,322
  • 27
  • 342
  • 338