Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

de.fayard.refreshVersions v0.7.0 : #65 #102 #104 #103

Merged
merged 8 commits into from
Oct 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# Unreleased

# 0.7.0

The plugin will in the future focus on `:refreshVersions`.

For now it is published under two names, with an identical content:

```
plugins {
id("de.fayard.refreshVersions").version("0.7.0")
// or
id("de.fayard.buildSrcVersions).version("0.7.0")
}
```

Next step: integration with https://github.com/LouisCAD/Splitties

See https://github.com/jmfayard/buildSrcVersions/issues/104

Changes:

- New configuration: orderBy = GROUP_AND_LENGTH or GROUP_AND_ALPHABETICAL #65
- PluginConfig.virtualGroups for kotlinx-coroutines #102




# 0.6.5

- useFqdnFor() should also work for groups #99
Expand Down
30 changes: 16 additions & 14 deletions README.adoc
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// plugin.de.fayard.buildSrcVersions
:plugin_version: 0.6.5
// plugin.de.fayard.buildSrcVersions (aka buildSrcVersions)
:plugin_version: 0.7.0
:gradle_version: 5.6.2
:imagesdir: doc
:repo: jmfayard/buildSrcVersions
:branch: 26-buildSrcVersions
:github: https://github.com/{repo}
:plugin_issues: https://github.com/gradle/kotlin-dsl/issues?utf8=%E2%9C%93&q=author%3Ajmfayard+
:plugin_gradle_portal: https://plugins.gradle.org/plugin/de.fayard.buildSrcVersions
:plugin_gradle_portal: https://plugins.gradle.org/plugin/de.fayard.refreshVersions
:contributors_badge: image:https://www.codetriage.com/jmfayard/buildsrcversions/badges/users.svg["Code Triage",link="https://www.codetriage.com/jmfayard/buildsrcversions"]
:gradle_kotlin_dsl: https://github.com/gradle/kotlin-dsl
:slack_url: https://app.slack.com/client/T09229ZC6/CP5659EL9
Expand All @@ -17,12 +18,11 @@
:medium_protips: https://proandroiddev.com/android-studio-pro-tips-for-working-with-gradle-8a7aa61a8cc4
:medium_mvp: https://dev.to/jmfayard/the-minimum-viable-pull-request-5e7p
:devto_readme: https://dev.to/jmfayard/how-to-write-a-good-readme-discuss-4hkl
:root: file:///Users/jmfayard/Dev/mautinoa/buildSrcVersions
:issues: https://github.com/jmfayard/buildSrcVersions/issues
:master: https://github.com/jmfayard/buildSrcVersions/blob/master
:badge_mit: image:https://img.shields.io/github/license/mashape/apistatus.svg["GitHub",link="{github}/blob/master/LICENSE.txt"]
:image_version: https://img.shields.io/maven-metadata/v/https/plugins.gradle.org/m2/de.fayard/buildSrcVersions/de.fayard.buildSrcVersions.gradle.plugin/maven-metadata.xml.svg
:badge_version: image:{image_version}?label=gradlePluginPortal["Maven Central",link="https://plugins.gradle.org/plugin/de.fayard.buildSrcVersions"]
:image_version: https://img.shields.io/maven-metadata/v/https/plugins.gradle.org/m2/de.fayard/refreshVersions/de.fayard.refreshVersions.gradle.plugin/maven-metadata.xml.svg
:badge_version: image:{image_version}?label=gradlePluginPortal["Maven Central",link="https://plugins.gradle.org/plugin/de.fayard.refreshVersions"]
:badge_issues: image:https://img.shields.io/github/issues/{repo}.svg["GitHub issues",link="{github}/issues"]
:badge_pr: image:https://img.shields.io/github/issues-pr/{repo}.svg["GitHub pull requests",link="{github}/pulls?utf8=%E2%9C%93&q=is%3Apr+"]
:badge_build: image:https://img.shields.io/travis/com/{repo}/{branch}.svg["Travis (.org)",link="https://travis-ci.com/{repo}"]
Expand All @@ -31,19 +31,20 @@
:benmanes: https://github.com/ben-manes/gradle-versions-plugin
:image_faq: https://user-images.githubusercontent.com/459464/64926128-1a076980-d7fa-11e9-8a69-eb354d211f51.png

//:imagesdir: /Users/jmfayard/Dev/mautinoa/buildSrcVersions/doc
:imagesdir: doc


= de.fayard.buildSrcVersions
= de.fayard.refreshVersions

{badge_version} {slack_badge} {contributors_badge} {badge_build} {badge_mit} {badge_issues} {badge_pr}

The Gradle plugin `de.fayard.buildSrcVersions` goal is to make it as painless as possible to upgrade your project to the latest and greatest version of everything.
The Gradle plugin `de.fayard.refreshVersions` goal is to make it as painless as possible to upgrade your project to the latest and greatest version of everything.

It does that by extracting all your dependencies, searching for available dependencies updates
and generating Kotlin code, Groovy code or Gradle properties.

The plugin was called before `de.fayard.buildSrcVersions`, which still exists and is currently identical.

[The goal in the future is to focus on :refreshVersions](https://github.com/jmfayard/buildSrcVersions/issues/104)

== Installation

Edit your root `build.gradle(.kts)` file
Expand All @@ -56,7 +57,7 @@ buildscript {
//...
}
plugins {
id("de.fayard.buildSrcVersions") version "{plugin_version}"
id("de.fayard.refreshVersions") version "{plugin_version}"
}
// Don't put any code before the buildscripts {} and plugins {} block
----
Expand All @@ -82,11 +83,11 @@ buildscript {
}
}
dependencies {
classpath "de.fayard.buildSrcVersions:de.fayard.buildSrcVersions.gradle.plugin:{plugin_version}"
classpath "de.fayard.refrshVersions:de.fayard.refrshVersions.gradle.plugin:{plugin_version}"
}
}

apply plugin: "de.fayard.buildSrcVersions"
apply plugin: "de.fayard.refrshVersions"
----
++++
</details>
Expand Down Expand Up @@ -146,6 +147,7 @@ buildSrcVersions {
rejectVersionIf {
isNonStable(candidate.version)
}
orderBy = OrderBy.GROUP_AND_LENGTH
indent = "from-editorconfig-file"
renameLibs = "Libs"
renameVersions = "Versions"
Expand Down
2 changes: 1 addition & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- Create a GitHub release https://github.com/jmfayard/buildSrcVersions/releases/new
- Try the plugin in sample projects
- Update `:plugin_version:` in `README.adoc`
- Search for `plugin.de.fayard.buildSrcVersions` everywhere to update the version
- Search for `plugin.de.fayard.refreshVersions` everywhere to update the version
- Otherwise update the README
- Update Plugin Configuration https://github.com/jmfayard/buildSrcVersions/issues/53

Expand Down
10 changes: 8 additions & 2 deletions plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,21 @@ plugins {
}


version = "0.7.0" // plugin.de.fayard.buildSrcVersions
version = "0.7.1" // plugin.de.fayard.refreshversions
group = "de.fayard"


gradlePlugin {
plugins {
create("buildSrcVersions") {
id = "de.fayard.buildSrcVersions"
displayName = "buildSrcVersions"
displayName = "./gradlew buildSrcVersions"
description = "Painless dependencies management"
implementationClass = "de.fayard.BuildSrcVersionsPlugin"
}
create("refreshVersions") {
id = "de.fayard.refreshVersions"
displayName = "./gradlew refreshVersions"
description = "Painless dependencies management"
implementationClass = "de.fayard.BuildSrcVersionsPlugin"
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# See https://github.com/jmfayard/buildSrcVersions/issues/77
plugin.org.gradle.kotlin.kotlin.dsl=1.2.9
# available=1.3.1
plugin.de.fayard.buildsrcversions=0.6.4
plugin.de.fayard.refreshVersions=0.7.0
plugin.com.gradle.plugin-publish=0.10.0
# available=0.10.1
plugin.com.gradle.build-scan=2.4.1
Expand Down
8 changes: 8 additions & 0 deletions plugin/src/main/kotlin/de/fayard/BuildSrcVersionsExtension.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,13 @@ interface BuildSrcVersionsExtension {
*/
var versionsOnlyFile: String?

/**
* orderBy = OrderBy.GROUP_AND_ALPHABETICAL to override the default behavior
* https://github.com/jmfayard/buildSrcVersions/issues/65 **/
var orderBy: OrderBy

}

enum class OrderBy {
GROUP_AND_LENGTH, GROUP_AND_ALPHABETICAL
}
2 changes: 1 addition & 1 deletion plugin/src/main/kotlin/de/fayard/BuildSrcVersionsPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import org.gradle.kotlin.dsl.extra
open class BuildSrcVersionsPlugin : Plugin<Project> {

override fun apply(project: Project) {
check(project == project.rootProject) { "ERROR: plugins de.fayard.buildSrcVersions must be applied to the root build.gradle(.kts)" }
check(project == project.rootProject) { "ERROR: plugins de.fayard.refreshVersions must be applied to the root build.gradle(.kts)" }
project.apply(plugin = PluginConfig.GRADLE_VERSIONS_PLUGIN_ID)
project.configure()
project.useVersionsFromGradleProperties()
Expand Down
6 changes: 3 additions & 3 deletions plugin/src/main/kotlin/de/fayard/BuildSrcVersionsTask.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ open class BuildSrcVersionsTask : DefaultTask() {
KOTLIN_OBJECT -> false
else -> return
}
val versions = unsortedParsedDependencies.sortedBeautifullyBy { it.versionName }
val versions = unsortedParsedDependencies.sortedBeautifullyBy(extension.orderBy) { it.versionName }

val kotlinPoetry: KotlinPoetry = kotlinpoet(versions, dependencyGraph.gradle, extension, computeIndent())

Expand Down Expand Up @@ -109,7 +109,7 @@ open class BuildSrcVersionsTask : DefaultTask() {
}

val dependencies = (unsortedParsedDependencies + specialDependencies)
.sortedBeautifullyBy { it.versionProperty }
.sortedBeautifullyBy(extension.orderBy) { it.versionProperty }
.distinctBy { it.versionProperty }

if (versionsOnlyMode == GRADLE_PROPERTIES) {
Expand Down Expand Up @@ -155,7 +155,7 @@ open class BuildSrcVersionsTask : DefaultTask() {
val projectExtension = project.extensions.getByType<BuildSrcVersionsExtension>() as BuildSrcVersionsExtensionImpl
this._extension = projectExtension.defensiveCopy()
action.execute(this._extension)
PluginConfig.useRefreshVersions = project.hasProperty("plugin.de.fayard.buildSrcVersions")
PluginConfig.useRefreshVersions = project.hasProperty("plugin.de.fayard.buildSrcVersions") || project.hasProperty("plugin.de.refreshVersions")
}

private fun computeIndent(): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package de.fayard.internal

import com.github.benmanes.gradle.versions.updates.resolutionstrategy.ComponentFilter
import de.fayard.BuildSrcVersionsExtension
import de.fayard.OrderBy
import de.fayard.VersionsOnlyMode

internal open class BuildSrcVersionsExtensionImpl(
Expand All @@ -11,12 +12,13 @@ internal open class BuildSrcVersionsExtensionImpl(
override var versionsOnlyMode: VersionsOnlyMode? = null,
override var versionsOnlyFile: String? = null,
var useFqqnFor: List<String> = emptyList(),
var alwaysUpdateVersions: Boolean = false
var alwaysUpdateVersions: Boolean = false,
override var orderBy: OrderBy = OrderBy.GROUP_AND_LENGTH
) : BuildSrcVersionsExtension, java.io.Serializable {

// Necessary because of https://github.com/jmfayard/buildSrcVersions/issues/92
fun defensiveCopy(): BuildSrcVersionsExtensionImpl = BuildSrcVersionsExtensionImpl(
renameLibs, renameVersions, indent, versionsOnlyMode, versionsOnlyFile, useFqqnFor, alwaysUpdateVersions
renameLibs, renameVersions, indent, versionsOnlyMode, versionsOnlyFile, useFqqnFor, alwaysUpdateVersions, orderBy
)

override fun alwaysUpdateVersions() {
Expand Down
15 changes: 14 additions & 1 deletion plugin/src/main/kotlin/de/fayard/internal/DependencyGraph.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ data class Dependency(
var mode: VersionMode = VersionMode.MODULE,
val available: AvailableDependency? = null
) {
fun groupOrVirtualGroup() : String = virtualGroup(this) ?: group

val module: String get() = name
val versionName: String
get() = PluginConfig.versionKtFor(this)
Expand All @@ -52,10 +54,21 @@ data class Dependency(
else -> this.copy(available = null, version = newerVersion)
}
}

companion object {
fun virtualGroup(dependency: Dependency, withVersion: Boolean = false): String? {
val virtualGroup = PluginConfig.virtualGroups.firstOrNull { "${dependency.group}.${dependency.module}".startsWith(it) }
return when {
virtualGroup == null -> null
withVersion -> "version.$virtualGroup"
else -> virtualGroup
}
}
}
}

enum class VersionMode {
MODULE, GROUP, GROUP_MODULE
GROUP, GROUP_MODULE, MODULE
}

data class GradleConfig(
Expand Down
21 changes: 14 additions & 7 deletions plugin/src/main/kotlin/de/fayard/internal/KotlinPoetry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import com.squareup.kotlinpoet.PropertySpec
import com.squareup.kotlinpoet.TypeSpec
import com.squareup.kotlinpoet.asClassName
import de.fayard.BuildSrcVersionsExtension
import de.fayard.OrderBy
import de.fayard.OrderBy.*
import org.gradle.plugin.use.PluginDependenciesSpec
import org.gradle.plugin.use.PluginDependencySpec

Expand Down Expand Up @@ -62,10 +64,14 @@ fun kotlinpoet(
}

// https://github.com/jmfayard/buildSrcVersions/issues/65
fun <T> List<T>.sortedBeautifullyBy(exceptIf: Boolean = false, selection: (T) -> String?) : List<T> =
this.filterNot { selection(it) == null }
fun List<Dependency>.sortedBeautifullyBy(orderBy: OrderBy, selection: (Dependency) -> String?) : List<Dependency> {
val unsorted = this.filterNot { selection(it) == null }
.sortedBy { selection(it)!! }
.sortedByDescending { selection(it)!!.length }
return when(orderBy) {
GROUP_AND_LENGTH -> unsorted.sortedByDescending { selection(it)!!.length }.sortedBy { it.mode }
GROUP_AND_ALPHABETICAL -> unsorted.sortedBy { it.mode }
}
}

fun FileSpec.Builder.addMaybeBuildSrcVersions(versions: List<Dependency>, extension: BuildSrcVersionsExtension) {
versions.firstOrNull {
Expand Down Expand Up @@ -151,7 +157,7 @@ fun List<Dependency>.checkModeAndNames(useFdqnByDefault: List<String>): List<Dep
d.escapedName = PluginConfig.escapeVersionsKt(
when (d.mode) {
VersionMode.MODULE -> d.name
VersionMode.GROUP -> d.group
VersionMode.GROUP -> d.groupOrVirtualGroup()
VersionMode.GROUP_MODULE -> "${d.group}_${d.name}"
}
)
Expand All @@ -166,10 +172,11 @@ fun List<Dependency>.orderDependencies(): List<Dependency> {


fun List<Dependency>.findCommonVersions(): List<Dependency> {
val map = groupBy { d -> d.group }
val map = groupBy { d: Dependency -> d.groupOrVirtualGroup() }
for (deps in map.values) {
val groupTogether = deps.size > 1 && deps.map { it.version }.distinct().size == 1
if (groupTogether) {
val sameVersions = deps.map { it.version }.distinct().size == 1
val hasVirtualGroup = deps.any { it.groupOrVirtualGroup() != it.group }
if (sameVersions && (hasVirtualGroup || deps.size > 1)) {
deps.forEach { d -> d.mode = VersionMode.GROUP }
}
}
Expand Down
24 changes: 18 additions & 6 deletions plugin/src/main/kotlin/de/fayard/internal/PluginConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ import java.io.File
object PluginConfig {



const val PLUGIN_ID = "de.fayard.buildSrcVersions"
const val PLUGIN_VERSION = "0.7.0" // plugin.de.fayard.buildSrcVersions
const val PLUGIN_ID = "de.fayard.refreshVersions"
const val PLUGIN_VERSION = "0.7.0" // plugin.de.fayard.refreshVersions
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"
Expand Down Expand Up @@ -48,23 +47,36 @@ object PluginConfig {
* Gradle properties can be set either in "gradle.properties" or from the command-line with
* $ ./gradlew -Pversion.kotlin.stdlib=1.3.50
* **/
fun considerGradleProperties(group: String, module: String): List<String> = listOf(
fun considerGradleProperties(group: String, module: String): List<String> = listOfNotNull(
"version.$group..$module",
Dependency.virtualGroup(Dependency(group = group, name = module)),
"version.$group",
"version.$module"
)

/**
* We want to treat all "org.getbrains.kotlinx:kotlinx-coroutines-*" as if they were a maven group
* with one common version, but different from org.jetbrains.kotlinx:kotlinx-serialization*
* For now this list is not part of the public API but feel free to add feedback that you need it.
* Add your use case here https://github.com/jmfayard/buildSrcVersions/issues/102
***/
val virtualGroups : MutableList<String> = mutableListOf(
"org.jetbrains.kotlinx.kotlinx-coroutines",
"org.jetbrains.kotlinx.kotlinx-serialization"
)


@JvmStatic
fun versionPropertyFor(d: Dependency): String = when (d.mode) {
MODULE -> d.name
GROUP -> d.group
GROUP -> d.groupOrVirtualGroup()
GROUP_MODULE -> "${d.group}..${d.name}"
}

fun versionKtFor(d: Dependency): String = escapeVersionsKt(
when (d.mode) {
MODULE -> d.name
GROUP -> d.group
GROUP -> d.groupOrVirtualGroup()
GROUP_MODULE -> "${d.group}:${d.name}"
}
)
Expand Down
Loading