How can I set gradle project properties when using gradle tooling API?

542 Views Asked by At

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.

1

There are 1 best solutions below

0
tim_yates On BEST ANSWER

You can do:

connection.newBuild()
            .withArguments('-Penv=local')
            .forTasks('deploy')
            .setStandardOutput(System.out)
            .run()