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 7, 2023
1 parent 6e40f72 commit 863c892
Show file tree
Hide file tree
Showing 11 changed files with 230 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,17 +15,19 @@
*/

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")
}

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,86 @@
/*
* 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 com.autonomousapps.DependencyAnalysisExtension
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

// part of work-around for https://github.com/autonomousapps/dependency-analysis-android-gradle-plugin/issues/719
buildscript {
if (!JavaVersion.current().isJava11Compatible) {
dependencies {
components {
listOf(
"com.autonomousapps:dependency-analysis-gradle-plugin",
"com.autonomousapps:graph-support"
).forEach {
withModule(it) {
allVariants {
attributes {
attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 8)
}
}
}
}
}
}
}
}

plugins {
`kotlin-dsl`
alias(libs.plugins.versions)
// part of work-around for https://github.com/autonomousapps/dependency-analysis-android-gradle-plugin/issues/719
alias(libs.plugins.dependency.analysis) apply JavaVersion.current().isJava11Compatible
}

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

// part of work-around for https://github.com/autonomousapps/dependency-analysis-android-gradle-plugin/issues/719
if (JavaVersion.current().isJava11Compatible) {
configure<DependencyAnalysisExtension> {
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}"
}
20 changes: 20 additions & 0 deletions gradle/conditional-refresh-versions/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 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.

#TODO: Remove with Gradle 8+
systemProp.org.gradle.kotlin.dsl.precompiled.accessors.strict = true

org.gradle.caching = true

dependency.analysis.print.build.health = true
37 changes: 37 additions & 0 deletions gradle/conditional-refresh-versions/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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

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,13 +15,18 @@
*/

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")
}

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 @@ -75,6 +75,7 @@ if (gradle.parent == null && parent == null) {
dependencies {
gradle
.includedBuilds
.filterNot { it.name == "conditional-refresh-versions" }
.forEach { dependencyUpdatesResults(":${it.name}") }
}

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,22 +15,24 @@
*/

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

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

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 863c892

Please sign in to comment.