Closed vesely-david closed 7 years ago
The immediate problem you have is that there is no property stage
or scope
on the release
task. There are just properties release.stage
and release.scope
on the project itself.
The other problem you'll have is that using a task to configure the properties is too late in the process given the way Gradle's evaluation and many common plugins work.
Basically, you need to set those properties as soon as possible to ensure that those are in place before any other part of Gradle asks what version this is.
Your best bet if you really need a task instead of properties is the task graph. This is the rough idea, but I didn't double check the exact property/method names to call.
task releaseFinalMajor
gradle.taskGraph.whenEvaluated { graph ->
if (graph.containsTask('releaseFinalMajor')) {
project.ext['release.scope'] = 'major'
project.ext['release.stage'] = 'final'
}
}
Thank you for your approach. Finally, we decided to set default properties for SNAPSHOT in gradle.properties and release final versions via command line with parameters.
I'm struggling with the same issue currently and wanted to add this if someone finds this issue in the future.
The following code snippet would work:
task releaseFinalMinor
gradle.taskGraph.whenReady { graph ->
if (graph.hasTask(releaseFinalMinor)) {
project.ext['release.scope'] = 'minor'
project.ext['release.stage'] = 'final'
}
}
However, there is one major implication: As soon as the maven-publish
plugin is applied, the version is inferred even before the taskGraph is ready (my guess that this is part of the initialization phase). Therefore as soon as you use the maven-publish
plugin this solution does not work. I haven't been able to find a workaround for this yet.
FYI, maven-publish
(and similar ordering issues are the reason I use properties instead of tasks.
I would like to create my own task releaseFinalMajor which would setup scope to major and stage to final.
The problem is that I am still getting an error:
Please, does anyone know what is wrong with such code? Is it even possible to setup scope and stage parameters by code and not in command line?