diff --git a/.github/workflows/build-common.yml b/.github/workflows/build-common.yml index 5399344ac6..b191ad9630 100644 --- a/.github/workflows/build-common.yml +++ b/.github/workflows/build-common.yml @@ -88,8 +88,7 @@ jobs: run: | # add any untracked folders that may have been added by generateLicenseReport git add licenses - # there's always going to one line difference due to the timestamp included in the report - if [[ $(git diff --cached --shortstat licenses) == " 1 file changed, 1 insertion(+), 1 deletion(-)" ]] + if [[ $(git diff --cached --shortstat licenses) == "" ]] then echo "Licenses are up-to-date." else diff --git a/javaagent/build.gradle.kts b/javaagent/build.gradle.kts index 89df36ddc9..ef7a6369ea 100644 --- a/javaagent/build.gradle.kts +++ b/javaagent/build.gradle.kts @@ -2,7 +2,9 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar import com.github.jk1.license.filter.LicenseBundleNormalizer import com.github.jk1.license.render.InventoryMarkdownReportRenderer import org.spdx.sbom.gradle.SpdxSbomTask +import java.nio.file.Files import java.util.UUID +import java.util.regex.Pattern plugins { id("com.github.jk1.dependency-license-report") @@ -240,11 +242,29 @@ tasks { delete(rootProject.file("licenses")) } + val removeLicenseDate by registering { + // removing the license report date makes it idempotent + doLast { + val filePath = rootDir.toPath().resolve("licenses").resolve("licenses.md") + if (Files.exists(filePath)) { + val datePattern = Pattern.compile("^_[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} .*_$") + val lines = Files.readAllLines(filePath) + // 4th line contains the timestamp of when the license report was generated, replace it with + // an empty line + if (lines.size > 3 && datePattern.matcher(lines[3]).matches()) { + lines[3] = "" + Files.write(filePath, lines) + } + } + } + } + val generateLicenseReportEnabled = gradle.startParameter.taskNames.any { it.equals("generateLicenseReport") } named("generateLicenseReport").configure { dependsOn(cleanLicenses) finalizedBy(":spotlessApply") + finalizedBy(removeLicenseDate) // disable licence report generation unless this task is explicitly run // the files produced by this task are used by other tasks without declaring them as dependency // which gradle considers an error diff --git a/licenses/licenses.md b/licenses/licenses.md index 388e6671ed..b9f0857e93 100644 --- a/licenses/licenses.md +++ b/licenses/licenses.md @@ -1,7 +1,7 @@ # javaagent ## Dependency License Report -_2024-07-19 10:32:38 CEST_ + ## Apache License, Version 2.0 **1** **Group:** `com.blogspot.mydailyjava` **Name:** `weak-lock-free` **Version:** `0.18`