Steve Anderson
Steve Anderson

Reputation: 334

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

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.

Upvotes: 3

Views: 575

Answers (1)

tim_yates
tim_yates

Reputation: 171054

You can do:

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

Upvotes: 2

Related Questions