Skip to content
Closed
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
78 changes: 71 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,72 @@
# Project exclude paths
/.gradle/
/build/
/buildSrc/.gradle/
/buildSrc/build/
/sample-project/build/
/.idea/
### Kotlin/JVM ###
*.class
*.log

hs_err_pid*
replay_pid*
*.hprof

*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar


### IntelliJ ###
.idea


### Eclipse ###
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
.settings/
.loadpath
.recommenders
.classpath

.apt_generated/
.apt_generated_test/
.project


### Linux ###
*~
.fuse_hidden*
.Trash-*
.nfs*


### Windows ###
[Dd]esktop.ini
$RECYCLE.BIN/
*.lnk


### macOS ###
.DS_Store
._*


# Icon must end with two \r
Icon


###########################

### Gradle ###
.gradle
build/


# Put unignores last so they don't get accidentally re-ignored
!gradle/wrapper/gradle-wrapper.jar
!gradle/wrapper/gradle-wrapper.properties
!/.idea/copyright
285 changes: 285 additions & 0 deletions api/binary-compatibility-validator.api

Large diffs are not rendered by default.

169 changes: 5 additions & 164 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,168 +1,9 @@
import com.gradle.publish.*
import kotlinx.validation.build.*
import org.jetbrains.kotlin.gradle.tasks.*

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

repositories {
mavenCentral()
gradlePluginPortal()
google()
}

sourceSets {
test {
java.srcDir("src/test/kotlin")
}
}

sourceSets {
create("functionalTest") {
withConvention(org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet::class) {
}
compileClasspath += sourceSets.main.get().output + configurations.testRuntimeClasspath
runtimeClasspath += output + compileClasspath
}
}

tasks.register<Test>("functionalTest") {
testClassesDirs = sourceSets["functionalTest"].output.classesDirs
classpath = sourceSets["functionalTest"].runtimeClasspath
}
tasks.check { dependsOn(tasks["functionalTest"]) }

// While gradle testkit supports injection of the plugin classpath it doesn't allow using dependency notation
// to determine the actual runtime classpath for the plugin. It uses isolation, so plugins applied by the build
// script are not visible in the plugin classloader. This means optional dependencies (dependent on applied plugins -
// for example kotlin multiplatform) are not visible even if they are in regular gradle use. This hack will allow
// extending the classpath. It is based upon: https://docs.gradle.org/6.0/userguide/test_kit.html#sub:test-kit-classpath-injection

// Create a configuration to register the dependencies against
val testPluginRuntimeConfiguration = configurations.register("testPluginRuntime")

// The task that will create a file that stores the classpath needed for the plugin to have additional runtime dependencies
// This file is then used in to tell TestKit which classpath to use.
val createClasspathManifest = tasks.register("createClasspathManifest") {
val outputDir = buildDir.resolve("cpManifests")
inputs.files(testPluginRuntimeConfiguration)
.withPropertyName("runtimeClasspath")
.withNormalizer(ClasspathNormalizer::class)

outputs.dir(outputDir)
.withPropertyName("outputDir")

doLast {
outputDir.mkdirs()
file(outputDir.resolve("plugin-classpath.txt")).writeText(testPluginRuntimeConfiguration.get().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")
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib-jdk8")
}

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}")

// 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.
add(testPluginRuntimeConfiguration.name, "org.jetbrains.kotlin.multiplatform:org.jetbrains.kotlin.multiplatform.gradle.plugin:$kotlinVersion")
add(testPluginRuntimeConfiguration.name, "com.android.tools.build:gradle:${androidGradlePluginVersion}")

testImplementation(kotlin("test-junit"))
"functionalTestImplementation"(files(createClasspathManifest))

"functionalTestImplementation"("org.assertj:assertj-core:3.18.1")
"functionalTestImplementation"(gradleTestKit())
"functionalTestImplementation"(kotlin("test-junit"))
}

tasks.compileKotlin {
kotlinOptions.apply {
allWarningsAsErrors = true

languageVersion = "1.4"
apiVersion = "1.4"
jvmTarget = "1.8"

// Suppressing "w: Language version 1.4 is deprecated and its support will be removed" message
// because LV=1.4 in practice is mandatory as it is a default language version in Gradle 7.0+ for users' kts scripts.
freeCompilerArgs += "-Xsuppress-version-warnings"
}
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

tasks {
compileTestKotlin {
kotlinOptions {
languageVersion = "1.6"
}
}
test {
systemProperty("overwrite.output", System.getProperty("overwrite.output", "false"))
systemProperty("testCasesClassesDirs", sourceSets.test.get().output.classesDirs.asPath)
jvmArgs("-ea")
}
}

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

publishing {
publications {
create<MavenPublication>("maven") {
from(components["java"])
mavenCentralMetadata()
mavenCentralArtifacts(project, project.sourceSets.main.get().allSource)
}

mavenRepositoryPublishing(project)
mavenCentralMetadata()
}

publications.withType(MavenPublication::class).all {
signPublicationIfKeyPresent(this)
}
kotlinx.validation.build.conventions.base
id("org.jetbrains.kotlinx.binary-compatibility-validator")
}

apply(plugin = "org.gradle.java-gradle-plugin")
apply(plugin = "com.gradle.plugin-publish")

extensions.getByType(PluginBundleExtension::class).apply {
website = "https://github.com/Kotlin/binary-compatibility-validator"
vcsUrl = "https://github.com/Kotlin/binary-compatibility-validator"
tags = listOf("kotlin", "api-management", "binary-compatibility")
}

gradlePlugin {
testSourceSets(sourceSets["functionalTest"])

plugins {
create("binary-compatibility-validator") {
id = "org.jetbrains.kotlinx.binary-compatibility-validator"
implementationClass = "kotlinx.validation.BinaryCompatibilityValidatorPlugin"
displayName = "Binary compatibility validator"
description = "Produces binary API dumps and compares them in order to verify that binary API is preserved"
}
}
group = "org.jetbrains.kotlinx"
providers.gradleProperty("DeployVersion").orNull?.let {
version = it
}
37 changes: 8 additions & 29 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,24 @@
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
*/

import org.jetbrains.kotlin.gradle.plugin.*
import org.gradle.kotlin.dsl.support.expectedKotlinDslPluginsVersion
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.util.*

plugins {
`kotlin-dsl`
}

repositories {
jcenter()
}

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["main"].withConvention(KotlinSourceSet::class) { kotlin.srcDirs("src") }

kotlinDslPluginOptions {
experimentalWarning.set(false)
implementation("org.gradle.kotlin:gradle-kotlin-dsl-plugins:$expectedKotlinDslPluginsVersion") {
because("allows applying the `kotlin-dsl` / `embedded-kotlin` plugins in buildSrc convention plugins")
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, I know you like removing the unnecessary src/main dirs, but in this case I thought it was extra configuration that didn't really bring much. Given how Gradle can be quite fragile, and how IntelliJ has tenuous support of buildSrc as it is, I thought it was better remove anything not strictly necessary.

Copy link
Member

Choose a reason for hiding this comment

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

It brings a flat folder structure that we would like to embrace everywhere and get rid of the legacy nested format. Dogfooding and reporting all the problems in the process in an important part here.

I'm okay with this change and can tweak it later after all the merges though

implementation(libs.gradlePlugin.kotlin)
implementation(libs.gradlePlugin.pluginPublishing)
implementation(libs.gradlePlugin.bcv)
}

tasks.withType<KotlinCompile>().configureEach {
kotlinOptions.apply {
kotlinOptions {
allWarningsAsErrors = true
apiVersion = "1.3"
freeCompilerArgs += "-Xskip-runtime-version-check"
}
}

// Silence the following warning:
// 'compileJava' task (current target is 17) and 'compileKotlin' task (current target is 1.8) jvm target compatibility should be set to the same Java version.
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
31 changes: 31 additions & 0 deletions buildSrc/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.
*/
import org.gradle.api.initialization.resolve.RepositoriesMode.PREFER_SETTINGS

rootProject.name = "buildSrc"

pluginManagement {
repositories {
gradlePluginPortal()
mavenCentral()
}
}

@Suppress("UnstableApiUsage")
dependencyResolutionManagement {

repositoriesMode.set(PREFER_SETTINGS)

repositories {
mavenCentral()
gradlePluginPortal()
}

versionCatalogs {
create("libs") {
from(files("../gradle/libs.versions.toml"))
}
}
}
56 changes: 0 additions & 56 deletions buildSrc/src/MavenCentralMetadata.kt

This file was deleted.

Loading