// Load external plugins buildscript { repositories { gradlePluginPortal() mavenCentral() } dependencies { classpath 'me.qoomon:gradle-git-versioning-plugin:6.4.3' } } // Apply plugins apply plugin: me.qoomon.gradle.gitversioning.GitVersioningPlugin // Setup versions handling gitVersioning.apply { refs { branch('(feature|bugfix)/(?.+)') { version = '${ref.feature}-SNAPSHOT' } branch('release/v(?.*)') { version = '${ref.version}-RC' } branch('.+') { version = '${ref}-SNAPSHOT' } tag('v(?.*)') { version = '${ref.version}' } } // optional fallback configuration in case of no matching ref configuration rev { version = '${commit}' } } // Simple task to write the env shell script to register version env vars task writeVersionFile() { doLast { new File(buildDir, 'env-setup.sh').text = """ #!/bin/sh # Default env vars export APPLICATION_VERSION=${version} export APPLICATION_NAME=${project.name} export APPLICATION_FILE_BINARY=${bootJar.archiveFileName.get()} export APPLICATION_PORT=${applicationPort} export APPLICATION_JAVA_VERSION=${java.sourceCompatibility} # Gitea/Github specific env variables echo "APPLICATION_VERSION=\$APPLICATION_VERSION" >> \$GITHUB_ENV echo "APPLICATION_FILE_BINARY=\$APPLICATION_FILE_BINARY" >> \$GITHUB_ENV echo "APPLICATION_NAME=\$APPLICATION_NAME" >> \$GITHUB_ENV echo "APPLICATION_PORT=\$APPLICATION_PORT" >> \$GITHUB_ENV echo "APPLICATION_JAVA_VERSION=\$APPLICATION_JAVA_VERSION" >> \$GITHUB_ENV """ } } // Link up version file task to bootJar tasks.named('bootJar').configure { dependsOn writeVersionFile } task removeEnvFile(type: Delete) { delete new File(buildDir, 'env-setup.sh') } // Link up version file task to bootJar tasks.named('writeVersionFile').configure { dependsOn removeEnvFile }