Skip to content

Commit

Permalink
Shade antlr dependency for partiql-parser and partiql-lang
Browse files Browse the repository at this point in the history
  • Loading branch information
alancai98 committed Apr 19, 2024
1 parent d302a01 commit d3961ac
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 41 deletions.
3 changes: 3 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -44,6 +46,7 @@ dependencies {
implementation(Plugins.kotlinGradle)
implementation(Plugins.ktlint)
implementation(Plugins.pig)
implementation(Plugins.shadow)
}

allprojects {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -51,6 +54,7 @@ abstract class PublishPlugin : Plugin<Project> {
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) }
Expand Down Expand Up @@ -86,57 +90,63 @@ abstract class PublishPlugin : Plugin<Project> {
}

// Setup Maven Central Publishing
val publishing = extensions.getByType(PublishingExtension::class.java).apply {
publications {
create<MavenPublication>("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:[email protected]:partiql/partiql-lang-kotlin.git")
developerConnection.set("scm:[email protected]:partiql/partiql-lang-kotlin.git")
url.set("[email protected]:partiql/partiql-lang-kotlin.git")
afterEvaluate {
val publishing = extensions.getByType(PublishingExtension::class.java).apply {
publications {
create<MavenPublication>("maven") {
project.extensions.configure<ShadowExtension> {
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:[email protected]:partiql/partiql-lang-kotlin.git")
developerConnection.set("scm:[email protected]:partiql/partiql-lang-kotlin.git")
url.set("[email protected]:partiql/partiql-lang-kotlin.git")
}
}
developers {
developer {
name.set("PartiQL Team")
email.set("[email protected]")
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("[email protected]")
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"])
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions partiql-lang/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
11 changes: 11 additions & 0 deletions partiql-parser/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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('.', '/')}"
Expand Down

0 comments on commit d3961ac

Please sign in to comment.