diff --git a/CHANGELOG.md b/CHANGELOG.md index 66f3cfaa5..39d3a5925 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,17 @@ # Unreleased +# 0.6.5 + +- useFqdnFor() should also work for groups #99 +- Always update version "_" or "+" #98 +- (maybe) Non deterministic behavior #95 +- rejectVersionIf { isStable(currentVersion) && isNonStable(candidate.version) } #96 + # 0.6.4 - isStable(currentVersion) && isNonStable(candidate.version) #96 +- useFqdnFor() should also work for groups #99 +- # 0.6.3 diff --git a/README.adoc b/README.adoc index fc5a9bd94..372ddbf65 100644 --- a/README.adoc +++ b/README.adoc @@ -1,5 +1,5 @@ // plugin.de.fayard.buildSrcVersions -:plugin_version: 0.6.4 +:plugin_version: 0.6.5 :gradle_version: 5.6.2 :repo: jmfayard/buildSrcVersions :branch: 26-buildSrcVersions diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts index 9bb424306..024b40aa6 100644 --- a/plugin/build.gradle.kts +++ b/plugin/build.gradle.kts @@ -1,7 +1,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { - id("de.fayard.buildSrcVersions") version ("0.6.4") // plugin.de.fayard.buildSrcVersions + id("de.fayard.buildSrcVersions") version ("0.6.5") // plugin.de.fayard.buildSrcVersions id("com.gradle.plugin-publish") `java-gradle-plugin` @@ -11,7 +11,7 @@ plugins { } -version = "0.6.5" // plugin.de.fayard.buildSrcVersions +version = "0.7.0" // plugin.de.fayard.buildSrcVersions group = "de.fayard" diff --git a/plugin/src/main/kotlin/de/fayard/BuildSrcVersionsTask.kt b/plugin/src/main/kotlin/de/fayard/BuildSrcVersionsTask.kt index 1141ecb8e..6430bbf75 100644 --- a/plugin/src/main/kotlin/de/fayard/BuildSrcVersionsTask.kt +++ b/plugin/src/main/kotlin/de/fayard/BuildSrcVersionsTask.kt @@ -144,8 +144,7 @@ open class BuildSrcVersionsTask : DefaultTask() { } private val unsortedParsedDependencies: List by lazy { - val useFdqnByDefault = extension().useFqqnFor.map { PluginConfig.escapeVersionsKt(it) } - parseGraph(dependencyGraph, useFdqnByDefault + PluginConfig.MEANING_LESS_NAMES) + parseGraph(dependencyGraph, extension().useFqqnFor) .map { d -> d.maybeUpdate(update || extension().alwaysUpdateVersions) } } diff --git a/plugin/src/main/kotlin/de/fayard/internal/DependencyGraph.kt b/plugin/src/main/kotlin/de/fayard/internal/DependencyGraph.kt index 4e5c590e4..f7b9f3c0d 100644 --- a/plugin/src/main/kotlin/de/fayard/internal/DependencyGraph.kt +++ b/plugin/src/main/kotlin/de/fayard/internal/DependencyGraph.kt @@ -37,6 +37,7 @@ data class Dependency( var mode: VersionMode = VersionMode.MODULE, val available: AvailableDependency? = null ) { + val module: String get() = name val versionName: String get() = PluginConfig.versionKtFor(this) diff --git a/plugin/src/main/kotlin/de/fayard/internal/KotlinPoetry.kt b/plugin/src/main/kotlin/de/fayard/internal/KotlinPoetry.kt index 54cc30de9..87a60b65a 100644 --- a/plugin/src/main/kotlin/de/fayard/internal/KotlinPoetry.kt +++ b/plugin/src/main/kotlin/de/fayard/internal/KotlinPoetry.kt @@ -134,32 +134,28 @@ fun Dependency.generateLibsProperty(extension: BuildSrcVersionsExtension): Prope fun parseGraph( graph: DependencyGraph, - useFdqnByDefault: List + useFdqn: List ): List { - val dependencies: List = graph.current + graph.exceeded + graph.outdated + graph.unresolved - return dependencies.checkModeAndNames(useFdqnByDefault).findCommonVersions() + val resolvedUseFqdn = PluginConfig.computeUseFqdnFor(dependencies, useFdqn, PluginConfig.MEANING_LESS_NAMES) + return dependencies.checkModeAndNames(resolvedUseFqdn).findCommonVersions() } fun List.checkModeAndNames(useFdqnByDefault: List): List { - groupBy { d -> d.name } - .forEach { (name, list) -> - for (d: Dependency in list) { - d.mode = when { - d.name in useFdqnByDefault -> VersionMode.GROUP_MODULE - PluginConfig.escapeVersionsKt(d.name) in useFdqnByDefault -> VersionMode.GROUP_MODULE - list.size >= 2 -> VersionMode.GROUP_MODULE - else -> VersionMode.MODULE - } - d.escapedName = PluginConfig.escapeVersionsKt( - when (d.mode) { - VersionMode.MODULE -> d.name - VersionMode.GROUP -> d.group - VersionMode.GROUP_MODULE -> "${d.group}_${d.name}" - } - ) - } + for (d: Dependency in this) { + d.mode = when { + d.name in useFdqnByDefault -> VersionMode.GROUP_MODULE + PluginConfig.escapeVersionsKt(d.name) in useFdqnByDefault -> VersionMode.GROUP_MODULE + else -> VersionMode.MODULE } + d.escapedName = PluginConfig.escapeVersionsKt( + when (d.mode) { + VersionMode.MODULE -> d.name + VersionMode.GROUP -> d.group + VersionMode.GROUP_MODULE -> "${d.group}_${d.name}" + } + ) + } return this } diff --git a/plugin/src/main/kotlin/de/fayard/internal/PluginConfig.kt b/plugin/src/main/kotlin/de/fayard/internal/PluginConfig.kt index 1f5c0606f..633ffa042 100644 --- a/plugin/src/main/kotlin/de/fayard/internal/PluginConfig.kt +++ b/plugin/src/main/kotlin/de/fayard/internal/PluginConfig.kt @@ -17,7 +17,7 @@ object PluginConfig { const val PLUGIN_ID = "de.fayard.buildSrcVersions" - const val PLUGIN_VERSION = "0.6.5" // plugin.de.fayard.buildSrcVersions + const val PLUGIN_VERSION = "0.7.0" // plugin.de.fayard.buildSrcVersions const val GRADLE_VERSIONS_PLUGIN_ID = "com.github.ben-manes.versions" const val GRADLE_VERSIONS_PLUGIN_VERSION = "0.25.0" // Sync with plugin/build.gradle.kts const val EXTENSION_NAME = "buildSrcVersions" @@ -107,7 +107,7 @@ object PluginConfig { val MEANING_LESS_NAMES: List = listOf( "common", "core", "testing", "runtime", "extensions", "compiler", "migration", "db", "rules", "runner", "monitor", "loader", - "media", "print", "io", "media", "collection", "gradle", "android" + "media", "print", "io", "collection", "gradle", "android" ) val INITIAL_GITIGNORE = """ @@ -225,6 +225,17 @@ object PluginConfig { } ) + fun computeUseFqdnFor( + dependencies: List, + configured: List, + byDefault: List = MEANING_LESS_NAMES + ) : List { + val groups = (configured + byDefault).filter { it.contains(".") }.distinct() + val depsFromGroups = dependencies.filter { it.group in groups }.map { it.module } + val ambiguities = dependencies.groupBy { it.module }.filter { it.value.size > 1 }.map { it.key } + return (configured + byDefault + ambiguities + depsFromGroups - groups).distinct().sorted() + } + var useRefreshVersions: Boolean = false lateinit var configureGradleVersions: (DependencyUpdatesTask.() -> Unit) -> Unit diff --git a/plugin/src/test/kotlin/de/fayard/FqdnTest.kt b/plugin/src/test/kotlin/de/fayard/FqdnTest.kt new file mode 100644 index 000000000..a27b83754 --- /dev/null +++ b/plugin/src/test/kotlin/de/fayard/FqdnTest.kt @@ -0,0 +1,43 @@ +package de.fayard + +import de.fayard.internal.PluginConfig +import io.kotlintest.matchers.collections.containExactlyInAnyOrder +import io.kotlintest.should +import io.kotlintest.shouldBe +import io.kotlintest.specs.FreeSpec + +class FqdnTest: FreeSpec({ + val appCompat = "androidx.appcompat:appcompat:_".asDependency() + val asyncLayoutInflater = "androidx.asynclayoutinflater:asynclayoutinflater:_".asDependency() + val browser = "androidx.browser:browser:_".asDependency() + val car = "androidx.car:car:_".asDependency() + val sliceCore = "androidx.slice:slice-core:_".asDependency() + val sliceView = "androidx.slice:slice-view:_".asDependency() + + val ALL = listOf(appCompat, asyncLayoutInflater, browser, car, sliceCore, sliceView) + val NO_DEFAULT = emptyList() + + with(PluginConfig) { + + "Nothing configured -> MEANINGLESS NAMES" { + computeUseFqdnFor(emptyList(), emptyList()) shouldBe MEANING_LESS_NAMES.sorted() + } + + "Using a dependency module" { + val result = computeUseFqdnFor(ALL, listOf("car", "car", "browser", "slice-car"), listOf("browser", "gradle")) + result shouldBe listOf("browser", "car", "gradle", "slice-car") + } + + "Using a group" { + computeUseFqdnFor(ALL, listOf("androidx.slice", "androidx.browser", "com.example"), NO_DEFAULT) shouldBe listOf("browser", "slice-core", "slice-view") + } + + "Ambiguity in module names" { + val annotations = listOf( + "androidx.annotation:annotation:_".asDependency(), + "com.example:annotation:_".asDependency() + ) + computeUseFqdnFor(annotations, emptyList(), emptyList()) shouldBe listOf("annotation") + } + } +}) diff --git a/sample-groovy/build.gradle b/sample-groovy/build.gradle index 2dff5b218..95e5fb4df 100644 --- a/sample-groovy/build.gradle +++ b/sample-groovy/build.gradle @@ -23,6 +23,8 @@ repositories { dependencies { compile("com.google.guava:guava:15.0") compile("com.google.inject:guice:2.0") + compile("androidx.annotation:annotation:1.1.0") + compile("org.jetbrains:annotation:17.0.0") } def isNonStable = { String version -> @@ -32,7 +34,7 @@ def isNonStable = { String version -> } buildSrcVersions { - useFqdnFor('module') + useFqdnFor('module', 'com.google.inject') renameLibs = "Libs" renameVersions = "Versions" indent = " " diff --git a/sample-groovy/buildSrc/src/main/kotlin/Libs.kt b/sample-groovy/buildSrc/src/main/kotlin/Libs.kt index fed87f5ae..f8fc2726a 100644 --- a/sample-groovy/buildSrc/src/main/kotlin/Libs.kt +++ b/sample-groovy/buildSrc/src/main/kotlin/Libs.kt @@ -8,9 +8,13 @@ import kotlin.String */ object Libs { const val com_gradle_build_scan_gradle_plugin: String = - "com.gradle.build-scan:com.gradle.build-scan.gradle.plugin:2.4.2" + "com.gradle.build-scan:com.gradle.build-scan.gradle.plugin:2.4.2" - const val guava: String = "com.google.guava:guava:15.0" + const val androidx_annotation_annotation: String = "androidx.annotation:annotation:1.1.0" + + const val org_jetbrains_annotation: String = "org.jetbrains:annotation:17.0.0" - const val guice: String = "com.google.inject:guice:2.0" + const val com_google_inject_guice: String = "com.google.inject:guice:2.0" + + const val guava: String = "com.google.guava:guava:15.0" } diff --git a/sample-groovy/gradle.properties b/sample-groovy/gradle.properties index 83521baff..9ddf71de0 100644 --- a/sample-groovy/gradle.properties +++ b/sample-groovy/gradle.properties @@ -8,8 +8,10 @@ resolutionStrategyConfig=verbose # You can edit the rest of the file, it will be kept intact # See https://github.com/jmfayard/buildSrcVersions/issues/77 plugin.com.github.ben-manes.versions=0.25.0 -plugin.de.fayard.buildSrcVersions=0.6.5 +plugin.de.fayard.buildSrcVersions=0.7.0 plugin.com.gradle.build-scan=2.4.2 +version.androidx.annotation..annotation=1.1.0 +version.org.jetbrains..annotation=17.0.0 +version.com.google.inject..guice=2.0 version.gradleLatestVersion=5.6.2 -version.guava=15.0 -version.guice=2.0 \ No newline at end of file +version.guava=15.0 \ No newline at end of file diff --git a/sample-kotlin/buildSrc/src/main/kotlin/Libs.kt b/sample-kotlin/buildSrc/src/main/kotlin/Libs.kt index 9ca344f81..6334aeee5 100644 --- a/sample-kotlin/buildSrc/src/main/kotlin/Libs.kt +++ b/sample-kotlin/buildSrc/src/main/kotlin/Libs.kt @@ -1,3 +1,5 @@ +import kotlin.String + /** * Generated by https://github.com/jmfayard/buildSrcVersions * @@ -6,10 +8,10 @@ */ object Libs { const val org_jetbrains_kotlin_jvm_gradle_plugin: String = - "org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:1.3.50" + "org.jetbrains.kotlin.jvm:org.jetbrains.kotlin.jvm.gradle.plugin:1.3.50" const val com_gradle_build_scan_gradle_plugin: String = - "com.gradle.build-scan:com.gradle.build-scan.gradle.plugin:2.4.2" + "com.gradle.build-scan:com.gradle.build-scan.gradle.plugin:2.4.2" const val org_mongodb_mongo_java_driver: String = "org.mongodb:mongo-java-driver:3.11.0" @@ -20,7 +22,7 @@ object Libs { const val okhttp_urlconnection: String = "com.squareup.okhttp3:okhttp-urlconnection:4.2.0" const val kotlin_scripting_compiler_embeddable: String = - "org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:1.3.50" + "org.jetbrains.kotlin:kotlin-scripting-compiler-embeddable:1.3.50" const val kotlin_stdlib_jdk8: String = "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.50" diff --git a/sample-kotlin/gradle.properties b/sample-kotlin/gradle.properties index 25079c723..21bfd2642 100644 --- a/sample-kotlin/gradle.properties +++ b/sample-kotlin/gradle.properties @@ -8,7 +8,7 @@ resolutionStrategyConfig=verbose # You can edit the rest of the file, it will be kept intact # See https://github.com/jmfayard/buildSrcVersions/issues/77 plugin.com.github.ben-manes.versions=0.25.0 -plugin.de.fayard.buildSrcVersions=0.6.5 +plugin.de.fayard.buildSrcVersions=0.7.0 plugin.org.jetbrains.kotlin.jvm=1.3.50 plugin.com.gradle.build-scan=2.4.2 version.org.mongodb..mongo-java-driver=3.11.0 diff --git a/sample-versionsOnlyMode/GROOVY_DEF.gradle b/sample-versionsOnlyMode/GROOVY_DEF.gradle index ba45abee4..75e9072e7 100644 --- a/sample-versionsOnlyMode/GROOVY_DEF.gradle +++ b/sample-versionsOnlyMode/GROOVY_DEF.gradle @@ -4,7 +4,7 @@ // Generated by ./gradle buildSrcVersions // See https://github.com/jmfayard/buildSrcVersions/issues/54 def com_github_ben_manes_versions_gradle_plugin = '0.25.0' -def de_fayard_buildsrcversions_gradle_plugin = '0.6.5' +def de_fayard_buildsrcversions_gradle_plugin = '0.7.0' def org_jetbrains_kotlin_jvm_gradle_plugin = '1.3.50' def org_jetbrains_kotlin = '1.3.50' def gradlelatestversion = '5.5.1' // available: '5.6.1' diff --git a/sample-versionsOnlyMode/GROOVY_EXT.gradle b/sample-versionsOnlyMode/GROOVY_EXT.gradle index 5fba1f03d..313237a75 100644 --- a/sample-versionsOnlyMode/GROOVY_EXT.gradle +++ b/sample-versionsOnlyMode/GROOVY_EXT.gradle @@ -5,7 +5,7 @@ // See https://github.com/jmfayard/buildSrcVersions/issues/54 ext { com_github_ben_manes_versions_gradle_plugin = '0.25.0' - de_fayard_buildsrcversions_gradle_plugin = '0.6.5' + de_fayard_buildsrcversions_gradle_plugin = '0.7.0' org_jetbrains_kotlin_jvm_gradle_plugin = '1.3.50' org_jetbrains_kotlin = '1.3.50' gradlelatestversion = '5.5.1' // available: '5.6.1' diff --git a/sample-versionsOnlyMode/KOTLIN_VAL.gradle.kts b/sample-versionsOnlyMode/KOTLIN_VAL.gradle.kts index 7ed8abecb..fa4bc2319 100644 --- a/sample-versionsOnlyMode/KOTLIN_VAL.gradle.kts +++ b/sample-versionsOnlyMode/KOTLIN_VAL.gradle.kts @@ -4,7 +4,7 @@ // Generated by ./gradle buildSrcVersions // See https://github.com/jmfayard/buildSrcVersions/issues/54 val com_github_ben_manes_versions_gradle_plugin = "0.25.0" -val de_fayard_buildsrcversions_gradle_plugin = "0.6.5" +val de_fayard_buildsrcversions_gradle_plugin = "0.7.0" val org_jetbrains_kotlin_jvm_gradle_plugin = "1.3.50" val org_jetbrains_kotlin = "1.3.50" val gradlelatestversion = "5.5.1" // available: "5.6.1" diff --git a/sample-versionsOnlyMode/gradle.properties b/sample-versionsOnlyMode/gradle.properties index 9e9c2cf0a..1f2194498 100644 --- a/sample-versionsOnlyMode/gradle.properties +++ b/sample-versionsOnlyMode/gradle.properties @@ -9,11 +9,10 @@ resolutionStrategyConfig=verbose # See https://github.com/jmfayard/buildSrcVersions/issues/77 plugin.com.github.ben-manes.versions=0.25.0 plugin.org.lovedev.greeting.kotlin=1.1 -plugin.de.fayard.buildSrcVersions=0.6.5 +plugin.de.fayard.buildSrcVersions=0.7.0 plugin.org.jetbrains.kotlin.jvm=1.3.50 plugin.ch.tutteli.kotlin.utils=0.29.0 -plugin.com.gradle.build-scan=2.4.1 -# # available=2.4.2 +plugin.com.gradle.build-scan=2.4.2 plugin.nebula.kotlin=1.3.50 version.org.jetbrains.kotlin=1.3.50 version.gradleLatestVersion=5.6.2