Skip to content

Commit

Permalink
Make dependency rake account for all version catalogs (#435)
Browse files Browse the repository at this point in the history
Resolves #406

<!--
  ⬆ Put your description above this! ⬆

  Please be descriptive and detailed.
  
Please read our [Contributing
Guidelines](https://github.com/tinyspeck/slack-gradle-plugin/blob/main/.github/CONTRIBUTING.md)
and [Code of Conduct](https://slackhq.github.io/code-of-conduct).

Don't worry about deleting this, it's not visible in the PR!
-->
  • Loading branch information
ZacSweers authored Jun 30, 2023
1 parent 5582e6d commit 335f321
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ constructor(objects: ObjectFactory, providers: ProviderFactory) : AbstractPostPr

@TaskAction
fun rake() {
if (identifierMap.get().isEmpty()) {
logger.warn("No identifier map found. Skipping rake.")
return
}
val noApi = noApi.get()
val projectAdvice = projectAdvice()
val redundantPlugins = projectAdvice.pluginAdvice
Expand Down
8 changes: 4 additions & 4 deletions slack-plugin/src/main/kotlin/slack/gradle/SlackGradleUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,13 @@ internal fun Project.jvmTargetVersion(): Int {
return SlackProperties(this).jvmTarget
}

internal fun Project.getVersionsCatalog(): VersionCatalog {
return getVersionsCatalogOrNull() ?: error("No versions catalog found!")
internal fun Project.getVersionsCatalog(name: String = "libs"): VersionCatalog {
return getVersionsCatalogOrNull(name) ?: error("No versions catalog found!")
}

internal fun Project.getVersionsCatalogOrNull(): VersionCatalog? {
internal fun Project.getVersionsCatalogOrNull(name: String = "libs"): VersionCatalog? {
return try {
project.extensions.getByType<VersionCatalogsExtension>().named("libs")
project.extensions.getByType<VersionCatalogsExtension>().named(name)
} catch (ignored: Exception) {
null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import org.gradle.api.Project
import org.gradle.api.artifacts.Configuration
import org.gradle.api.artifacts.MinimalExternalModuleDependency
import org.gradle.api.artifacts.VersionCatalog
import org.gradle.api.artifacts.VersionCatalogsExtension
import org.gradle.api.logging.Logger
import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.plugins.JavaPluginExtension
Expand Down Expand Up @@ -168,14 +169,25 @@ internal class StandardProjectConfigurations(
// Configure rake
plugins.withId("com.autonomousapps.dependency-analysis") {
val isNoApi = slackProperties.rakeNoApi
val catalogNames =
extensions.findByType<VersionCatalogsExtension>()?.catalogNames ?: return@withId
val rakeDependencies =
tasks.register<RakeDependencies>("rakeDependencies") {
// TODO https://github.com/gradle/gradle/issues/25014
buildFileProperty.set(project.buildFile)
noApi.setDisallowChanges(isNoApi)
identifierMap.setDisallowChanges(
project.provider {
project.getVersionsCatalog().identifierMap().mapValues { (_, v) -> "libs.$v" }
buildMap {
for (catalogName in catalogNames) {
putAll(
project.getVersionsCatalog(catalogName).identifierMap().mapValues { (_, v)
->
"$catalogName.$v"
}
)
}
}
}
)
}
Expand Down

0 comments on commit 335f321

Please sign in to comment.