Skip to content
Snippets Groups Projects
app-version.gradle 1.12 KiB
Newer Older
  • Learn to ignore specific revisions
  • 
    tasks.withType(JavaCompile) {
      doFirst {
    
        apply plugin: "com.palantir.git-version"
    
        def versionFile = new File("${projectDir}/src/main/resources/version/nshmp-haz-version.json")
        new File(versionFile.getParent()).mkdirs()
    
        try {
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
          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. Writing blank file.")
    
    Clayton, Brandon Scott's avatar
    Clayton, Brandon Scott committed
          println(e)
    
          versionFile.write('{}')