I've got a task property defined like this: ```abs...
# community-support
b
I've got a task property defined like this:
Copy code
abstract class ChangeModuleVersion : DefaultTask() {
    @Input
    val moduleVersion: Provider<String> = project.objects.property<String>()
and registered like this:
Copy code
tasks.register<ChangeModuleVersion>("changeModuleVersion")
how do I pass I pass the parameter to the task, because ./gradlew changeModuleVersion -PmoduleVersion=0.0.1 gives me a property 'moduleVersion' doesn't have a configured value.
1
j
There are two different things called property (🤷) 1. Property (as an extension of Provider) is what you use to make tasks configurable 2. Gradle Property is the thing you pass via
-P
(it's like a global parameter for the build) In your example, you probably want to connect theses two:
Copy code
tasks.register<ChangeModuleVersion>("changeModuleVersion") {
    moduleVersion = providers.gradleProperty("moduleVersion")
}
b
is it recommended to use something else? I have that task as a dependency of a package task so it needs to be available in that context
j
If you want the
moduleVersion
to be something you configure via command line
-PmoduleVersion=...
is the right way to do it. And then link that to some task as in the snippet I posted. What does the
changeModuleVersion
task do?
b
it edits a module.json file by replacing the version and download link parameter
j
And then the "package task" uses that file? Is the
module.json
file a source file in Git?
b
exactly
it also needs to be present in the git repo although I might want to change that
the package format is a bit difficult in that it needs both a zip and a module.json file served under some link
j
It's a special situation. Ideally, a task other tasks depend on has Inputs and Outputs that do not overlap. Modifying a file in place can be done, but then the task can not have Inputs/Outputs in the Gradle sense. The task will never be UP-TO-DATE. It's then probably more correct to define:
Copy code
@Internal
val moduleVersion: Property<String>
...and not
@Input
(but it makes no difference as long as there is no
@Output...
defined)
b
thank you