From 24e1cac93cb781a57a0b8aab1b340ccc328bc69f Mon Sep 17 00:00:00 2001 From: Brandon Clayton <bclayton@usgs.gov> Date: Tue, 26 Apr 2022 09:05:12 -0600 Subject: [PATCH] use try catch --- gradle/app-version.gradle | 40 +++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/gradle/app-version.gradle b/gradle/app-version.gradle index 2367ef400..f7e96ed1e 100644 --- a/gradle/app-version.gradle +++ b/gradle/app-version.gradle @@ -2,23 +2,27 @@ apply plugin: "com.palantir.git-version" tasks.withType(JavaCompile) { doFirst { - def versionFile = new File("${projectDir}/src/main/resources/version/nshmp-haz-version.json") - new File(versionFile.getParent()).mkdirs() - def details = versionDetails() - def ciProjectUrl = System.getenv("CI_PROJECT_URL") - def branch = System.getenv("CI_COMMIT_BRANCH") - def versionInfo = [ - branchName: branch ? branch : details.branchName, - commitDistance: details.commitDistance, - gitHash: details.gitHash, - gitHashFull: details.gitHashFull, - isCleanTag: details.isCleanTag, - lastTag: details.lastTag, - projectName: project.name, - url: ciProjectUrl ? ciProjectUrl : 'git config --get remote.origin.url'.execute().text.replace('\n', ''), - version: details.version, - ] - def json = groovy.json.JsonOutput.toJson(versionInfo) - versionFile.write(groovy.json.JsonOutput.prettyPrint(json)) + try { + def versionFile = new File("${projectDir}/src/main/resources/version/nshmp-haz-version.json") + new File(versionFile.getParent()).mkdirs() + def details = versionDetails() + def ciProjectUrl = System.getenv("CI_PROJECT_URL") + def branch = System.getenv("CI_COMMIT_BRANCH") + def versionInfo = [ + branchName: branch ? branch : details.branchName, + commitDistance: details.commitDistance, + gitHash: details.gitHash, + gitHashFull: details.gitHashFull, + isCleanTag: details.isCleanTag, + lastTag: details.lastTag, + projectName: project.name, + url: ciProjectUrl ? ciProjectUrl : "git config --get remote.origin.url".execute().text.replace("\n", ""), + version: details.version, + ] + def json = groovy.json.JsonOutput.toJson(versionInfo) + versionFile.write(groovy.json.JsonOutput.prettyPrint(json)) + } catch (Exception e) { + println("Failed to create version file.") + } } } -- GitLab