Skip to content

Commit

Permalink
BaseReleasePlugin: change how we detect if project version is written…
Browse files Browse the repository at this point in the history
… in build file
  • Loading branch information
rpalcolea committed Oct 23, 2023
1 parent 336673b commit 0edfff5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ class BaseReleasePlugin implements Plugin<Project> {

project.afterEvaluate {
prepareTask.configure {
// Force version inference if it hasn't happened already
project.version.toString()
if(!(project.version instanceof String) && project.version.inferredVersion) {
it.projectVersion.set(project.version.inferredVersion)
}
it.remote.set(extension.remote)
it.gitWriteCommandsUtil.set(extension.gitWriteCommands)
it.gitCommandUtil.set(extension.gitReadCommands)
Expand All @@ -77,11 +82,9 @@ class BaseReleasePlugin implements Plugin<Project> {
releaseTask.configure {
// Force version inference if it hasn't happened already
project.version.toString()
if(project.version instanceof String) {
throw new GradleException("version should not be set in build file when using nebula-release plugin. Instead use `-Prelease.version` parameter")
if(!(project.version instanceof String) && project.version.inferredVersion) {
it.projectVersion.set(project.version.inferredVersion)
}

it.projectVersion.set(project.version.inferredVersion)
it.tagStrategy.set(extension.tagStrategy)
it.remote.set(extension.remote)
it.gitWriteCommandsUtil.set(extension.gitWriteCommands)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.gradle.api.GradleException
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.TaskAction
import org.gradle.work.DisableCachingByDefault

Expand All @@ -19,9 +20,15 @@ abstract class PrepareTask extends DefaultTask {
abstract Property<GitWriteCommandsUtil> getGitWriteCommandsUtil()
@Input
abstract Property<String> getRemote()
@Input
@Optional
abstract Property<ReleaseVersion> getProjectVersion()

@TaskAction
void prepare() {
if(!projectVersion.isPresent()) {
throw new GradleException("version should not be set in build file when using nebula-release plugin. Instead use `-Prelease.version` parameter")
}
logger.info('Fetching changes from remote: {}', remote.get())
GitReadOnlyCommandUtil gitReadCommandUtil = gitCommandUtil.get()
GitWriteCommandsUtil gitWriteCommandUtil = gitWriteCommandsUtil.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package nebula.plugin.release.git.base

import nebula.plugin.release.git.command.GitWriteCommandsUtil
import org.gradle.api.DefaultTask
import org.gradle.api.GradleException
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Input
import org.gradle.api.tasks.Internal
import org.gradle.api.tasks.Optional
import org.gradle.api.tasks.TaskAction
import org.gradle.work.DisableCachingByDefault

Expand All @@ -16,12 +18,16 @@ abstract class ReleaseTask extends DefaultTask {
@Internal
abstract Property<TagStrategy> getTagStrategy()
@Input
@Optional
abstract Property<ReleaseVersion> getProjectVersion()
@Input
abstract Property<String> getRemote()

@TaskAction
void release() {
if(!projectVersion.isPresent()) {
throw new GradleException("version should not be set in build file when using nebula-release plugin. Instead use `-Prelease.version` parameter")
}
GitWriteCommandsUtil gitCommands = gitWriteCommandsUtil.get()
String tagName = tagStrategy.get().maybeCreateTag(gitCommands, projectVersion.get())
if (tagName) {
Expand Down

0 comments on commit 0edfff5

Please sign in to comment.