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

Build fails when not using git #345

Closed
goatfanboi23 opened this issue Jul 10, 2024 · 1 comment
Closed

Build fails when not using git #345

goatfanboi23 opened this issue Jul 10, 2024 · 1 comment
Labels
type: documentation This issue is about editing the documentation

Comments

@goatfanboi23
Copy link
Contributor

Overview:

Grgit silently puts a null reference in gradle.properties when it can not find a git repo. This leads to a build failure when processResources task is executed.

Error:

When building without a git repo, the following abbreviated error is shown:

Could not copy file...
Invalid filter specification for org.apache.tools.ant.filters.ReplaceTokens...
Cannot cast object {insert property file data here} with class 'java.util.HashMap' to class 'java.util.Hashtable'
due to: java.lang.NullPointerException

Inside the {insert property file data here} is the line grgit=null, which—as previously mentioned—is inserted by grgit when it can not find a git repo.

Possible Solutions:

without making any changes to the underlying logic, you can simply replace all null vales in the gradle.properties file with an empty string. This can be done by concatenating .collectEntries{ k, v -> [k, v ?: '']} to the filter call in the processResources task.
The task now looks like this:

processResources {
        filesMatching(['**/*.json', '**/*.yml']) {
            filter ReplaceTokens as Class, beginToken: '${', endToken: '}',
                    tokens: rootProject.ext.properties.collectEntries{ k, v -> [k, v ?: '']}
        }
}

This does not have any consequences because the resulting plugin.yaml version field will just be concatenated with unknown as specified by versionMetadata method:

if (grgit == null) {
        return '-unknown'
}

This fix however could potentially down the line introduce errors when devolving if a property is null but gets copied as an empty string.
To only replace the grgit=null entry you can use the following code:

def tokenMap = rootProject.ext.properties
        tokenMap.merge("grgit",'',(s, s2) -> s)
        filesMatching(['**/*.json', '**/*.yml']) {
            filter ReplaceTokens as Class, beginToken: '${', endToken: '}',
                    tokens: tokenMap
}

The merge function replaces the key grgit with '' if null otherwise it uses the original value.
Hopefully this helps anyone with the same error, and please let me know if you would like me to make a PR.

@WiIIiam278
Copy link
Owner

Always enjoy a detailed issue write-up :). Sure thing, send in a PR.

The vast majority of folks just clone the repo and build, hence the broken failsafe stuff I wrote never functioned correctly as I didn't quite bother to test it. But this would be nice for those who download the source zip.

@WiIIiam278 WiIIiam278 added the type: documentation This issue is about editing the documentation label Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: documentation This issue is about editing the documentation
Projects
None yet
Development

No branches or pull requests

2 participants