Configure default properties in Gradle precompiled plugin

I want to pass properties from precompiled script plugin to the project itself. I have precompiled script plugin inside of buildSrc directory.

1 In buildSrc/gradle.properties I have defined defaultSpringBootVersion property that holds value of 2.6.3. This property is used in buildSrc/build.gradle to specify the org.springframework.boot plugin version.

2 At the same time I would like that the plugin itself located in buildSrc/src/main/groovy/com.rivancic.convention-gradle-plugin.gradle applies it to project properties:

project.ext{
  springBootVersion = defaultSpringBootVersion
}

3 If I try then in root project to access springBootVersion that I expect it will be available through the plugin, I get following error:

An exception occurred applying plugin request [id: 'com.rivancic.convention-gradle-plugin']
> Failed to apply plugin 'com.rivancic.convention-gradle-plugin'.
   > groovy.lang.MissingPropertyException: Could not get unknown property 'defaultSpringBootVersion' for object of type org.gradle.internal.extensibility.DefaultExtraPropertiesExtension.

Link to the example project: GitHub - rivancic/gradle-plugin-properties: Example project in passing properties form Gradle plugin to the project itself

Representation: enter image description here

How to properly inject properties from buildSrc/gradle.properties into Precompiled Script Plugin, in this case buildSrc/src/main/groovy/com.rivancic.convention-gradle-plugin.gradle

2 Likes

Did you find a solution?