diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts index 96f7c14a1..8d67c6a04 100644 --- a/plugin/build.gradle.kts +++ b/plugin/build.gradle.kts @@ -29,6 +29,7 @@ publishing { } repositories { + maven("/Users/jmfayard/try/gradle-versions-plugin/build/repository") mavenCentral() jcenter() } @@ -41,7 +42,7 @@ pluginBundle { dependencies { testImplementation("io.kotlintest:kotlintest-runner-junit5:3.1.9") - implementation("com.github.ben-manes:gradle-versions-plugin:0.22.0") + implementation("com.github.ben-manes:gradle-versions-plugin:0.24.0") implementation("com.squareup.okio:okio:2.1.0") implementation( "com.squareup.moshi:moshi:1.7.0") diff --git a/plugin/src/main/kotlin/de/fayard/BuildSrcVersionsExtension.kt b/plugin/src/main/kotlin/de/fayard/BuildSrcVersionsExtension.kt index cd2e8a49d..34fdf3a20 100644 --- a/plugin/src/main/kotlin/de/fayard/BuildSrcVersionsExtension.kt +++ b/plugin/src/main/kotlin/de/fayard/BuildSrcVersionsExtension.kt @@ -1,12 +1,21 @@ package de.fayard +import com.github.benmanes.gradle.versions.updates.resolutionstrategy.ComponentSelectionWithCurrent +import org.gradle.api.Transformer + interface BuildSrcVersionsExtension { var useFdqnFor: MutableList fun useFdqnFor(vararg dependencyName: String) + fun rejectVersionIf(filter: Transformer) + + var filter: Transformer + + //@Deprecated("use rejectVersionIf") var rejectedVersionKeywords: MutableList + //@Deprecated("use rejectVersionIf") fun rejectedVersionKeywords(vararg keyword: String) var renameLibs : String @@ -19,6 +28,7 @@ interface BuildSrcVersionsExtension { var versionsOnlyFile : String? + } open class BuildSrcVersionsExtensionImpl( @@ -31,6 +41,12 @@ open class BuildSrcVersionsExtensionImpl( override var rejectedVersionKeywords: MutableList = PluginConfig.DEFAULT_REJECTED_KEYWORDS ) : BuildSrcVersionsExtension { + @Transient + override var filter: Transformer = PluginConfig.defaultFilter + + override fun rejectVersionIf(filter: Transformer) { + this.filter = filter + } override fun rejectedVersionKeywords(vararg keyword: String) { rejectedVersionKeywords = keyword.toMutableList() diff --git a/plugin/src/main/kotlin/de/fayard/BuildSrcVersionsPlugin.kt b/plugin/src/main/kotlin/de/fayard/BuildSrcVersionsPlugin.kt index c11c88d72..31e131ee1 100644 --- a/plugin/src/main/kotlin/de/fayard/BuildSrcVersionsPlugin.kt +++ b/plugin/src/main/kotlin/de/fayard/BuildSrcVersionsPlugin.kt @@ -10,10 +10,10 @@ open class BuildSrcVersionsPlugin : Plugin { override fun apply(project: Project) = project.run { - configureBenManesVersions() - extensions.create(BuildSrcVersionsExtension::class, PluginConfig.EXTENSION_NAME, BuildSrcVersionsExtensionImpl::class) + configureBenManesVersions() + tasks.create("buildSrcVersions", BuildSrcVersionsTask::class) { group = "Help" description = "Update buildSrc/src/main/kotlin/{Versions.kt,Libs.kt}" @@ -24,28 +24,10 @@ open class BuildSrcVersionsPlugin : Plugin { Unit } - fun Project.configureBenManesVersions(): DependencyUpdatesTask { - val rejectedKeywordsRegexps: List by lazy { - project.extensions.getByType().rejectedVersionKeywords - .map { qualifier -> Regex("(?i).*[.-]$qualifier[.\\d-]*") } - } - - val benManesVersions: DependencyUpdatesTask = - tasks.maybeCreate("dependencyUpdates", DependencyUpdatesTask::class.java) - - benManesVersions.outputFormatter = "json" - benManesVersions.checkForGradleUpdate = true - benManesVersions.resolutionStrategy { - - componentSelection { - all { - if (rejectedKeywordsRegexps.any { it.matches(candidate.version) }) { - reject("Release candidate") - } - } - } - + fun Project.configureBenManesVersions(): DependencyUpdatesTask = + tasks.maybeCreate("dependencyUpdates", DependencyUpdatesTask::class.java).also { task: DependencyUpdatesTask -> + task.checkForGradleUpdate = true + task.outputFormatter = "json" + task.rejectVersionIf(project.extensions.getByType().filter) } - return benManesVersions - } } diff --git a/plugin/src/main/kotlin/de/fayard/PluginConfig.kt b/plugin/src/main/kotlin/de/fayard/PluginConfig.kt index 4dc55f16e..5a150d8a2 100644 --- a/plugin/src/main/kotlin/de/fayard/PluginConfig.kt +++ b/plugin/src/main/kotlin/de/fayard/PluginConfig.kt @@ -1,9 +1,11 @@ package de.fayard +import com.github.benmanes.gradle.versions.updates.resolutionstrategy.ComponentSelectionWithCurrent import com.squareup.moshi.JsonAdapter import com.squareup.moshi.Moshi import okio.buffer import okio.source +import org.gradle.api.Transformer import java.io.File object PluginConfig { @@ -15,6 +17,17 @@ object PluginConfig { */ const val EXTENSION_NAME = "buildSrcVersions" + fun isNonStable(version: String): Boolean { + val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.toUpperCase().contains(it) } + val regex = "^[0-9,.v-]+$".toRegex() + val isStable = stableKeyword || regex.matches(version) + return isStable.not() + } + + val defaultFilter = Transformer { current: ComponentSelectionWithCurrent -> + isNonStable(current.candidate.version) + } + const val DEFAULT_LIBS = "Libs" const val DEFAULT_VERSIONS = "Versions" const val DEFAULT_INDENT = " " diff --git a/sample-groovy/buildSrc/src/main/kotlin/Versions.kt b/sample-groovy/buildSrc/src/main/kotlin/Versions.kt index ecab5b09a..218c8a4b0 100644 --- a/sample-groovy/buildSrc/src/main/kotlin/Versions.kt +++ b/sample-groovy/buildSrc/src/main/kotlin/Versions.kt @@ -27,5 +27,5 @@ object Versions { */ const val gradleLatestVersion: String = "5.6.2" - const val gradleCurrentVersion: String = "5.6.1" + const val gradleCurrentVersion: String = "5.6.2" } diff --git a/sample-groovy/settings.gradle b/sample-groovy/settings.gradle index e0944b122..89ac30ef4 100644 --- a/sample-groovy/settings.gradle +++ b/sample-groovy/settings.gradle @@ -1,3 +1,10 @@ +pluginManagement { + repositories { + def localGradleRepo = "/Users/jmfayard/try/gradle-versions-plugin/build/repository" + if (new File(localGradleRepo).exists()) maven { setUrl(localGradleRepo) } + gradlePluginPortal() + } +} rootProject.name = 'sample-groovy' includeBuild '../plugin' diff --git a/sample-kotlin/build.gradle.kts b/sample-kotlin/build.gradle.kts index 55115370c..71df476a5 100644 --- a/sample-kotlin/build.gradle.kts +++ b/sample-kotlin/build.gradle.kts @@ -1,3 +1,5 @@ +import com.github.benmanes.gradle.versions.updates.resolutionstrategy.ComponentSelectionWithCurrent +import de.fayard.PluginConfig import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { kotlin("jvm") version "1.3.11" @@ -30,5 +32,8 @@ buildSrcVersions { renameLibs = "Libs" renameVersions = "Versions" indent = " " - rejectedVersionKeywords("alpha", "beta", "rc", "cr", "m", "preview", "eap") + + rejectVersionIf { current: ComponentSelectionWithCurrent -> + PluginConfig.isNonStable(current.candidate.version) || PluginConfig.isNonStable(current.currentVersion) + } } diff --git a/sample-kotlin/settings.gradle.kts b/sample-kotlin/settings.gradle.kts index 25062ddda..4373e05fa 100644 --- a/sample-kotlin/settings.gradle.kts +++ b/sample-kotlin/settings.gradle.kts @@ -1,3 +1,10 @@ +pluginManagement { + repositories { + val localGradleRepo = "/Users/jmfayard/try/gradle-versions-plugin/build/repository" + if (File(localGradleRepo).exists()) maven { setUrl(localGradleRepo) } + gradlePluginPortal() + } +} rootProject.name = "sample-kotlin" includeBuild("../plugin") diff --git a/sample-versionsOnlyMode/settings.gradle.kts b/sample-versionsOnlyMode/settings.gradle.kts index c0fa0cf5e..fb850c55a 100644 --- a/sample-versionsOnlyMode/settings.gradle.kts +++ b/sample-versionsOnlyMode/settings.gradle.kts @@ -1,3 +1,10 @@ +pluginManagement { + repositories { + val localGradleRepo = "/Users/jmfayard/try/gradle-versions-plugin/build/repository" + if (File(localGradleRepo).exists()) maven { setUrl(localGradleRepo) } + gradlePluginPortal() + } +} rootProject.name = "sample-versionsOnlyMode" includeBuild("../plugin")