diff options
| author | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-11-13 12:28:04 +0000 |
|---|---|---|
| committer | Fabian Mastenbroek <mail.fabianm@gmail.com> | 2022-11-13 17:42:01 +0000 |
| commit | 83ad9c927952474f1adeb03bd67331288ed6d6d9 (patch) | |
| tree | b1a2626375e07e43d8c412c9adcc78f0f4130f5e /buildSrc/src/main/kotlin/Libs.kt | |
| parent | fb2672afb2d8236d5291cd028196c99d8e4d47f1 (diff) | |
build: Make use of Gradle's Java Toolchains feature
This change updates the build configuration for Gradle to make use of
its Java Toolchains feature which enables running/testing multiple Java
versions at the same time. This feature can also provision a Java
installation if it is not available on the user's system.
Diffstat (limited to 'buildSrc/src/main/kotlin/Libs.kt')
| -rw-r--r-- | buildSrc/src/main/kotlin/Libs.kt | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/buildSrc/src/main/kotlin/Libs.kt b/buildSrc/src/main/kotlin/Libs.kt index 97dc36ca..09432b06 100644 --- a/buildSrc/src/main/kotlin/Libs.kt +++ b/buildSrc/src/main/kotlin/Libs.kt @@ -24,32 +24,27 @@ import org.gradle.api.JavaVersion import org.gradle.api.Project +import org.gradle.api.artifacts.VersionCatalog import org.gradle.api.artifacts.VersionCatalogsExtension import org.gradle.kotlin.dsl.getByType /** - * This class makes the version catalog accessible for the build scripts until Gradle adds support for it. - * - * See https://github.com/gradle/gradle/issues/15383 + * Obtain the default [VersionCatalog] of the project. */ -public class Libs(project: Project) { - /** - * The version catalog of the project. - */ - private val versionCatalog = project.extensions.getByType(VersionCatalogsExtension::class).named("libs") +public val Project.defaultVersionCatalog: VersionCatalog + get() = project.extensions.getByType(VersionCatalogsExtension::class).named("libs") - /** - * Obtain the version for the specified [dependency][name]. - */ - operator fun get(name: String): String { - val dep = versionCatalog.findLibrary(name).get().get() - return "${dep.module.group}:${dep.module.name}:${dep.versionConstraint.displayName}" - } +/** + * Obtain the dependency string for the specified [name]. + */ +public operator fun VersionCatalog.get(name: String): String { + val dep = findLibrary(name).get().get() + return "${dep.module.group}:${dep.module.name}:${dep.versionConstraint.displayName}" +} - companion object { - /** - * The JVM version to target. - */ - val jvmTarget = JavaVersion.VERSION_17 - } +/** + * Obtain the string representation of the version with the given [name]. + */ +public fun VersionCatalog.getVersion(name: String): String { + return findVersion(name).get().displayName } |
