From 2d6f14e274b17beab819c622b4999813866ce088 Mon Sep 17 00:00:00 2001 From: Jendrik Johannes Date: Fri, 8 Dec 2023 18:03:15 +0100 Subject: [PATCH] Do not access 'project.zipTree' in mapping closure This is not supported by the Configuration Cache. Instead, we inject an ArchiveOperations service. Fixes #229 --- .../groovy/me/champeau/jmh/ParameterSpec.groovy | 1 - src/main/groovy/me/champeau/jmh/JMHPlugin.groovy | 12 ++++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/funcTest/groovy/me/champeau/jmh/ParameterSpec.groovy b/src/funcTest/groovy/me/champeau/jmh/ParameterSpec.groovy index 4169ab5c..53b4b2a4 100644 --- a/src/funcTest/groovy/me/champeau/jmh/ParameterSpec.groovy +++ b/src/funcTest/groovy/me/champeau/jmh/ParameterSpec.groovy @@ -39,7 +39,6 @@ class ParameterSpec extends AbstractFuncSpec { def "executes with configuration cache"() { given: - usingGradleVersion(GradleVersion.version("7.6")) usingSample("java-project") when: diff --git a/src/main/groovy/me/champeau/jmh/JMHPlugin.groovy b/src/main/groovy/me/champeau/jmh/JMHPlugin.groovy index 2ab81fd0..29bdbc5c 100644 --- a/src/main/groovy/me/champeau/jmh/JMHPlugin.groovy +++ b/src/main/groovy/me/champeau/jmh/JMHPlugin.groovy @@ -20,6 +20,7 @@ import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.artifacts.Configuration import org.gradle.api.artifacts.dsl.DependencyHandler +import org.gradle.api.file.ArchiveOperations import org.gradle.api.file.Directory import org.gradle.api.file.FileCollection import org.gradle.api.file.FileCopyDetails @@ -35,10 +36,12 @@ import org.gradle.plugins.ide.eclipse.EclipseWtpPlugin import org.gradle.plugins.ide.idea.IdeaPlugin import org.gradle.util.GradleVersion +import javax.inject.Inject + /** * Configures the JMH Plugin. */ -class JMHPlugin implements Plugin { +abstract class JMHPlugin implements Plugin { private static GradleVersion GRADLE_MIN = GradleVersion.version('7.0') private static boolean IS_GRADLE_MIN = GradleVersion.current() >= GRADLE_MIN @@ -50,6 +53,9 @@ class JMHPlugin implements Plugin { static final String JMH_TASK_COMPILE_GENERATED_CLASSES_NAME = 'jmhCompileGeneratedClasses' static final String JHM_RUNTIME_CLASSPATH_CONFIGURATION = 'jmhRuntimeClasspath' + @Inject + protected abstract ArchiveOperations getArchives() + void apply(Project project) { assertMinimalGradleVersion() project.plugins.apply(JavaPlugin) @@ -265,6 +271,8 @@ class JMHPlugin implements Plugin { Provider jmhGeneratedClassesDir, Configuration runtimeConfiguration) { project.tasks.register(JMH_JAR_TASK_NAME, Jar) { + def archives = archives + it.group = JMH_GROUP it.dependsOn JMH_TASK_COMPILE_GENERATED_CLASSES_NAME it.inputs.files project.sourceSets.jmh.output @@ -277,7 +285,7 @@ class JMHPlugin implements Plugin { it.collect { it.asFile } .findAll { it.directory || it.name.toLowerCase().endsWith('.jar') } .collect { - it.directory ? it : project.zipTree(it) + it.directory ? it : archives.zipTree(it) } as Set }).exclude(metaInfExcludes) def jmhSourceSetOutput = project.sourceSets.jmh.output