diff --git a/src/main/java/de/thetaphi/forbiddenapis/gradle/CheckForbiddenApis.java b/src/main/java/de/thetaphi/forbiddenapis/gradle/CheckForbiddenApis.java
index f8244e1..b5cf364 100644
--- a/src/main/java/de/thetaphi/forbiddenapis/gradle/CheckForbiddenApis.java
+++ b/src/main/java/de/thetaphi/forbiddenapis/gradle/CheckForbiddenApis.java
@@ -40,11 +40,14 @@
import org.gradle.api.file.FileTreeElement;
import org.gradle.api.specs.Spec;
import org.gradle.api.tasks.CompileClasspath;
+import org.gradle.api.tasks.IgnoreEmptyDirectories;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFiles;
import org.gradle.api.tasks.Internal;
import org.gradle.api.tasks.Optional;
import org.gradle.api.tasks.ParallelizableTask;
+import org.gradle.api.tasks.PathSensitive;
+import org.gradle.api.tasks.PathSensitivity;
import org.gradle.api.tasks.SkipWhenEmpty;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.VerificationTask;
@@ -465,6 +468,8 @@ public CheckForbiddenApis include(@SuppressWarnings("rawtypes") Closure arg0) {
/** Returns the classes to check. */
@InputFiles
@SkipWhenEmpty
+ @IgnoreEmptyDirectories
+ @PathSensitive(PathSensitivity.RELATIVE)
public FileTree getClassFiles() {
return getClassesDirs().getAsFileTree().matching(getPatternSet());
}
diff --git a/src/main/java/org/gradle/api/tasks/IgnoreEmptyDirectories.java b/src/main/java/org/gradle/api/tasks/IgnoreEmptyDirectories.java
new file mode 100644
index 0000000..958740c
--- /dev/null
+++ b/src/main/java/org/gradle/api/tasks/IgnoreEmptyDirectories.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2020 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.gradle.api.tasks;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import de.thetaphi.forbiddenapis.gradle.CheckForbiddenApis;
+
+/**
+ * Attached to an input property to specify that directories should be ignored
+ * when snapshotting inputs. Files within directories and subdirectories will be
+ * snapshot, but the directories themselves will be ignored. Empty directories,
+ * and directories that contain only empty directories will have no effect on the
+ * resulting snapshot.
+ * Copy of Gradle 6.8 annotation to allow compilation of {@link CheckForbiddenApis}.
+ * It is excluded from the JAR file (runtime annotations are still optional at runtime).
+ */
+@Documented
+@Retention(RetentionPolicy.RUNTIME)
+@Target({ElementType.METHOD, ElementType.FIELD})
+public @interface IgnoreEmptyDirectories {
+}