Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Version 3.0.0: requireBranch property is final and cannot be overridden #357

Open
arjanvlek opened this issue Jun 24, 2022 · 6 comments
Open

Comments

@arjanvlek
Copy link

We're releasing from the development branch to the master branch.
The following configuration works fine in version 2.8.1 of the plugin, but breaks in 3.0.0:

release {
    pushReleaseVersionBranch = 'master' // Release to master
    tagTemplate = 'v${version}'

    git {
        requireBranch = 'development' // Release from development
    }
}

With version 3.0.0, we're getting the following error message:

A problem occurred evaluating root project '<<projectname>>'.
> Cannot set the property 'requireBranch' because the backing field is final.

We need to override the requireBranch property, because we are not releasing from main (or previously master) branch but from development. The readme indicates this is still a valid configuration setting, so I wouldn't have expected this to break.

Versions I'm using:

------------------------------------------------------------
Gradle 7.4.1
------------------------------------------------------------

Build time:   2022-03-09 15:04:47 UTC
Revision:     36dc52588e09b4b72f2010bc07599e0ee0434e2e

Kotlin:       1.5.31
Groovy:       3.0.9
Ant:          Apache Ant(TM) version 1.10.11 compiled on July 10 2021
JVM:          17.0.1 (Eclipse Adoptium 17.0.1+12)
OS:           Mac OS X 11.4 x86_64

OS version is not right, my Intel Mac is running macOS 12.4 so i don't know why it says 11.4.

@ColdFireIce
Copy link

HI, I'm having the same problem. Using

release {
    git.requireBranch = 'master'
}

Doesn't work either. The error is:

A problem occurred evaluating root project '<project-name>'.
> Cannot set readonly property: requireBranch for class: net.researchgate.release.GitAdapter$GitConfig

@xvik
Copy link

xvik commented Jun 24, 2022

I faced that too, and agree that it's not normal, but the following workaround works:

release.git.requireBranch.set('master')

@ColdFireIce
Copy link

I faced that too, and agree that it's not normal, but the following workaround works:

release.git.requireBranch.set('master')

Thank you very much. This worked for me.

@djessich
Copy link

djessich commented Jun 24, 2022

I have the same problem, but with litte different error.

release {
    // ...
    git {
        requireBranch = 'master'
    }
}

Results in the following error:
Cannot cast object 'main' with class 'java.lang.String' to class 'org.gradle.api.provider.Property'

I think that the error from @arjanvlek is related to mine, because the releaseBranch property is declared final and initialized in the Constructor of GitAdapter.GitConfig. I think it would be possible to fix this error by initializing all properties of GitAdapter.GitConfig inline, without using the Constructor.

Configuring the following beforementioned workaround in build.gradle works for me too:

release {
    // ...
    git {
        requireBranch.set('master')
    }
}

However, this workaround is not intentional. The Gradle Documentation for Lazy Evaluation states:
Note that Gradle Groovy DSL generates setter methods for each Property-typed property in a task implementation. These setter methods allow you to configure the property using the assignment (=) operator as a convenience.

Please provide a fix for the root problem, as this plugin is not conform to Gradle documentation anymore.

BTW: The documentation of this plugin in README.md is not correct anymore, as requireBranch and other properties of git block cannot be set anymore with assignment operator.

kjetiljd added a commit to navikt/ep-eux that referenced this issue Jul 5, 2022
kjetiljd added a commit to navikt/ep-logging that referenced this issue Jul 5, 2022
kjetiljd added a commit to navikt/ep-metrics that referenced this issue Jul 5, 2022
kjetiljd added a commit to navikt/ep-security-sts that referenced this issue Jul 5, 2022
kjetiljd added a commit to navikt/ep-pensjonsinformasjon that referenced this issue Jul 5, 2022
@nre-ableton
Copy link

FYI, the problem was introduced here in this commit: a4a29c1#diff-e153b6a5c5ad5979271a2f7e4b409cd2357bb11a25d1498d1e374d3cb1eabe77R39-R40

Ping @Hillkorn

@Shuyinsama
Copy link

Shuyinsama commented Feb 6, 2023

It seems the following also does not work anymore

release {
    git.requireBranch.set("release/.*")
}

My release just failed saying I was not on the main branch. Event though we set the requireBranch

Strangely enough all commits and the actual release of the artifact went correctly?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants