Skip to content

Commit

Permalink
Apply refreshVersions only when called
Browse files Browse the repository at this point in the history
This is a work-around for Splitties/refreshVersions#667.
  • Loading branch information
Vampire committed Feb 16, 2023
1 parent 32af37a commit c2e1cac
Show file tree
Hide file tree
Showing 11 changed files with 204 additions and 6 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
/build/
/gradle/build-logic/.gradle/
/gradle/build-logic/build/
/gradle/conditional-refresh-versions/.gradle/
/gradle/conditional-refresh-versions/build/
/gradle/dependency-updates-report-aggregation/.gradle/
/gradle/dependency-updates-report-aggregation/build/
/ncc-packer/build/
6 changes: 4 additions & 2 deletions gradle/build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,23 @@
*/

import de.fayard.refreshVersions.core.FeatureFlag.GRADLE_UPDATES
import net.kautler.conditionalRefreshVersions
import org.gradle.api.initialization.resolve.RepositoriesMode.FAIL_ON_PROJECT_REPOS

pluginManagement {
includeBuild("../dependency-updates-report-aggregation")
includeBuild("../conditional-refresh-versions")
repositories {
mavenCentral()
gradlePluginPortal()
}
}

plugins {
id("de.fayard.refreshVersions") version "0.51.0"
id("net.kautler.conditional-refresh-versions")
}

refreshVersions {
conditionalRefreshVersions {
featureFlags {
disable(GRADLE_UPDATES)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2020-2023 Björn Kautler
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
`kotlin-dsl`
alias(libs.plugins.versions)
alias(libs.plugins.dependency.analysis)
}

dependencies {
implementation(plugin(libs.plugins.refresh.versions))
}

dependencyAnalysis {
dependencies {
bundle("de.fayard.refreshVersions.gradle.plugin") {
includeDependency("de.fayard.refreshVersions:de.fayard.refreshVersions.gradle.plugin")
includeDependency("de.fayard.refreshVersions:refreshVersions")
includeDependency("de.fayard.refreshVersions:refreshVersions-core")
}
}
issues {
all {
onAny {
severity("fail")
}
}
}
}

tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
allWarningsAsErrors = true
}
}

tasks.dependencyUpdates {
checkForGradleUpdate = false
checkConstraints = true
}

fun plugin(plugin: Provider<PluginDependency>) = plugin.map {
"${it.pluginId}:${it.pluginId}.gradle.plugin:${it.version.requiredVersion}"
}
17 changes: 17 additions & 0 deletions gradle/conditional-refresh-versions/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2020-2023 Björn Kautler
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

org.gradle.caching = true

dependency.analysis.print.build.health = true
44 changes: 44 additions & 0 deletions gradle/conditional-refresh-versions/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright 2020-2023 Björn Kautler
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import org.gradle.api.initialization.resolve.RepositoriesMode.FAIL_ON_PROJECT_REPOS

pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
}
}

dependencyResolutionManagement {
repositories {
mavenCentral()
gradlePluginPortal()
}
repositoriesMode.set(FAIL_ON_PROJECT_REPOS)

versionCatalogs {
create("libs") {
from(files("../libs.versions.toml"))
}
}
}

rootProject.name = "conditional-refresh-versions"
rootProject.buildFileName = "conditional-refresh-versions.gradle.kts"

enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
enableFeaturePreview("STABLE_CONFIGURATION_CACHE")
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright 2020-2023 Björn Kautler
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.kautler

import de.fayard.refreshVersions.RefreshVersionsExtension
import org.gradle.api.initialization.Settings
import org.gradle.api.invocation.Gradle
import org.gradle.kotlin.dsl.refreshVersions

inline fun Settings.onRefreshVersionsRequested(configure: Settings.() -> Unit) {
val rootBuild = gradle.parent == null
val startTaskNames = gradle.rootBuild.startParameter.taskNames
if (
(rootBuild && (startTaskNames.contains(":refreshVersions") || startTaskNames.contains("refreshVersions")))
|| (!rootBuild && startTaskNames.contains(":${settings.rootProject.name}:refreshVersions"))
) {
configure()
}
}

inline fun Settings.conditionalRefreshVersions(configure: RefreshVersionsExtension.() -> Unit) {
onRefreshVersionsRequested {
refreshVersions(configure)
}
}

val Gradle.rootBuild: Gradle
get() = if (gradle.parent == null) gradle else gradle.parent!!.rootBuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright 2020-2023 Björn Kautler
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.kautler

require(gradle.rootBuild.startParameter.taskNames.count { it.endsWith("refreshVersions") } <= 1) {
"Only one refreshVersions task can be executed per Gradle run"
}

onRefreshVersionsRequested {
apply(plugin = "de.fayard.refreshVersions")
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,22 @@
*/

import de.fayard.refreshVersions.core.FeatureFlag.GRADLE_UPDATES
import net.kautler.conditionalRefreshVersions
import org.gradle.api.initialization.resolve.RepositoriesMode.FAIL_ON_PROJECT_REPOS

pluginManagement {
includeBuild("../conditional-refresh-versions")
repositories {
mavenCentral()
gradlePluginPortal()
}
}

plugins {
id("de.fayard.refreshVersions") version "0.51.0"
id("net.kautler.conditional-refresh-versions")
}

refreshVersions {
conditionalRefreshVersions {
featureFlags {
disable(GRADLE_UPDATES)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ if (gradle.parent == null && parent == null) {

dependencies {
includedBuildNames
.filterNot { it == "conditional-refresh-versions" }
.forEach { dependencyUpdatesResults(":$it") }
}

Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ build-github-api = "1.117"
build-gradle-plugin-dependency-analysis = "1.19.0"
build-gradle-plugin-github = "1.4.0"
build-gradle-plugin-grgit = "4.1.1"
build-gradle-plugin-refresh-versions = "0.51.0"
build-gradle-plugin-release = "2.8.1"
build-gradle-plugin-versions = "0.45.0"
build-inject = "1"
Expand Down Expand Up @@ -67,5 +68,6 @@ github = { id = "net.wooga.github", version.ref = "build-gradle-plugin-github" }
grgit = { id = "org.ajoberstar.grgit", version.ref = "build-gradle-plugin-grgit" }
kotlin-js = { id = "org.jetbrains.kotlin.js", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "build-kotlin" }
refresh-versions = { id = "de.fayard.refreshVersions", version.ref = "build-gradle-plugin-refresh-versions" }
release = { id = "net.researchgate.release", version.ref = "build-gradle-plugin-release" }
versions = { id = "com.github.ben-manes.versions", version.ref = "build-gradle-plugin-versions" }
6 changes: 4 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import de.fayard.refreshVersions.core.FeatureFlag.GRADLE_UPDATES
import net.kautler.conditionalRefreshVersions
import org.gradle.api.initialization.resolve.RepositoriesMode.PREFER_SETTINGS

pluginManagement {
Expand All @@ -23,18 +24,19 @@ pluginManagement {
}

includeBuild("gradle/build-logic")
includeBuild("gradle/conditional-refresh-versions")
repositories {
mavenCentral()
gradlePluginPortal()
}
}

plugins {
id("de.fayard.refreshVersions") version "0.51.0"
id("net.kautler.conditional-refresh-versions")
id("com.gradle.enterprise") version "3.12.3"
}

refreshVersions {
conditionalRefreshVersions {
featureFlags {
disable(GRADLE_UPDATES)
}
Expand Down

0 comments on commit c2e1cac

Please sign in to comment.