How to embed dependencies in Gradle plugin in Gradle recommended method?

I am writing a custom plugin and testing it, I want to introduce mock implementations. This is not only for testing, but also from the point of view of the API, I want to implement various implementations depending on the context. I am currently using Gradle 2.6, and I understand that it supports some form of Injection Dependency. I do not want to use Spring / Guice / HK2, since Gradle itself supports it. However, I cannot find any information on how to inject dependencies using the Gradle 2.6 API.

For example,

 class CustomTask extends DefaultTask {

       private SomeInterface interface

       @Inject
       CustomTask(SomeInterface interface) {}

       @TaskAction
       public void executeTask() {
           interface.executeSomething()
       }
 }

So, in essence, I want to determine where to define the bindings for different instances SomeInterfaceand the mechanism for entering it into the task or elsewhere, like some custom classes.

+4
1

, - , .

Spring/Guice/HK2, Gradle .

, Gradle.
https://discuss.gradle.org/t/dependency-injection-in-gradle-plugins/6538

. Gradle, , . - .

Gradle, , .
https://github.com/gradle/gradle/tree/bd4fb1c396a695d55aeba9bc37e164a488c0b882/design-docs

, , , , . , .

, ( ) 20 2017 :

. . ,

  • GitHub Epics .
  • Google (, ).

. .

, . , . , .

+3

Source: https://habr.com/ru/post/1607017/


All Articles