0

Both provided in samples/toolingApi/customModel and Feature Spotlight examples of Gradle Tooling API custom model use plugin to register the model. However in order to apply the plugin it's necessary to either change build.gradle or use initialization scripts, which are supported by GradleConnector (yet).

How can I register a custom model within Tooling API itself, so my application can retrieve projects' information in a custom format without changing their build.gradle files? How can I get a reference to ToolingModelBuilderRegistry implementation in an application code?

Viktor
  • 345
  • 1
  • 3
  • 13

1 Answers1

3

Init scripts are supported, they are just an argument like any other.

projectConnection.models(ModelType).withArguments('--init-script', pathToInitScript).get()
Stefan Oehme
  • 449
  • 2
  • 7
  • Thanks, but I'm failing to understand this line. Is `connection` an instance of `ProjectConnection`? Then in Java I would have to start with `connection.getModel(CustomModel.class)` before registering the model. Where does `withArguments()` belong to? – Viktor Nov 22 '16 at 11:33
  • Seems you are referring to `withArguments()` of `BuildLauncher`. This can work, but then I have to parse an output of new plugin in order to retrieve the model. I still hope to use something like `CustomModel myModel = connection.getModel(CustomModel.class);` after registering `CustomModel.class` in Tooling API – Viktor Nov 22 '16 at 11:55
  • You don't register `CustomModel`, you register `CustomModelImpl` in your init script. I'm referring to `ModelBuilder#withArguments()`. You'll see if you paste the snippet above into your code. – Stefan Oehme Nov 22 '16 at 14:13
  • Actually, this exact use case is explained in the blog post you linked: https://github.com/bmuschko/tooling-api-custom-model/blob/master/invocation/src/main/java/org/gradle/sample/toolingapi/ToolingApiRunner.java – Stefan Oehme Nov 22 '16 at 14:25
  • Thanks! Building of that project was failing. I created a [PR](https://github.com/bmuschko/tooling-api-custom-model/pull/3) for that – Viktor Nov 23 '16 at 19:46