Skip to content

Commit

Permalink
feat: added plugin to auto-exclude commons-logging, possibly more to …
Browse files Browse the repository at this point in the history
…be added in the future
  • Loading branch information
testersen committed Jan 14, 2024
1 parent 264795f commit 38d67d4
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,11 @@ organizations.

`telenor.dcapi()` Will add the legacy DC API repository from
Prima Nexus.

### Auto Exclude

This plugin will automatically exclude the following
dependencies from all configurations:

- `commons-logging:commons-logging`
unless `AUTO_EXCLUDE_KEEP` contains `commons-logging`
2 changes: 2 additions & 0 deletions src/main/kotlin/sh/tnn/gradle/TelenorNextPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sh.tnn.gradle

import org.gradle.api.Plugin
import org.gradle.api.Project
import sh.tnn.gradle.plugins.auto_exclude.AutoExcludePlugin
import sh.tnn.gradle.plugins.auto_version.AutoVersionPlugin
import sh.tnn.gradle.plugins.dotenv.DotEnvPlugin
import sh.tnn.gradle.plugins.github.GitHubPlugin
Expand All @@ -18,6 +19,7 @@ class TelenorNextPlugin : Plugin<Project> {
GitHubPlugin::class,
TelenorPlugin::class,
OpenTelemetryPlugin::class,
AutoExcludePlugin::class,
).forEach {
project.pluginManager.apply(it.java)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package sh.tnn.gradle.plugins.auto_exclude

import org.gradle.api.Plugin
import org.gradle.api.Project
import sh.tnn.gradle.plugins.dotenv.DotEnvPlugin

class AutoExcludePlugin : Plugin<Project> {
companion object {
val excluded = arrayOf(
"commons-logging:commons-logging" unlessKeep "commons-logging",
)
}

override fun apply(project: Project) {
val keep = (DotEnvPlugin.get(project, "AUTO_EXCLUDE_KEEP") ?: "").split(",").map { it.trim().lowercase() }
project.configurations.all { conf ->
excluded.forEach { notation ->
if (notation.second in keep) return@forEach
val (group, module) = notation.first.split(":")
conf.exclude(mapOf("group" to group, "module" to module))
}
}
}
}

private infix fun String.unlessKeep(other: String): Pair<String, String> = this to other.lowercase()

0 comments on commit 38d67d4

Please sign in to comment.