create version.txt file in project dir via build.gradle task

前端 未结 1 1403
夕颜
夕颜 2020-12-09 01:29

Apologies in advance for my ignorance. I\'m very new to gradle.

My is goal is to have some task in my build.gradle file, wherein a file \'version.txt\' is created in

相关标签:
1条回答
  • 2020-12-09 02:11

    The example you're referring to is almost correct. With a couple of minor tweaks it works as expected:

    import java.text.SimpleDateFormat
    import org.ajoberstar.grgit.Grgit
    
    plugins {
        id "org.ajoberstar.grgit" version "1.7.2"
    }
    
    version = 1.0
    
    task versionTxt()  {
        doLast {
            new File(projectDir, "version.txt").text = """
    Version: $version
    Revision: ${grgit.head().abbreviatedId}
    Buildtime: ${new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date())}
    Application-name: foobarbaz app
    """
        }
    }
    

    Run gradle versionTxt to get the desired output.

    0 讨论(0)
提交回复
热议问题