1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import java.io.File
plugins {
`java-base`
`maven-publish`
id("com.github.johnrengelman.shadow") version "4.0.3" apply false
}
repositories {
jcenter()
}
val baseProtobuf by configurations.creating
val baseProtobufSources by configurations.creating
val protobufVersion: String by rootProject.extra
val protobufJarPrefix = "protobuf-$protobufVersion"
val renamedSources = "$buildDir/renamedSrc/"
val outputJarsPath = "$buildDir/libs"
dependencies {
baseProtobuf("com.google.protobuf:protobuf-java:$protobufVersion")
baseProtobufSources("com.google.protobuf:protobuf-java:$protobufVersion:sources")
}
val prepare = task<ShadowJar>("prepare") {
destinationDir = File(outputJarsPath)
version = protobufVersion
classifier = ""
from(
provider {
baseProtobuf.files.find { it.name.startsWith("protobuf-java") }?.canonicalPath
}
)
relocate("com.google.protobuf", "org.jetbrains.kotlin.protobuf" ) {
exclude("META-INF/maven/com.google.protobuf/protobuf-java/pom.properties")
}
}
artifacts.add("default", prepare)
val relocateSources = task<Copy>("relocateSources") {
from(
provider {
zipTree(baseProtobufSources.files.find { it.name.startsWith("protobuf-java") && it.name.endsWith("-sources.jar") }
?: throw GradleException("sources jar not found among ${baseProtobufSources.files}"))
}
)
into(renamedSources)
filter { it.replace("com.google.protobuf", "org.jetbrains.kotlin.protobuf") }
}
val prepareSources = task<Jar>("prepareSources") {
destinationDir = File(outputJarsPath)
version = protobufVersion
classifier = "sources"
from(relocateSources)
}
artifacts.add("default", prepareSources)
publishing {
publications {
create<MavenPublication>("maven") {
artifact(prepare)
artifact(prepareSources)
}
}
repositories {
maven {
url = uri("${rootProject.buildDir}/internal/repo")
}
}
}
|