From ad28ad9c5941bd094b6d089ae96dc2a2c0d46770 Mon Sep 17 00:00:00 2001
From: Kengo TODA <skypencil@gmail.com>
Date: Fri, 13 May 2022 09:10:21 +0800
Subject: [PATCH 1/2] test: reproduce the reported issue

---
 .../snom/CacheabilityFunctionalTest.groovy    | 65 +++++++++++++++++++
 1 file changed, 65 insertions(+)

diff --git a/src/functionalTest/groovy/com/github/spotbugs/snom/CacheabilityFunctionalTest.groovy b/src/functionalTest/groovy/com/github/spotbugs/snom/CacheabilityFunctionalTest.groovy
index c561a406..ab708d57 100644
--- a/src/functionalTest/groovy/com/github/spotbugs/snom/CacheabilityFunctionalTest.groovy
+++ b/src/functionalTest/groovy/com/github/spotbugs/snom/CacheabilityFunctionalTest.groovy
@@ -110,6 +110,71 @@ class CacheabilityFunctionalTest extends Specification {
         hashKeyLine1 == hashKeyLine2
     }
 
+    /**
+     * @see <a href="https://github.com/spotbugs/spotbugs-gradle-plugin/issues/710">GitHub Issue</a>
+     */
+    def 'build cache is invalidate when user changes stylesheet'() {
+        given:
+        def buildDir = Files.createTempDirectory(null).toFile()
+        def buildFile = new File(buildDir, 'build.gradle')
+        def version = System.getProperty('snom.test.functional.gradle', GradleVersion.current().version)
+        def buildFileContent = '''
+            |plugins {
+            |    id 'java'
+            |    id 'com.github.spotbugs'
+            |}
+            |
+            |version = 1.0
+            |
+            |repositories {
+            |    mavenCentral()
+            |}
+            |spotbugsMain {
+            |    reports {
+            |        html {
+            |            required = true
+            |            stylesheet = 'fancy-hist.xsl'
+            |        }
+            |    }
+            |}
+            |'''.stripMargin()
+
+        initializeBuildFile(buildDir)
+        buildFile.write(buildFileContent)
+
+        when:
+        GradleRunner.create()
+                .withProjectDir(buildDir)
+                .withArguments('--build-cache', ':spotbugsMain')
+                .withPluginClasspath()
+                .withGradleVersion(version)
+                .build()
+
+        buildFile.write(buildFileContent.replace('fancy-hist.xsl', 'plain.xsl'))
+        BuildResult result1 =
+                GradleRunner.create()
+                .withProjectDir(buildDir)
+                .withArguments('--build-cache', ':spotbugsMain')
+                .withPluginClasspath()
+                .withGradleVersion(version)
+                .build()
+
+        then:
+        result1.task(':spotbugsMain').outcome == TaskOutcome.SUCCESS
+
+        when:
+        BuildResult result2 =
+                GradleRunner.create()
+                .withProjectDir(buildDir)
+                .withArguments('--build-cache', ':spotbugsMain')
+                .withPluginClasspath()
+                .withGradleVersion(version)
+                .build()
+
+        then:
+        result2.task(':spotbugsMain').outcome == TaskOutcome.UP_TO_DATE
+    }
+
     private static String getHashKeyLine(BuildResult result) {
         return result.output.find('Build cache key for task \':spotbugsMain\' is .*')
     }

From 6b22c2111f6e487225a69294c008f7349245dd4a Mon Sep 17 00:00:00 2001
From: Kengo TODA <skypencil@gmail.com>
Date: Fri, 13 May 2022 10:37:57 +0800
Subject: [PATCH 2/2] fix: changing stylesheet does not invalidate gradle build
 cache

---
 .../com/github/spotbugs/snom/internal/SpotBugsHtmlReport.java   | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/main/groovy/com/github/spotbugs/snom/internal/SpotBugsHtmlReport.java b/src/main/groovy/com/github/spotbugs/snom/internal/SpotBugsHtmlReport.java
index f7c20d2c..39331eb4 100644
--- a/src/main/groovy/com/github/spotbugs/snom/internal/SpotBugsHtmlReport.java
+++ b/src/main/groovy/com/github/spotbugs/snom/internal/SpotBugsHtmlReport.java
@@ -24,6 +24,7 @@
 import org.gradle.api.model.ObjectFactory;
 import org.gradle.api.provider.Property;
 import org.gradle.api.resources.TextResource;
+import org.gradle.api.tasks.Input;
 
 public abstract class SpotBugsHtmlReport extends SpotBugsReport {
   private final Property<TextResource> stylesheet;
@@ -56,6 +57,7 @@ public String getName() {
   }
 
   @Override
+  @Input
   public TextResource getStylesheet() {
     if (stylesheet.isPresent()) {
       return stylesheet.get();