Skip to content

Commit

Permalink
Gradle 8.4
Browse files Browse the repository at this point in the history
Includes a bunch of other updates, and buildSrc was
replaced with convention-plugins in hope for quicker
Gradle sync and configuration time.
  • Loading branch information
LouisCAD committed Nov 15, 2023
1 parent 6960af6 commit 9ec529c
Show file tree
Hide file tree
Showing 55 changed files with 452 additions and 410 deletions.
8 changes: 4 additions & 4 deletions plugins/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
allprojects {
repositories {
mavenCentral()
}
plugins {
// Defined in convention-plugins (includedBuild).
// Added here to see updates in versions.properties.
id("com.gradle.plugin-publish") apply false
}
11 changes: 0 additions & 11 deletions plugins/buildSrc/build.gradle.kts

This file was deleted.

5 changes: 0 additions & 5 deletions plugins/buildSrc/src/main/kotlin/Property.kt

This file was deleted.

45 changes: 9 additions & 36 deletions plugins/buildSrcLibs/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion

plugins {
id("com.gradle.plugin-publish")
`java-gradle-plugin`
`maven-publish`
signing
id("gradle-plugin")
`kotlin-dsl`
}

Expand All @@ -15,30 +12,12 @@ gradlePlugin {
displayName = "Dependency notation generator & updates"
description = "Generates dependency notations constants in buildSrc and " +
"updates the versions with gradle refreshVersions"
tags = listOf("dependencies", "versions", "buildSrc", "kotlin", "kotlin-dsl")
implementationClass = "de.fayard.buildSrcLibs.BuildSrcLibsPlugin"
}
}
}

pluginBundle {
website = "https://jmfayard.github.io/refreshVersions"
vcsUrl = "https://github.com/jmfayard/refreshVersions"
tags = listOf("dependencies", "versions", "buildSrc", "kotlin", "kotlin-dsl")
}

signing {
useInMemoryPgpKeys(
propertyOrEnvOrNull("GPG_key_id"),
propertyOrEnvOrNull("GPG_private_key") ?: return@signing,
propertyOrEnv("GPG_private_password")
)
sign(publishing.publications)
}

publishing {
setupAllPublications(project)
}

dependencies {

api(project(":refreshVersions-core"))
Expand All @@ -60,20 +39,14 @@ dependencies {
}


tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.freeCompilerArgs += listOf(
"-Xopt-in=kotlin.RequiresOptIn",
"-Xopt-in=de.fayard.refreshVersions.core.internal.InternalRefreshVersionsApi"
)
kotlin {
jvmToolchain(8)
compilerOptions {
apiVersion = KotlinVersion.KOTLIN_1_8 // https://docs.gradle.org/current/userguide/compatibility.html#kotlin
freeCompilerArgs.add("-opt-in=de.fayard.refreshVersions.core.internal.InternalRefreshVersionsApi")
}
}

tasks.withType<Test>().configureEach {
useJUnitPlatform()
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
withSourcesJar()
}
9 changes: 9 additions & 0 deletions plugins/convention-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
plugins {
`kotlin-dsl`
}

fun plugin(id: String, version: String) = "$id:$id.gradle.plugin:$version"

dependencies {
implementation(plugin(id = "com.gradle.plugin-publish", version = "_"))
}
15 changes: 15 additions & 0 deletions plugins/convention-plugins/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
plugins {
id("de.fayard.refreshVersions") version "0.60.3"
}

dependencyResolutionManagement {
@Suppress("UnstableApiUsage")
repositories {
mavenCentral()
gradlePluginPortal()
}
}

refreshVersions {
versionsPropertiesFile = rootDir.parentFile.resolve("versions.properties")
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import org.gradle.api.Project

fun Project.propertyOrEnv(key: String): String {
internal fun Project.propertyOrEnv(key: String): String {
return findProperty(key) as String?
?: System.getenv(key)
?: error("Didn't find any value for the key \"$key\" in Project properties or environment variables.")
}

fun Project.propertyOrEnvOrNull(key: String): String? {
internal fun Project.propertyOrEnvOrNull(key: String): String? {
return findProperty(key) as String? ?: System.getenv(key)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
plugins {
id("com.gradle.plugin-publish")
signing
}

signing {
useInMemoryPgpKeys(
propertyOrEnvOrNull("GPG_key_id"),
propertyOrEnvOrNull("GPG_private_key") ?: return@signing,
propertyOrEnv("GPG_private_password")
)
sign(publishing.publications)
}

gradlePlugin {
website = Publishing.siteUrl
vcsUrl = Publishing.repoUrl
}

publishing {
setupAllPublications(project)
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,20 @@
@file:Suppress("PackageDirectoryMismatch")

import org.gradle.api.Project
import org.gradle.api.UnknownTaskException
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.tasks.TaskContainer
import org.gradle.api.tasks.TaskProvider
import org.gradle.jvm.tasks.Jar
import org.gradle.kotlin.dsl.named
import org.gradle.kotlin.dsl.register
import org.gradle.kotlin.dsl.assign
import org.gradle.kotlin.dsl.withType

object Publishing {
internal object Publishing {
const val gitUrl = "https://github.com/Splitties/refreshVersions.git"
const val siteUrl = "https://github.com/Splitties/refreshVersions"
const val siteUrl = "https://splitties.github.io/refreshVersions/"
const val repoUrl = "https://github.com/Splitties/refreshVersions"
const val libraryDesc = "Life is too short to Google for dependencies and versions."
}

fun PublishingExtension.setupAllPublications(project: Project) {
val mavenPublications = publications.withType<MavenPublication>()
mavenPublications.configureEach {
artifact(project.tasks.emptyJavadocJar())
setupPom()
}
internal fun PublishingExtension.setupAllPublications(project: Project) {
publications.withType<MavenPublication>().configureEach { setupPom() }
if (project.isSnapshot) {
sonatypeSnapshotsPublishing(project = project)
}
Expand All @@ -39,16 +31,6 @@ fun PublishingExtension.setupAllPublications(project: Project) {
}
}

fun TaskContainer.emptyJavadocJar(): TaskProvider<Jar> {
val taskName = "javadocJar"
return try {
named(name = taskName)
} catch (e: UnknownTaskException) {
register(name = taskName) { archiveClassifier by "javadoc" }
}
}


private fun Project.registerPublishingTask() {
require(project != rootProject)

Expand All @@ -71,32 +53,31 @@ private fun Project.registerPublishingTask() {
private val Project.isDevVersion get() = version.let { it is String && it.contains("-dev-") }
private val Project.isSnapshot get() = version.let { it is String && it.endsWith("-SNAPSHOT") }

@Suppress("UnstableApiUsage")
private fun MavenPublication.setupPom() = pom {
name.set("refreshVersions")
description.set(Publishing.libraryDesc)
url.set(Publishing.siteUrl)
name = "refreshVersions"
description = Publishing.libraryDesc
url = Publishing.siteUrl
licenses {
license {
name.set("MIT License")
url.set("https://opensource.org/licenses/MIT")
name = "MIT License"
url = "https://opensource.org/licenses/MIT"
}
}
developers {
developer {
id.set("jmfayard")
name.set("Jean-Michel Fayard")
email.set("[email protected]")
id = "jmfayard"
name = "Jean-Michel Fayard"
email = "[email protected]"
}
developer {
id.set("louiscad")
name.set("Louis CAD")
email.set("[email protected]")
id = "louiscad"
name = "Louis CAD"
email = "[email protected]"
}
}
scm {
connection.set(Publishing.gitUrl)
developerConnection.set(Publishing.gitUrl)
url.set(Publishing.siteUrl)
connection = Publishing.gitUrl
developerConnection = Publishing.gitUrl
url = Publishing.repoUrl
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.gradle.api.publish.PublishingExtension
import java.net.URI


fun PublishingExtension.mavenCentralStagingPublishing(
internal fun PublishingExtension.mavenCentralStagingPublishing(
project: Project,
sonatypeUsername: String? = project.propertyOrEnvOrNull("sonatype_username"),
sonatypePassword: String? = project.propertyOrEnvOrNull("sonatype_password"),
Expand All @@ -26,7 +26,7 @@ fun PublishingExtension.mavenCentralStagingPublishing(
}
}

fun PublishingExtension.sonatypeSnapshotsPublishing(
internal fun PublishingExtension.sonatypeSnapshotsPublishing(
project: Project,
sonatypeUsername: String? = project.propertyOrEnvOrNull("sonatype_username"),
sonatypePassword: String? = project.propertyOrEnvOrNull("sonatype_password")
Expand Down
77 changes: 20 additions & 57 deletions plugins/core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.splitties.gradle.VersionFileWriter
import org.splitties.gradle.putVersionInCode

plugins {
id("com.gradle.plugin-publish")
`java-gradle-plugin`
id("gradle-plugin")
`java-test-fixtures`
`maven-publish`
signing
`kotlin-dsl`
idea
}

gradlePlugin {
Expand All @@ -16,30 +14,12 @@ gradlePlugin {
id = "de.fayard.refreshVersions-core"
displayName = "./gradlew refreshVersions"
description = "Painless dependencies management"
tags = listOf("dependencies", "versions", "buildSrc", "kotlin", "kotlin-dsl")
implementationClass = "de.fayard.refreshVersions.core.RefreshVersionsCorePlugin"
}
}
}

pluginBundle {
website = "https://jmfayard.github.io/refreshVersions"
vcsUrl = "https://github.com/jmfayard/refreshVersions"
tags = listOf("dependencies", "versions", "buildSrc", "kotlin", "kotlin-dsl")
}

signing {
useInMemoryPgpKeys(
propertyOrEnvOrNull("GPG_key_id"),
propertyOrEnvOrNull("GPG_private_key") ?: return@signing,
propertyOrEnv("GPG_private_password")
)
sign(publishing.publications)
}

publishing {
setupAllPublications(project)
}

dependencies {
compileOnly(gradleKotlinDsl())
implementation(KotlinX.coroutines.core)
Expand Down Expand Up @@ -75,44 +55,27 @@ kotlin {
javaComponent.withVariantsFromConfiguration(configurations["testFixturesRuntimeElements"]) { skip() }
}

val genResourcesDir = buildDir.resolve("generated/refreshVersions/resources")

sourceSets.main {
resources.srcDir(genResourcesDir.path)
}

idea {
module.generatedSourceDirs.add(genResourcesDir)
kotlin.srcDir("build/gen")
}

val copyVersionFile by tasks.registering {
val versionFile = rootProject.file("version.txt")
val versionFileCopy = genResourcesDir.resolve("version.txt")
inputs.file(versionFile)
outputs.file(versionFileCopy)
doFirst { versionFile.copyTo(versionFileCopy, overwrite = true) }
}
tasks.processResources {
dependsOn(copyVersionFile)
}

tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.apiVersion = "1.5"
kotlinOptions.freeCompilerArgs += listOf(
"-Xmulti-platform", // Allow using expect and actual keywords.
"-opt-in=de.fayard.refreshVersions.core.internal.InternalRefreshVersionsApi"
putVersionInCode(
outputDirectory = layout.dir(provider { file("build/gen") }),
writer = VersionFileWriter.Kotlin(
fileName = "PluginVersion.kt",
`package` = "de.fayard.refreshVersions",
propertyName = "thisProjectVersion"
)
)

kotlin {
jvmToolchain(8)
compilerOptions {
apiVersion = KotlinVersion.KOTLIN_1_8 // https://docs.gradle.org/current/userguide/compatibility.html#kotlin
freeCompilerArgs.add("-opt-in=de.fayard.refreshVersions.core.internal.InternalRefreshVersionsApi")
}
}

tasks.withType<Test>().configureEach {
useJUnitPlatform()
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
withSourcesJar()
}

tasks.named("sourcesJar").configure { dependsOn(copyVersionFile) }
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fun Configuration.countDependenciesWithHardcodedVersions(
@InternalRefreshVersionsApi
fun Project.countDependenciesWithHardcodedVersions(versionsMap: Map<String, String>): Int {
val versionKeyReader = RefreshVersionsConfigHolder.versionKeyReader
return (buildscript.configurations + configurations).sumBy { configuration ->
return (buildscript.configurations + configurations).sumOf { configuration ->
if (configuration.shouldBeIgnored()) 0 else {
configuration.countDependenciesWithHardcodedVersions(versionsMap, versionKeyReader)
}
Expand Down
Loading

0 comments on commit 9ec529c

Please sign in to comment.