From 93ea51e62b7a3f753e65d6ecd707fdab7f630052 Mon Sep 17 00:00:00 2001 From: Roger Littin Date: Fri, 8 Sep 2023 10:59:31 +0100 Subject: [PATCH] Gradle build updates (#17) * Update gradle build workflow - Add versioning for Wowza dependencies - Implement git-properties gradle plugin - Add build info to jar MANIFEST.MF - Add LICENSE.txt to jar META-INF * Remove unused upload-artifact action from release workflow --- .github/workflows/release.yml | 4 ---- README.md | 2 +- build.gradle | 43 +++++++++++++++++++++++++++-------- 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 19829f6..6144308 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -58,10 +58,6 @@ jobs: build -Pversion=${{ github.ref_name }} -PwseLibDir=${{ vars.WSE_HOME }}/files/lib - - uses: actions/upload-artifact@v3 - with: - name: Package - path: build/libs - name: Release uses: softprops/action-gh-release@v1 with: diff --git a/README.md b/README.md index 5dfa841..91cd467 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ The module is also able to send tracking events via a _Server Side Tag Manager_ ## Build instructions * Clone repo to local filesystem. * Update `wseLibDir` variable in the `gradle.properties` file to point to local _Wowza Streaming Engine_ `lib` folder. -* Run `./gradlew generateJava` command to generate the `BuildProperties.java` file. This task will automatically run before each compile to regenerate the file. +* Run `./gradlew generateBuildProperties` command to generate the `BuildProperties.java` file. This task will automatically run before each compile to regenerate the file. * Run `./gradlew build` to build the jar file. ## More resources diff --git a/build.gradle b/build.gradle index cad2abb..6e53868 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,6 @@ plugins { id 'java-library' + id 'com.gorylenko.gradle-git-properties' version '2.4.1' } java { @@ -16,29 +17,53 @@ repositories { } dependencies { - compileOnly name: 'wms-server' - compileOnly name: 'wms-webrtc' + compileOnly 'com.wowza.wms:wms-server:4.8.22' + compileOnly 'com.wowza.wms:wms-webrtc:4.8.22' compileOnly 'org.apache.logging.log4j:log4j-core:2.17.2' compileOnly 'org.apache.logging.log4j:log4j-api:2.17.2' } -tasks.register("generateJava") { +gitProperties { + extProperty = 'gitProps' + dateFormat = "yyyy-MM-dd'T'HH:mm:ss'Z'" + dateFormatTimeZone = 'UTC' +} + +generateGitProperties.outputs.upToDateWhen { false } + +tasks.register('generateBuildProperties') { + dependsOn generateGitProperties ext.outputDir = "$buildDir/generated/java" inputs.property('version', project.version) outputs.dir outputDir doLast { mkdir "$outputDir/com/wowza/wms/plugin/${projectName}" - file("$outputDir/com/wowza/wms/plugin/analytics/BuildProperties.java").text = + file("$outputDir/com/wowza/wms/plugin/${projectName}/BuildProperties.java").text = """|package com.wowza.wms.plugin.${projectName}; |public class BuildProperties { | public static String getVersion() { return "${project.version}"; } + | public static String getBuildDate() { return "${-> project.ext.gitProps['git.commit.time']}"; } + | public static String getBuildRevision() { return "${-> project.ext.gitProps['git.commit.id.abbrev']}"; } |}""".stripMargin() } } -compileJava.dependsOn generateJava -sourceSets.main.java.srcDir generateJava.outputDir +compileJava.dependsOn generateBuildProperties +sourceSets.main.java.srcDir generateBuildProperties.outputDir -tasks.withType(Jar).configureEach { - archiveBaseName = "wse-plugin-${projectName}" -} \ No newline at end of file +jar.configure { + manifest { + attributes( + 'Gradle-Version' : "Gradle ${gradle.gradleVersion}", + 'Created-By' : "${System.properties['java.version']} (${System.properties['java.vendor']} ${System.properties['java.vm.version']})", + 'Name' : "${project.name}", + 'Build-Version' : "${project.version}", + 'Build-Timestamp' : "${-> project.ext.gitProps['git.commit.time']}", + 'Build-Revision' : "${-> project.ext.gitProps['git.commit.id.abbrev']}", + ) + } + exclude('git.properties') + metaInf { + from files('LICENSE.txt') + } +}