Skip to content
This repository was archived by the owner on May 11, 2026. It is now read-only.

Commit a56d2ed

Browse files
committed
fix: legacy Gradle maybe crashed when using "excludeGroupAndSubgroups" and "includeGroupAndSubgroups"
1 parent 301283a commit a56d2ed

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

  • sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/manager

sweetdependency-gradle-plugin/src/main/java/com/highcapable/sweetdependency/manager/RepositoryManager.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ package com.highcapable.sweetdependency.manager
2424
import com.highcapable.sweetdependency.document.PreferencesDocument
2525
import com.highcapable.sweetdependency.document.RepositoryDocument
2626
import com.highcapable.sweetdependency.exception.SweetDependencyUnresolvedException
27+
import com.highcapable.sweetdependency.gradle.helper.GradleHelper
2728
import com.highcapable.sweetdependency.manager.const.AdditionalRepositories
2829
import com.highcapable.sweetdependency.manager.content.Repositories
2930
import com.highcapable.sweetdependency.plugin.config.content.SweetDependencyConfigs
@@ -100,9 +101,17 @@ internal object RepositoryManager {
100101
fun List<String>.forEachParams(size: Int, result: (List<String>) -> Unit) = forEach {
101102
result(it.split(":").also { e -> if (e.size != size) SError.make("Missing argument in content configuration") })
102103
}
104+
105+
/**
106+
* 对旧版本不兼容的方法打印警告信息
107+
* @param name 方法名称
108+
*/
109+
fun warnIfNotSupport(name: String) = SLog.warn("Current Gradle ${GradleHelper.version} not support \"$name\"")
103110
document.content.exclude.also {
104111
it.group().noEmpty()?.forEach { e -> excludeGroup(e) }
105-
it.groupAndSubgroups().noEmpty()?.forEach { e -> excludeGroupAndSubgroups(e) }
112+
runCatching {
113+
it.groupAndSubgroups().noEmpty()?.forEach { e -> excludeGroupAndSubgroups(e) }
114+
}.onFailure { warnIfNotSupport(name = "excludeGroupAndSubgroups") }
106115
it.groupByRegex().noEmpty()?.forEach { e -> excludeGroupByRegex(e) }
107116
it.module().noEmpty()?.forEachParams(size = 2) { e -> excludeModule(e[0], e[1]) }
108117
it.moduleByRegex().noEmpty()?.forEachParams(size = 2) { e -> excludeModuleByRegex(e[0], e[1]) }
@@ -111,7 +120,9 @@ internal object RepositoryManager {
111120
}
112121
document.content.include.also {
113122
it.group().noEmpty()?.forEach { e -> includeGroup(e) }
114-
it.groupAndSubgroups().noEmpty()?.forEach { e -> includeGroupAndSubgroups(e) }
123+
runCatching {
124+
it.groupAndSubgroups().noEmpty()?.forEach { e -> includeGroupAndSubgroups(e) }
125+
}.onFailure { warnIfNotSupport(name = "includeGroupAndSubgroups") }
115126
it.groupByRegex().noEmpty()?.forEach { e -> includeGroupByRegex(e) }
116127
it.module().noEmpty()?.forEachParams(size = 2) { e -> includeModule(e[0], e[1]) }
117128
it.moduleByRegex().noEmpty()?.forEachParams(size = 2) { e -> includeModuleByRegex(e[0], e[1]) }

0 commit comments

Comments
 (0)