Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build config: Gradle Version Catalog + type-safe project dependencies #2884

Merged
merged 13 commits into from
Mar 17, 2023
Merged
24 changes: 6 additions & 18 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import java.util.*

plugins {
`kotlin-dsl`
}
Expand All @@ -10,22 +8,12 @@ kotlin {
}
}

// TODO define versions in Gradle Version Catalog https://github.com/Kotlin/dokka/pull/2884
val properties = file("../gradle.properties").inputStream().use {
Properties().apply { load(it) }
}

val kotlinVersion = properties["kotlin_version"]

dependencies {
// Import Gradle Plugins that will be used in the buildSrc pre-compiled script plugins, and any `build.gradle.kts`
// files in the project.
// Use their Maven coordinates (plus versions), not Gradle plugin IDs!
// This should be the only place that Gradle plugin versions are defined, so they are aligned across all build scripts
implementation(libs.gradlePlugin.dokka)
implementation(libs.gradlePlugin.kotlin)
implementation(libs.gradlePlugin.shadow)

implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
implementation("gradle.plugin.com.github.johnrengelman:shadow:7.1.2")
implementation("org.jetbrains.kotlinx:binary-compatibility-validator:0.12.1")
implementation("io.github.gradle-nexus:publish-plugin:1.1.0")
implementation("org.jetbrains.dokka:dokka-gradle-plugin:1.8.10")
// workaround for accessing version-catalog in convention plugins
// https://github.com/gradle/gradle/issues/15383#issuecomment-779893192
implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
}
6 changes: 6 additions & 0 deletions build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,10 @@ dependencyResolutionManagement {
google()
gradlePluginPortal()
}

versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ plugins {
base
}

abstract class SetupMavenProperties {
abstract class MavenCliSetupExtension {
abstract val mavenVersion: Property<String>
abstract val mavenPluginToolsVersion: Property<String>
abstract val mavenBuildDir: DirectoryProperty
Expand All @@ -34,10 +34,10 @@ abstract class SetupMavenProperties {
abstract val mvn: RegularFileProperty
}

val setupMavenProperties =
extensions.create("setupMavenProperties", SetupMavenProperties::class).apply {
mavenVersion.convention(providers.gradleProperty("mavenVersion"))
mavenPluginToolsVersion.convention(providers.gradleProperty("mavenPluginToolsVersion"))
val mavenCliSetupExtension =
extensions.create("mavenCliSetup", MavenCliSetupExtension::class).apply {
mavenVersion.convention(libs.versions.apache.maven)
mavenPluginToolsVersion.convention(libs.versions.apache.mavenPluginTools)

mavenBuildDir.convention(layout.buildDirectory.dir("maven"))
mavenInstallDir.convention(layout.buildDirectory.dir("apache-maven"))
Expand All @@ -64,7 +64,7 @@ val mavenBinary by configurations.registering {
isVisible = false

defaultDependencies {
addLater(setupMavenProperties.mavenVersion.map { mavenVersion ->
addLater(mavenCliSetupExtension.mavenVersion.map { mavenVersion ->
project.dependencies.create(
group = "org.apache.maven",
name = "apache-maven",
Expand All @@ -77,8 +77,8 @@ val mavenBinary by configurations.registering {
}

tasks.clean {
delete(setupMavenProperties.mavenBuildDir)
delete(setupMavenProperties.mavenInstallDir)
delete(mavenCliSetupExtension.mavenBuildDir)
delete(mavenCliSetupExtension.mavenInstallDir)
}

val installMavenBinary by tasks.registering(Sync::class) {
Expand All @@ -99,5 +99,5 @@ val installMavenBinary by tasks.registering(Sync::class) {
}
includeEmptyDirs = false
}
into(setupMavenProperties.mavenInstallDir)
into(mavenCliSetupExtension.mavenInstallDir)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
@file:Suppress("PackageDirectoryMismatch")

package org.gradle.kotlin.dsl // for convenience use a default package for gradle.kts scripts

import org.gradle.api.Project
import org.gradle.accessors.dm.LibrariesForLibs

/*
* Utility functions for accessing Gradle extensions that are created by convention plugins.
*
* (Gradle can't generate the nice DSL accessors for the project that defines them)
*
* These functions are not needed outside the convention plugins project and should be marked as
* `internal`
*/


/**
* workaround for accessing version-catalog in convention plugins
*
* See https://github.com/gradle/gradle/issues/15383#issuecomment-779893192
*/
internal val Project.libs : LibrariesForLibs
get() = extensions.getByType()
16 changes: 8 additions & 8 deletions build-logic/src/main/kotlin/org/jetbrains/publication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ package org.jetbrains

import com.github.jengelman.gradle.plugins.shadow.ShadowExtension
import org.gradle.api.Project
import org.gradle.api.plugins.JavaBasePlugin
import org.gradle.api.publish.PublishingExtension
import org.gradle.api.publish.maven.MavenPublication
import org.gradle.api.publish.maven.tasks.PublishToMavenRepository
import org.gradle.api.tasks.TaskContainer
import org.gradle.api.tasks.TaskProvider
import org.gradle.api.tasks.bundling.Jar
import org.gradle.kotlin.dsl.*
import org.gradle.plugins.signing.SigningExtension
import org.jetbrains.DokkaPublicationChannel.*
Expand All @@ -24,7 +20,10 @@ class DokkaPublicationBuilder {
}


fun Project.registerDokkaArtifactPublication(publicationName: String, configure: DokkaPublicationBuilder.() -> Unit) {
fun Project.registerDokkaArtifactPublication(
publicationName: String,
configure: DokkaPublicationBuilder.() -> Unit
) {
configure<PublishingExtension> {
publications {
register<MavenPublication>(publicationName) {
Expand Down Expand Up @@ -143,9 +142,10 @@ private fun Project.signPublicationsIfKeyPresent(vararg publications: String) {
useInMemoryPgpKeys(signingKey, signingKeyPassphrase)
}
publications.forEach { publicationName ->
extensions.findByType(PublishingExtension::class)!!.publications.findByName(publicationName)?.let {
sign(it)
}
extensions.getByType<PublishingExtension>()
.publications
.findByName(publicationName)
?.let { sign(it) }
}
aSemy marked this conversation as resolved.
Show resolved Hide resolved
}
}
Expand Down
12 changes: 7 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import org.jetbrains.ValidatePublications
import org.jetbrains.publicationChannels

@Suppress("DSL_SCOPE_VIOLATION") // fixed in Gradle 8.1 https://github.com/gradle/gradle/pull/23639
plugins {
id("org.jetbrains.conventions.base") apply false
id("org.jetbrains.dokka") version "1.8.10"
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
id("com.gradle.plugin-publish") version "0.20.0"
id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.12.1"
id("org.jetbrains.conventions.base")
id("org.jetbrains.conventions.dokka")

alias(libs.plugins.kotlinx.binaryCompatibilityValidator)
alias(libs.plugins.gradle.pluginPublish)
alias(libs.plugins.nexusPublish)
}

val dokka_version: String by project
Expand Down
18 changes: 7 additions & 11 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,22 @@ plugins {
}

dependencies {
api("org.jetbrains:markdown:0.3.1")
api(libs.jetbrainsMarkdown)
implementation(kotlin("reflect"))

val jsoup_version: String by project
implementation("org.jsoup:jsoup:$jsoup_version")
implementation(libs.jsoup)

val jackson_version: String by project
implementation("com.fasterxml.jackson.module:jackson-module-kotlin:$jackson_version")
implementation("com.fasterxml.jackson.dataformat:jackson-dataformat-xml:$jackson_version")
val jackson_databind_version: String by project
implementation(libs.jackson.kotlin)
implementation(libs.jackson.xml)
constraints {
implementation("com.fasterxml.jackson.core:jackson-databind:$jackson_databind_version") {
implementation(libs.jackson.databind) {
because("CVE-2022-42003")
}
}

val coroutines_version: String by project
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version")
implementation(libs.kotlinx.coroutines.core)

testImplementation(project(":core:test-api"))
testImplementation(projects.core.testApi)
testImplementation(kotlin("test-junit"))
}

Expand Down
6 changes: 3 additions & 3 deletions core/content-matcher-test-utils/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ plugins {
}

dependencies {
implementation(project(":core:test-api"))
implementation(kotlin("stdlib-jdk8"))
aSemy marked this conversation as resolved.
Show resolved Hide resolved
implementation(projects.core.testApi)

implementation(kotlin("reflect"))
implementation("com.willowtreeapps.assertk:assertk-jvm:0.25")
implementation(libs.assertk)
}
5 changes: 2 additions & 3 deletions core/test-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ plugins {
}

dependencies {
api(project(":core"))
implementation(project(":kotlin-analysis"))
api(projects.core)
implementation(projects.kotlinAnalysis)
implementation("junit:junit:4.13.2") // TODO: remove dependency to junit
implementation(kotlin("stdlib"))
implementation(kotlin("reflect"))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,5 @@ tasks.dokkaHtml {
}

dependencies {
implementation(kotlin("stdlib"))
aSemy marked this conversation as resolved.
Show resolved Hide resolved
testImplementation(kotlin("test-junit"))
}
1 change: 0 additions & 1 deletion examples/gradle/dokka-gradle-example/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ repositories {
}

dependencies {
implementation(kotlin("stdlib"))
testImplementation(kotlin("test-junit"))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ repositories {
}

dependencies {
implementation(kotlin("stdlib"))
testImplementation(kotlin("test-junit"))

// Will apply the plugin to all Dokka tasks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ repositories {
}

dependencies {
implementation(kotlin("stdlib"))
testImplementation(kotlin("test-junit"))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,3 @@ subprojects {
tasks.dokkaHtmlMultiModule {
moduleName.set("Dokka MultiModule Example")
}

dependencies {
implementation(kotlin("stdlib"))
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ plugins {
id("org.jetbrains.dokka")
}

dependencies {
implementation(kotlin("stdlib"))
}

// configuration specific to this subproject.
// notice the use of Partial task
tasks.withType<DokkaTaskPartial>().configureEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ plugins {
id("org.jetbrains.dokka")
}

dependencies {
implementation(kotlin("stdlib"))
}

// configuration specific to this subproject.
// notice the use of Partial task
tasks.withType<DokkaTaskPartial>().configureEach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ buildscript {
}
}

dependencies {
implementation(kotlin("stdlib"))
}

val currentVersion = "1.0"
val previousVersionsDirectory = project.rootProject.projectDir.resolve("previousDocVersions").invariantSeparatorsPath

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
dependencies {
implementation(kotlin("stdlib"))
}
// intentionally empty - build config is set in the root build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
dependencies {
implementation(kotlin("stdlib"))
}
// intentionally empty - build config is set in the root build.gradle.kts
2 changes: 1 addition & 1 deletion examples/plugin/hide-internal-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ repositories {

val dokkaVersion: String by project
dependencies {
implementation(kotlin("stdlib"))

compileOnly("org.jetbrains.dokka:dokka-core:$dokkaVersion")
implementation("org.jetbrains.dokka:dokka-base:$dokkaVersion")

Expand Down
15 changes: 0 additions & 15 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
# Project Settings
dokka_version=1.8.20-SNAPSHOT
dokka_integration_test_parallelism=2
# Versions
kotlin_version=1.8.10
coroutines_version=1.6.3
kotlinx_html_version=0.7.5
kotlin_plugin_version=213-1.8.10-release-430-IJ6777.52
jsoup_version=1.15.3
idea_version=213.6777.52
language_version=1.4
# jackson 2.13.X does not support kotlin language version 1.4, check before updating
jackson_version=2.12.7
# fixes CVE-2022-42003
jackson_databind_version=2.12.7.1
freemarker_version=2.3.31
# Dokka Maven Plugin versions
mavenVersion=3.5.0
mavenPluginToolsVersion=3.5.2
# Code style
kotlin.code.style=official
# Gradle settings
Expand Down
Loading