Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ ij_kotlin_line_break_after_multiline_when_entry = false
ij_kotlin_name_count_to_use_star_import = 2147483647
ij_kotlin_name_count_to_use_star_import_for_members = 2147483647
ij_kotlin_packages_to_use_import_on_demand = unset
ktlint_code_style = intellij_idea
ktlint_standard_function-expression-body = disabled
ktlint_standard_mixed-condition-operators = disabled

[*.md]
trim_trailing_whitespace = false
105 changes: 45 additions & 60 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,16 @@ plugins {
}

version = providers.gradleProperty("VERSION_NAME").get()

group = providers.gradleProperty("GROUP").get()

description = providers.gradleProperty("POM_DESCRIPTION").get()

dokka {
dokkaPublications.html {
outputDirectory = rootDir.resolve("docs/api")
}
}
dokka { dokkaPublications.html { outputDirectory = rootDir.resolve("docs/api") } }

kotlin {
explicitApi()
@OptIn(ExperimentalAbiValidation::class)
abiValidation {
enabled = true
}
@OptIn(ExperimentalAbiValidation::class) abiValidation { enabled = true }
compilerOptions {
allWarningsAsErrors = true
// https://docs.gradle.org/current/userguide/compatibility.html#kotlin
Expand All @@ -56,18 +51,15 @@ lint {
}

spotless {
kotlin {
ktlint(libs.ktlint.get().version)
}
kotlinGradle {
ktlint(libs.ktlint.get().version)
}
kotlin { ktfmt(libs.ktfmt.get().version).googleStyle() }
kotlinGradle { ktfmt(libs.ktfmt.get().version).googleStyle() }
}

val testPluginClasspath by configurations.registering {
isCanBeResolved = true
description = "Plugins used in integration tests could be resolved in classpath."
}
val testPluginClasspath by
configurations.registering {
isCanBeResolved = true
description = "Plugins used in integration tests could be resolved in classpath."
}

val testKit by sourceSets.creating
val testKitImplementation by configurations.getting
Expand All @@ -77,18 +69,18 @@ configurations.configureEach {
API_ELEMENTS_CONFIGURATION_NAME,
RUNTIME_ELEMENTS_CONFIGURATION_NAME,
JAVADOC_ELEMENTS_CONFIGURATION_NAME,
SOURCES_ELEMENTS_CONFIGURATION_NAME,
-> outgoing {
// Main/current capability.
capability("com.gradleup.shadow:shadow-gradle-plugin:$version")

// Historical capabilities.
capability("io.github.goooler.shadow:shadow-gradle-plugin:$version")
capability("com.github.johnrengelman:shadow:$version")
capability("gradle.plugin.com.github.jengelman.gradle.plugins:shadow:$version")
capability("gradle.plugin.com.github.johnrengelman:shadow:$version")
capability("com.github.jengelman.gradle.plugins:shadow:$version")
}
SOURCES_ELEMENTS_CONFIGURATION_NAME ->
outgoing {
// Main/current capability.
capability("com.gradleup.shadow:shadow-gradle-plugin:$version")

// Historical capabilities.
capability("io.github.goooler.shadow:shadow-gradle-plugin:$version")
capability("com.github.johnrengelman:shadow:$version")
capability("gradle.plugin.com.github.jengelman.gradle.plugins:shadow:$version")
capability("gradle.plugin.com.github.johnrengelman:shadow:$version")
capability("com.github.jengelman.gradle.plugins:shadow:$version")
}
}
}

Expand All @@ -108,11 +100,12 @@ configurations.named(API_ELEMENTS_CONFIGURATION_NAME) {
)
}

val testGradleVersion: String = providers.gradleProperty("testGradleVersion").orNull.let {
val value = if (it == null || it == "current") GradleVersion.current().version else it
logger.lifecycle("Using Gradle $value in tests")
value
}
val testGradleVersion: String =
providers.gradleProperty("testGradleVersion").orNull.let {
val value = if (it == null || it == "current") GradleVersion.current().version else it
logger.lifecycle("Using Gradle $value in tests")
value
}

dependencies {
compileOnly(libs.develocity)
Expand Down Expand Up @@ -141,17 +134,15 @@ dependencies {
}

testing.suites {
getByName<JvmTestSuite>("test") {
dependencies {
implementation(libs.xmlunit)
}
}
getByName<JvmTestSuite>("test") { dependencies { implementation(libs.xmlunit) } }
register<JvmTestSuite>("documentTest") {
targets.configureEach {
testTask {
val docsDir = file("docs").also {
if (!it.exists() || !it.isDirectory) error("Docs dir $it does not exist or is not a directory.")
}
val docsDir =
file("docs").also {
if (!it.exists() || !it.isDirectory)
error("Docs dir $it does not exist or is not a directory.")
}
// Add docs as an input directory to trigger ManualCodeSnippetTests re-run on changes.
inputs.dir(docsDir)
systemProperty("DOCS_DIR", docsDir.absolutePath)
Expand Down Expand Up @@ -215,10 +206,7 @@ gradlePlugin {
}
}

testSourceSets(
sourceSets["functionalTest"],
sourceSets["documentTest"],
)
testSourceSets(sourceSets["functionalTest"], sourceSets["documentTest"])
}

// This part should be placed after testing.suites to ensure the test sourceSets are created.
Expand All @@ -234,11 +222,7 @@ tasks.withType<JavaCompile>().configureEach {
options.release = libs.versions.jdkRelease.get().toInt()
}

tasks.pluginUnderTestMetadata {
pluginClasspath.from(
testPluginClasspath,
)
}
tasks.pluginUnderTestMetadata { pluginClasspath.from(testPluginClasspath) }

tasks.validatePlugins {
// TODO: https://github.com/gradle/gradle/issues/22600
Expand All @@ -254,11 +238,12 @@ tasks.check {
}

tasks.clean {
delete += listOf(
projectDir.resolve(".gradle"),
projectDir.resolve(".kotlin"),
dokka.dokkaPublications.html.map { it.outputDirectory },
// Generated by MkDocs.
rootDir.resolve("site"),
)
delete +=
listOf(
projectDir.resolve(".gradle"),
projectDir.resolve(".kotlin"),
dokka.dokkaPublications.html.map { it.outputDirectory },
// Generated by MkDocs.
rootDir.resolve("site"),
)
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pluginPublish = { module = "com.gradle.publish:plugin-publish-plugin", version.r

androidx-gradlePluginLints = "androidx.lint:lint-gradle:1.0.0-alpha05"
# Dummy to get renovate updates, the version is used in rootProject build.gradle with spotless.
ktlint = "com.pinterest.ktlint:ktlint-cli:1.8.0"
ktfmt = "com.facebook:ktfmt:0.59"

junit-bom = "org.junit:junit-bom:6.0.1"
assertk = "com.willowtreeapps.assertk:assertk:0.28.1"
Expand Down
4 changes: 1 addition & 3 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@ pluginManagement {
}
}

plugins {
id("com.gradle.develocity") version "4.3"
}
plugins { id("com.gradle.develocity") version "4.3" }

develocity {
buildScan {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,9 @@ class DocCodeSnippetTest {

@TestFactory
fun provideDynamicTests(@TempDir root: Path): List<DynamicTest> {
val langExecutables = DslLang.entries.map { executor ->
CodeSnippetExtractor.extract(executor)
}
val langExecutables = DslLang.entries.map { executor -> CodeSnippetExtractor.extract(executor) }

check(langExecutables.sumOf { it.size } > 0) {
"No code snippets found."
}
check(langExecutables.sumOf { it.size } > 0) { "No code snippets found." }
check(langExecutables.size == DslLang.entries.size) {
"We must provide build script snippets for all languages."
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,21 @@ object CodeSnippetExtractor {
private val docRoot = Path(System.getProperty("DOCS_DIR"))

@OptIn(ExperimentalPathApi::class)
private val markdownPaths = docRoot.walk()
.filter { it.name.endsWith(".md", ignoreCase = true) }
.toList()
private val markdownPaths =
docRoot.walk().filter { it.name.endsWith(".md", ignoreCase = true) }.toList()

fun extract(lang: DslLang): List<SnippetExecutable> {
return markdownPaths.flatMap { path ->
createExecutables(lang, path)
}
return markdownPaths.flatMap { path -> createExecutables(lang, path) }
}

private fun createExecutables(
lang: DslLang,
markdownPath: Path,
): List<SnippetExecutable> {
private fun createExecutables(lang: DslLang, markdownPath: Path): List<SnippetExecutable> {
val relativeDocPath = markdownPath.relativeTo(docRoot).toString()
return createSnippets(markdownPath.readText(), lang).map { (lineNumber, snippet) ->
SnippetExecutable.create(
lang,
snippet,
"$relativeDocPath:$lineNumber",
) {
RuntimeException("The error line in the doc is near ${markdownPath.toUri()}:$lineNumber", it)
SnippetExecutable.create(lang, snippet, "$relativeDocPath:$lineNumber") {
RuntimeException(
"The error line in the doc is near ${markdownPath.toUri()}:$lineNumber",
it,
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package com.github.jengelman.gradle.plugins.shadow.snippet

enum class DslLang {
Kotlin,
Groovy,
;
Groovy;

override fun toString(): String = name.lowercase()
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ class GroovyBuildExecutable(

override val buildScriptName: String = "build.gradle"

override val pluginsBlock: String = """
override val pluginsBlock: String =
"""
plugins {
id 'java'
id 'com.gradleup.shadow'
}
""".trimIndent()
"""
.trimIndent()

override val assembleDependsOn: String = """
override val assembleDependsOn: String =
"""
tasks.named('assemble') {
dependsOn tasks.withType(Jar) // ShadowJar is a subtype of Jar.
}
""".trimIndent()
"""
.trimIndent()
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ class KotlinBuildExecutable(

override val buildScriptName: String = "build.gradle.kts"

override val pluginsBlock: String = """
override val pluginsBlock: String =
"""
plugins {
java
id("com.gradleup.shadow")
}
""".trimIndent()
"""
.trimIndent()

override val assembleDependsOn: String = """
override val assembleDependsOn: String =
"""
tasks.named("assemble") {
dependsOn(tasks.withType(Jar::class.java)) // ShadowJar is a subtype of Jar.
}
""".trimIndent()
"""
.trimIndent()
}
Loading