diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 48c6cbf7dd..2f883199bc 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -28,6 +28,7 @@ object Versions { const val kotlin = "1.6.20" const val ktlint = "10.2.1" const val pig = "0.6.1" + const val shadow = "7.1.2" } object Plugins { @@ -36,6 +37,7 @@ object Plugins { const val kotlinGradle = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}" const val ktlint = "org.jlleitschuh.gradle:ktlint-gradle:${Versions.ktlint}" const val pig = "org.partiql:pig-gradle-plugin:${Versions.pig}" + const val shadow = "gradle.plugin.com.github.johnrengelman:shadow:${Versions.shadow}" } dependencies { @@ -44,6 +46,7 @@ dependencies { implementation(Plugins.kotlinGradle) implementation(Plugins.ktlint) implementation(Plugins.pig) + implementation(Plugins.shadow) } allprojects { diff --git a/buildSrc/src/main/kotlin/org/partiql/gradle/plugin/publish/PublishPlugin.kt b/buildSrc/src/main/kotlin/org/partiql/gradle/plugin/publish/PublishPlugin.kt index c7097f73a6..33095df382 100644 --- a/buildSrc/src/main/kotlin/org/partiql/gradle/plugin/publish/PublishPlugin.kt +++ b/buildSrc/src/main/kotlin/org/partiql/gradle/plugin/publish/PublishPlugin.kt @@ -15,6 +15,8 @@ package org.partiql.gradle.plugin.publish +import com.github.jengelman.gradle.plugins.shadow.ShadowExtension +import com.github.jengelman.gradle.plugins.shadow.ShadowPlugin import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.api.plugins.JavaPlugin @@ -35,10 +37,11 @@ import org.jetbrains.dokka.gradle.DokkaTask import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension import java.io.File +import org.gradle.kotlin.dsl.configure /** * Gradle plugin to consolidates the following publishing logic - * - Maven Publising + * - Maven Publishing * - Signing * - SourcesJar * - Dokka + JavadocJar @@ -51,6 +54,7 @@ abstract class PublishPlugin : Plugin { pluginManager.apply(MavenPublishPlugin::class.java) pluginManager.apply(SigningPlugin::class.java) pluginManager.apply(DokkaPlugin::class.java) + pluginManager.apply(ShadowPlugin::class.java) extensions.getByType(KotlinJvmProjectExtension::class.java).explicitApi = ExplicitApiMode.Strict val ext = extensions.create("publish", PublishExtension::class.java) target.afterEvaluate { publish(ext) } @@ -86,57 +90,63 @@ abstract class PublishPlugin : Plugin { } // Setup Maven Central Publishing - val publishing = extensions.getByType(PublishingExtension::class.java).apply { - publications { - create("maven") { - artifactId = ext.artifactId - from(components["java"]) - pom { - packaging = "jar" - name.set(ext.name) - description.set(ext.description) - url.set(ext.url) - scm { - connection.set("scm:git@github.com:partiql/partiql-lang-kotlin.git") - developerConnection.set("scm:git@github.com:partiql/partiql-lang-kotlin.git") - url.set("git@github.com:partiql/partiql-lang-kotlin.git") + afterEvaluate { + val publishing = extensions.getByType(PublishingExtension::class.java).apply { + publications { + create("maven") { + project.extensions.configure { + component(this@create) } - licenses { - license { - name.set("The Apache License, Version 2.0") - url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") + + artifactId = ext.artifactId + from(components["java"]) + pom { + packaging = "jar" + name.set(ext.name) + description.set(ext.description) + url.set(ext.url) + scm { + connection.set("scm:git@github.com:partiql/partiql-lang-kotlin.git") + developerConnection.set("scm:git@github.com:partiql/partiql-lang-kotlin.git") + url.set("git@github.com:partiql/partiql-lang-kotlin.git") } - } - developers { - developer { - name.set("PartiQL Team") - email.set("partiql-dev@amazon.com") - organization.set("PartiQL") - organizationUrl.set("https://github.com/partiql") + licenses { + license { + name.set("The Apache License, Version 2.0") + url.set("http://www.apache.org/licenses/LICENSE-2.0.txt") + } + } + developers { + developer { + name.set("PartiQL Team") + email.set("partiql-dev@amazon.com") + organization.set("PartiQL") + organizationUrl.set("https://github.com/partiql") + } } } } } - } - repositories { - maven { - url = uri("https://aws.oss.sonatype.org/service/local/staging/deploy/maven2") - credentials { - val ossrhUsername: String by rootProject - val ossrhPassword: String by rootProject - username = ossrhUsername - password = ossrhPassword + repositories { + maven { + url = uri("https://aws.oss.sonatype.org/service/local/staging/deploy/maven2") + credentials { + val ossrhUsername: String by rootProject + val ossrhPassword: String by rootProject + username = ossrhUsername + password = ossrhPassword + } } } } - } - // Sign only if publishing to Maven Central - extensions.getByType(SigningExtension::class.java).run { - setRequired { - releaseVersion && gradle.taskGraph.allTasks.any { it is PublishToMavenRepository } + // Sign only if publishing to Maven Central + extensions.getByType(SigningExtension::class.java).run { + setRequired { + releaseVersion && gradle.taskGraph.allTasks.any { it is PublishToMavenRepository } + } + sign(publishing.publications["maven"]) } - sign(publishing.publications["maven"]) } } } diff --git a/partiql-lang/build.gradle.kts b/partiql-lang/build.gradle.kts index d114530e9c..9531e40dee 100644 --- a/partiql-lang/build.gradle.kts +++ b/partiql-lang/build.gradle.kts @@ -64,6 +64,16 @@ dependencies { } } +val relocations = mapOf( + "org.antlr" to "org.partiql.thirdparty.antlr" +) + +tasks.shadowJar { + for ((from, to) in relocations) { + relocate(from, to) + } +} + publish { artifactId = "partiql-lang-kotlin" name = "PartiQL Lang Kotlin" diff --git a/partiql-parser/build.gradle.kts b/partiql-parser/build.gradle.kts index 24657d1e94..f2b9be0601 100644 --- a/partiql-parser/build.gradle.kts +++ b/partiql-parser/build.gradle.kts @@ -26,6 +26,17 @@ dependencies { implementation(Deps.antlrRuntime) } +val relocations = mapOf( + "org.antlr" to "org.partiql.thirdparty.antlr" +) + +tasks.shadowJar { + dependsOn(tasks.named("generateGrammarSource")) + for ((from, to) in relocations) { + relocate(from, to) + } +} + tasks.generateGrammarSource { val antlrPackage = "org.partiql.parser.antlr" val antlrSources = "$buildDir/generated-src/${antlrPackage.replace('.', '/')}"