gradle-plugins / toolbox

Painless and fast Gradle plugin development :rocket:
https://nokee.dev/docs/toolbox
Apache License 2.0
20 stars 3 forks source link

Passing arguments to "groovy-gradle-plugin" at build time #92

Closed codex70 closed 1 year ago

codex70 commented 1 year ago

I'm new to writing plugins for gradle and am following the examples here:

https://docs.gradle.org/current/userguide/structuring_software_products.html

Under "build-logic/commons/src/main/groovy" there are gradle files which I want to pass a value to for when the file is compiled and a value for when the plugin is being run. How do you do this?

So here is the sample code:

plugins {
    id('java')
}

group = 'com.example.myproduct'

dependencies {
    implementation(platform("com.example.platform:product-platform:${build_version}"))

    testImplementation(platform("com.example.platform:test-platform:${run_version}"))
}

The idea is to specify the value ${build_version} when the "groovy-gradle-plugin" is being run (so the value is compiled into the plugin) and allow the ${run_version} to be specified when the generated plugin is run.

It's not clear to me how to set either of these values (even after lots of searching). Also, as a note, if I hard code values in, the generated plugin works as expected.

lacasseio commented 1 year ago

Despite the name of the plugin, e.g. groovy-gradle-plugin, it's a Gradle core plugin. The plugins offered by this project is dev.gradleplugins.groovy-gradle-plugin (under the namespace dev.gradleplugins). I would recommend using the Gradle user forum for such questions. In short, you want to use a gradle.properties file. You can't pass properties to included builds which is my assumption around your usage of build-logic.