From f02192d0d8f5975b5931acc27b1b5bbdfff2aefc Mon Sep 17 00:00:00 2001 From: Shi Chen Date: Fri, 24 Jun 2022 11:21:00 +0800 Subject: [PATCH] fix: Limit minimal Gradle version to get plugin closure(#1239) --- .../com/microsoft/gradle/GradleProjectModelBuilder.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gradle-plugin/src/main/java/com/microsoft/gradle/GradleProjectModelBuilder.java b/gradle-plugin/src/main/java/com/microsoft/gradle/GradleProjectModelBuilder.java index af55e8eca..1f7635f05 100644 --- a/gradle-plugin/src/main/java/com/microsoft/gradle/GradleProjectModelBuilder.java +++ b/gradle-plugin/src/main/java/com/microsoft/gradle/GradleProjectModelBuilder.java @@ -42,9 +42,12 @@ import org.gradle.api.tasks.testing.Test; import org.gradle.internal.classpath.ClassPath; import org.gradle.tooling.provider.model.ToolingModelBuilder; +import org.gradle.util.GradleVersion; public class GradleProjectModelBuilder implements ToolingModelBuilder { + private static String MINIMAL_SUPPORTED_PLUGIN_CLOSURE_VERSION = "5.0"; + private Set cachedTasks = new HashSet<>(); public boolean canBuild(String modelName) { @@ -161,6 +164,10 @@ private List getPlugins(Project project) { } private List getPluginClosures(Project project) { + if (GradleVersion.version(project.getGradle().getGradleVersion()) + .compareTo(GradleVersion.version(MINIMAL_SUPPORTED_PLUGIN_CLOSURE_VERSION)) < 0) { + return Collections.emptyList(); + } Convention convention = project.getConvention(); ExtensionsSchema extensionsSchema = convention.getExtensionsSchema(); List closures = new ArrayList<>();