From 432021f5b23d8c3d34e9c209903614dd48e4108b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Don=C3=A1t=20Csik=C3=B3s?= Date: Thu, 6 Oct 2022 16:52:25 +0200 Subject: [PATCH] Don't use deprecated IdeaModule.sourceDirs property when configuring newer Gradle versions --- .../groovy/com/google/protobuf/gradle/Utils.groovy | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/groovy/com/google/protobuf/gradle/Utils.groovy b/src/main/groovy/com/google/protobuf/gradle/Utils.groovy index 91f6f68e..9ce0e679 100644 --- a/src/main/groovy/com/google/protobuf/gradle/Utils.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/Utils.groovy @@ -30,15 +30,19 @@ package com.google.protobuf.gradle import groovy.transform.CompileStatic import org.gradle.api.Project +import org.gradle.api.file.ConfigurableFileCollection import org.gradle.api.tasks.SourceSet import org.gradle.plugins.ide.idea.GenerateIdeaModule import org.gradle.plugins.ide.idea.model.IdeaModel +import org.gradle.util.GradleVersion /** * Utility classes. */ @CompileStatic class Utils { + private static final GradleVersion GRADLE_7_4 = GradleVersion.version("7.4") + /** * Returns the conventional name of a configuration for a sourceSet */ @@ -108,7 +112,12 @@ class Utils { project.plugins.withId("idea") { IdeaModel model = project.getExtensions().findByType(IdeaModel) if (isTest) { - model.module.testSourceDirs += f + if (GradleVersion.current() >= GRADLE_7_4) { + // TODO call directly after updating Gradle wrapper to 7.4+ + ((ConfigurableFileCollection) model.module.invokeMethod("getTestSources", null)).from(f) + } else { + model.module.testSourceDirs += f + } } else { model.module.sourceDirs += f }