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
61 changes: 33 additions & 28 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
import com.gradle.publish.*
import java.io.*
import kotlinx.validation.build.*
import kotlinx.validation.build.mavenCentralMetadata
import kotlinx.validation.build.mavenRepositoryPublishing
import kotlinx.validation.build.signPublicationIfKeyPresent
import org.gradle.api.attributes.TestSuiteType.FUNCTIONAL_TEST
import org.gradle.api.internal.tasks.testing.*
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.tasks.*


plugins {
kotlin("jvm")
`java-gradle-plugin`
id("com.gradle.plugin-publish")
kotlinx.validation.build.conventions.`java-base`
signing
`maven-publish`
`jvm-test-suite`
}

group = "org.jetbrains.kotlinx"
providers.gradleProperty("DeployVersion").orNull?.let {
version = it
}

sourceSets {
test {
java.srcDir("src/test/kotlin")
Expand Down Expand Up @@ -48,17 +51,11 @@ val createClasspathManifest = tasks.register("createClasspathManifest") {
.withPropertyName("outputDir")

doLast {
file(outputDir.resolve("plugin-classpath.txt")).writeText(
testPluginRuntimeConfiguration.joinToString(
"\n"
)
)
file(outputDir.resolve("plugin-classpath.txt"))
.writeText(testPluginRuntimeConfiguration.joinToString("\n"))
}
}

val kotlinVersion: String by project
val androidGradlePluginVersion: String = "7.2.2"

configurations.implementation {
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib")
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk7")
Expand All @@ -67,17 +64,19 @@ configurations.implementation {

dependencies {
implementation(gradleApi())
implementation("org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.6.0")
implementation("org.ow2.asm:asm:9.2")
implementation("org.ow2.asm:asm-tree:9.2")
implementation("com.googlecode.java-diff-utils:diffutils:1.3.0")
compileOnly("org.jetbrains.kotlin.multiplatform:org.jetbrains.kotlin.multiplatform.gradle.plugin:1.8.10")
//compileOnly("com.android.tools.build:gradle:${androidGradlePluginVersion}")
implementation(libs.kotlinx.metadata)
implementation(libs.ow2.asm)
implementation(libs.ow2.asmTree)
implementation(libs.javaDiffUtils)
compileOnly(libs.gradlePlugin.kotlin)

// Android support is not yet implemented https://github.com/Kotlin/binary-compatibility-validator/issues/94
//compileOnly(libs.gradlePlugin.android)

// The test needs the full kotlin multiplatform plugin loaded as it has no visibility of previously loaded plugins,
// unlike the regular way gradle loads plugins.
testPluginRuntimeConfiguration("org.jetbrains.kotlin.multiplatform:org.jetbrains.kotlin.multiplatform.gradle.plugin:$kotlinVersion")
testPluginRuntimeConfiguration("com.android.tools.build:gradle:${androidGradlePluginVersion}")
testPluginRuntimeConfiguration(libs.gradlePlugin.android)
testPluginRuntimeConfiguration(libs.gradlePlugin.kotlin)
}

tasks.compileKotlin {
Expand Down Expand Up @@ -115,11 +114,17 @@ tasks.withType<Test>().configureEach {
jvmArgs("-ea")
}

properties["DeployVersion"]?.let { version = it }

publishing {
mavenRepositoryPublishing(project)
mavenCentralMetadata()
publications {
create<MavenPublication>("maven") {
from(components["java"])
artifact(tasks.javadocJar)
artifact(tasks.sourcesJar)
}

mavenRepositoryPublishing(project)
mavenCentralMetadata()
}

publications.withType<MavenPublication>().all {
signPublicationIfKeyPresent(this)
Expand Down Expand Up @@ -155,8 +160,8 @@ testing {
useJUnit()
dependencies {
implementation(project())
implementation("org.assertj:assertj-core:3.18.1")
implementation(project.dependencies.kotlin("test-junit").toString())
implementation(libs.assertJ.core)
implementation(libs.kotlin.test)
}
}

Expand Down
28 changes: 2 additions & 26 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,11 @@ plugins {
`kotlin-dsl`
}

val props = Properties().apply {
project.file("../gradle.properties").inputStream().use { load(it) }
}

val kotlinVersion: String = props.getProperty("kotlinVersion")

dependencies {
implementation(kotlin("gradle-plugin-api", kotlinVersion))
}

sourceSets {
configureEach {
when (name) {
SourceSet.MAIN_SOURCE_SET_NAME -> {
kotlin.setSrcDirs(listOf("src"))
resources.setSrcDirs(listOf("resources"))
}

else -> {
kotlin.setSrcDirs(emptyList<String>())
resources.setSrcDirs(emptyList<String>())
}
}
java.setSrcDirs(emptyList<String>())
groovy.setSrcDirs(emptyList<String>())
}
implementation(libs.gradlePlugin.kotlin)
implementation(libs.gradlePlugin.pluginPublishing)
}


tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
allWarningsAsErrors = true
Expand Down
6 changes: 6 additions & 0 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ dependencyResolutionManagement {
mavenCentral()
gradlePluginPortal()
}

versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2020 JetBrains s.r.o.
* Copyright 2016-2023 JetBrains s.r.o.
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
*/
package kotlinx.validation.build
Expand Down
File renamed without changes.
32 changes: 32 additions & 0 deletions buildSrc/src/main/kotlin/conventions/base.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2016-2023 JetBrains s.r.o.
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
*/
package kotlinx.validation.build.conventions
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it correct that these conventions will be published along with BCV and will be applicable to target's projects manually?

Could you please add an integration test for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These convention plugins are only available in BCV's own build scripts for building BCV, and they are not published anywhere. They won't be visible for users at all.

These are pre-compiled script plugins which Gradle will auto-magically compile into a plugin with a plugin ID (based on the file path). The plugins are compiled into a JAR, buildSrc/build/libs/buildSrc.jar, which (because they're in buildSrc) is automatically added to the buildscript classpath.


import java.time.Duration

plugins {
base
}

// common config for all projects

if (project != rootProject) {
project.version = rootProject.version
project.group = rootProject.group
}

tasks.withType<AbstractArchiveTask>().configureEach {
// https://docs.gradle.org/current/userguide/working_with_files.html#sec:reproducible_archives
isPreserveFileTimestamps = false
isReproducibleFileOrder = true
}

tasks.withType<AbstractTestTask>().configureEach {
timeout.set(Duration.ofMinutes(60))
}

tasks.withType<AbstractCopyTask>().configureEach {
includeEmptyDirs = false
}
22 changes: 22 additions & 0 deletions buildSrc/src/main/kotlin/conventions/java-base.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright 2016-2023 JetBrains s.r.o.
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
*/
package kotlinx.validation.build.conventions

plugins {
id("kotlinx.validation.build.conventions.base")
`java`
}

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(8))
}
withSourcesJar()
withJavadocJar()
}

tasks.withType<Test>().configureEach {
useJUnit()
}
4 changes: 0 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
version=0.13.1-SNAPSHOT
group=org.jetbrains.kotlinx

kotlinVersion=1.8.10
pluginPublishVersion=1.1.0

kotlin.stdlib.default.dependency=false
42 changes: 42 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[versions]

kotlin = "1.8.10"

javaDiffUtils = "1.3.0"
junit = "5.9.2"
kotest = "5.5.5"
kotlinx-bcv = "0.13.0"
ow2Asm = "9.2"

gradlePluginPublishPlugin = "1.1.0"
androidGradlePlugin = "7.2.2"

[libraries]

## region Application libraries
kotlinx-metadata = { module = "org.jetbrains.kotlinx:kotlinx-metadata-jvm", version = "0.6.0" }

javaDiffUtils = { module = "com.googlecode.java-diff-utils:diffutils", version.ref = "javaDiffUtils" }
# update Java Diff Utils versions https://github.com/Kotlin/binary-compatibility-validator/issues/130
#javaDiffUtils = { module = "io.github.java-diff-utils:java-diff-utils", version = "4.12" }

ow2-asm = { module = "org.ow2.asm:asm", version.ref = "ow2Asm" }
ow2-asmTree = { module = "org.ow2.asm:asm-tree", version.ref = "ow2Asm" }
## endregion


## region Test libraries
junit-bom = { module = "org.junit:junit-bom", version.ref = "junit" }
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" }

assertJ-core = { module = "org.assertj:assertj-core", version = "3.18.1" }

kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" }
## endregion


## region Gradle Plugins
gradlePlugin-pluginPublishing = { module = "com.gradle.publish:plugin-publish-plugin", version.ref = "gradlePluginPublishPlugin" }
gradlePlugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
gradlePlugin-android = { module = "com.android.tools.build:gradle", version.ref = "androidGradlePlugin" }
## endregion
13 changes: 0 additions & 13 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,6 @@ pluginManagement {
gradlePluginPortal()
mavenCentral()
}

resolutionStrategy {
val kotlinVersion: String by settings
val pluginPublishVersion: String by settings
eachPlugin {
if (requested.id.namespace?.startsWith("org.jetbrains.kotlin") == true) {
useVersion(kotlinVersion)
}
if (requested.id.id == "com.gradle.plugin-publish") {
useVersion(pluginPublishVersion)
}
}
}
}

@Suppress("UnstableApiUsage")
Expand Down
14 changes: 11 additions & 3 deletions src/functionalTest/kotlin/kotlinx/validation/api/TestDsl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@

package kotlinx.validation.api

import java.io.*
import kotlinx.validation.API_DIR
import org.gradle.testkit.runner.GradleRunner
import org.intellij.lang.annotations.Language
import java.io.*

internal fun BaseKotlinGradleTest.test(fn: BaseKotlinScope.() -> Unit): GradleRunner {
val baseKotlinScope = BaseKotlinScope()
Expand Down Expand Up @@ -40,7 +40,11 @@ internal fun BaseKotlinGradleTest.test(fn: BaseKotlinScope.() -> Unit): GradleRu
/**
* same as [file][FileContainer.file], but prepends "src/${sourceSet}/kotlin" before given `classFileName`
*/
internal fun FileContainer.kotlin(classFileName: String, sourceSet: String = "main", fn: AppendableScope.() -> Unit) {
internal fun FileContainer.kotlin(
classFileName: String,
sourceSet: String = "main",
fn: AppendableScope.() -> Unit,
) {
require(classFileName.endsWith(".kt")) {
"ClassFileName must end with '.kt'"
}
Expand All @@ -52,7 +56,11 @@ internal fun FileContainer.kotlin(classFileName: String, sourceSet: String = "ma
/**
* same as [file][FileContainer.file], but prepends "src/${sourceSet}/java" before given `classFileName`
*/
internal fun FileContainer.java(classFileName: String, sourceSet: String = "main", fn: AppendableScope.() -> Unit) {
internal fun FileContainer.java(
classFileName: String,
sourceSet: String = "main",
fn: AppendableScope.() -> Unit,
) {
require(classFileName.endsWith(".java")) {
"ClassFileName must end with '.java'"
}
Expand Down