Search code examples
gradleproject

How to get project's implementation in gradle?


A build.gradle file represents an instance of Project in gradle. But Project is just an interface. The question is: how to get Project's implementation (kind of like *.java, *.class) that corresponds to the build.gradle script?


Solution

  • build.gradle is not an equivalent of Project's implementation. It's executed on a passed Project instance, this is not the same. To know the implementation class of Project run the script below:

    println project.getClass()
    

    You'll get org.gradle.api.internal.project.DefaultProject_Decorated which points to this class. What is this _Decorated suffix? As pointed here and here it marks the class as preprocessed. The goal of this preprocessing is:

    Generates a subclass of the target class to mix-in some DSL behaviour.