Skip to content

Commit

Permalink
Don't use deprecated IdeaModule.sourceDirs property when configuring …
Browse files Browse the repository at this point in the history
…newer Gradle versions
  • Loading branch information
donat authored Oct 6, 2022
1 parent e49807c commit 432021f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/main/groovy/com/google/protobuf/gradle/Utils.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 432021f

Please sign in to comment.