diff --git a/.gitignore b/.gitignore index d01689f0..fbdc97f6 100644 --- a/.gitignore +++ b/.gitignore @@ -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/ diff --git a/gradle/build-logic/settings.gradle.kts b/gradle/build-logic/settings.gradle.kts index fb2bd1a5..c0191b11 100644 --- a/gradle/build-logic/settings.gradle.kts +++ b/gradle/build-logic/settings.gradle.kts @@ -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) } diff --git a/gradle/conditional-refresh-versions/conditional-refresh-versions.gradle.kts b/gradle/conditional-refresh-versions/conditional-refresh-versions.gradle.kts new file mode 100644 index 00000000..1591f1fc --- /dev/null +++ b/gradle/conditional-refresh-versions/conditional-refresh-versions.gradle.kts @@ -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 { + 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().configureEach { + kotlinOptions { + allWarningsAsErrors = true + } +} + +tasks.dependencyUpdates { + checkForGradleUpdate = false + checkConstraints = true +} + +fun plugin(plugin: Provider) = plugin.map { + "${it.pluginId}:${it.pluginId}.gradle.plugin:${it.version.requiredVersion}" +} diff --git a/gradle/conditional-refresh-versions/gradle.properties b/gradle/conditional-refresh-versions/gradle.properties new file mode 100644 index 00000000..f871ca35 --- /dev/null +++ b/gradle/conditional-refresh-versions/gradle.properties @@ -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 diff --git a/gradle/conditional-refresh-versions/settings.gradle.kts b/gradle/conditional-refresh-versions/settings.gradle.kts new file mode 100644 index 00000000..a4b8601c --- /dev/null +++ b/gradle/conditional-refresh-versions/settings.gradle.kts @@ -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") diff --git a/gradle/conditional-refresh-versions/src/main/kotlin/net/kautler/ExtensionConfiguration.kt b/gradle/conditional-refresh-versions/src/main/kotlin/net/kautler/ExtensionConfiguration.kt new file mode 100644 index 00000000..71d3e9d4 --- /dev/null +++ b/gradle/conditional-refresh-versions/src/main/kotlin/net/kautler/ExtensionConfiguration.kt @@ -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 diff --git a/gradle/conditional-refresh-versions/src/main/kotlin/net/kautler/conditional-refresh-versions.settings.gradle.kts b/gradle/conditional-refresh-versions/src/main/kotlin/net/kautler/conditional-refresh-versions.settings.gradle.kts new file mode 100644 index 00000000..ea64a853 --- /dev/null +++ b/gradle/conditional-refresh-versions/src/main/kotlin/net/kautler/conditional-refresh-versions.settings.gradle.kts @@ -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") +} diff --git a/gradle/dependency-updates-report-aggregation/settings.gradle.kts b/gradle/dependency-updates-report-aggregation/settings.gradle.kts index 13641d91..d9278fc5 100644 --- a/gradle/dependency-updates-report-aggregation/settings.gradle.kts +++ b/gradle/dependency-updates-report-aggregation/settings.gradle.kts @@ -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) } diff --git a/gradle/dependency-updates-report-aggregation/src/main/kotlin/net/kautler/dependency-updates-report-aggregation.gradle.kts b/gradle/dependency-updates-report-aggregation/src/main/kotlin/net/kautler/dependency-updates-report-aggregation.gradle.kts index 4364465d..d49cf787 100644 --- a/gradle/dependency-updates-report-aggregation/src/main/kotlin/net/kautler/dependency-updates-report-aggregation.gradle.kts +++ b/gradle/dependency-updates-report-aggregation/src/main/kotlin/net/kautler/dependency-updates-report-aggregation.gradle.kts @@ -75,6 +75,7 @@ if (gradle.parent == null && parent == null) { dependencies { gradle .includedBuilds + .filterNot { it.name == "conditional-refresh-versions" } .forEach { dependencyUpdatesResults(":${it.name}") } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 01ac77fa..fee45794 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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" @@ -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" } diff --git a/settings.gradle.kts b/settings.gradle.kts index bcb040c9..9d59c738 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -15,10 +15,12 @@ */ 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() @@ -26,11 +28,11 @@ pluginManagement { } 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) }