Files
kotlin-fork/libraries/tools/kotlin-gradle-plugin-idea-proto/build.gradle.kts
T
2022-11-17 07:38:42 +00:00

113 lines
3.1 KiB
Kotlin

@file:Suppress("HasPlatformType")
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
plugins {
kotlin("jvm")
}
kotlin {
sourceSets.all {
languageSettings.optIn("org.jetbrains.kotlin.gradle.InternalKotlinGradlePluginApi")
}
}
val embedded by configurations.getting {
isTransitive = false
configurations.getByName("compileOnly").extendsFrom(this)
configurations.getByName("testImplementation").extendsFrom(this)
}
dependencies {
api(project(":kotlin-gradle-plugin-idea"))
embedded("com.google.protobuf:protobuf-java:3.21.9")
embedded("com.google.protobuf:protobuf-kotlin:3.21.9")
testImplementation(project(":kotlin-test:kotlin-test-junit"))
testImplementation(testFixtures(project(":kotlin-gradle-plugin-idea")))
}
configureKotlinCompileTasksGradleCompatibility()
sourceSets.main.configure {
java.srcDir("src/generated/java")
java.srcDir("src/generated/kotlin")
}
publish()
javadocJar()
sourcesJar()
runtimeJar(tasks.register<ShadowJar>("embeddable")) {
from(mainSourceSet.output)
exclude("**/*.proto")
relocate("com.google.protobuf", "org.jetbrains.kotlin.gradle.idea.proto.com.google.protobuf")
}
/* Setup configuration for binary compatibility tests */
run {
val binaryValidationApiElements by configurations.creating {
isCanBeResolved = false
isCanBeConsumed = true
}
val binaryValidationApiJar = tasks.register<Jar>("binaryValidationApiJar") {
this.archiveBaseName.set(project.name + "-api")
from(mainSourceSet.output)
}
artifacts.add(binaryValidationApiElements.name, binaryValidationApiJar)
}
/* Setup protoc */
tasks.register<Exec>("protoc") {
val protoSources = file("src/main/proto")
val javaOutput = file("src/generated/java/")
val kotlinOutput = file("src/generated/kotlin/")
inputs.dir(protoSources)
outputs.dir(javaOutput)
outputs.dir(kotlinOutput)
doFirst {
javaOutput.deleteRecursively()
kotlinOutput.deleteRecursively()
javaOutput.mkdirs()
kotlinOutput.mkdirs()
}
workingDir(project.projectDir)
commandLine(
*arrayOf(
"protoc",
"-I=$protoSources",
"--java_out=${javaOutput.absolutePath}",
"--kotlin_out=${kotlinOutput.absolutePath}"
) + protoSources.listFiles().orEmpty()
.filter { it.extension == "proto" }
.map { it.path },
)
}
/* Setup backwards compatibility tests */
run {
val compatibilityTestClasspath by configurations.creating {
isCanBeResolved = true
isCanBeConsumed = false
attributes.attribute(Usage.USAGE_ATTRIBUTE, objects.named(Usage.JAVA_RUNTIME))
attributes.attribute(Category.CATEGORY_ATTRIBUTE, objects.named(Category.LIBRARY))
}
dependencies {
compatibilityTestClasspath(project(":kotlin-gradle-plugin-idea-for-compatibility-tests"))
}
tasks.test {
dependsOn(compatibilityTestClasspath)
inputs.files(compatibilityTestClasspath)
doFirst { systemProperty("compatibilityTestClasspath", compatibilityTestClasspath.files.joinToString(";") { it.absolutePath }) }
}
}