23 lines
		
	
	
		
			619 B
		
	
	
	
		
			Groovy
		
	
	
	
			
		
		
	
	
			23 lines
		
	
	
		
			619 B
		
	
	
	
		
			Groovy
		
	
	
	
def getGitHash = { ->
 | 
						|
  def stdout = new ByteArrayOutputStream()
 | 
						|
  exec {
 | 
						|
    commandLine 'git', 'rev-parse', '--short', 'HEAD'
 | 
						|
    standardOutput = stdout
 | 
						|
  }
 | 
						|
  return stdout.toString().trim()
 | 
						|
}
 | 
						|
 | 
						|
tasks.register("writeVersionNumberFile") {
 | 
						|
 | 
						|
  def versionFile = file("${sourceSets.main.output.resourcesDir}/${project.name}.version")
 | 
						|
  inputs.property "version", project.version.toString()
 | 
						|
  outputs.file versionFile
 | 
						|
 | 
						|
  doFirst {
 | 
						|
    assert versionFile.parentFile.mkdirs() || versionFile.parentFile.directory
 | 
						|
    versionFile.text = "${project.version}~${getGitHash()}"
 | 
						|
  }
 | 
						|
}
 | 
						|
 | 
						|
compileJava.dependsOn writeVersionNumberFile
 |