Skip to content

Commit

Permalink
Shade antlr dependency for partiql-parser and partiql-lang (#1439)
Browse files Browse the repository at this point in the history
  • Loading branch information
alancai98 authored May 14, 2024
1 parent 2a13661 commit 5d49b21
Show file tree
Hide file tree
Showing 13 changed files with 196 additions and 79 deletions.
5 changes: 4 additions & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ repositories {
}

object Versions {
const val detekt = "1.20.0-RC1"
const val detekt = "1.20.0-RC2"
const val dokka = "1.6.10"
const val kotlin = "1.6.20"
const val ktlintGradle = "10.2.1"
const val pig = "0.6.1"
const val shadow = "8.1.1"
}

object Plugins {
Expand All @@ -36,6 +37,7 @@ object Plugins {
const val kotlinGradle = "org.jetbrains.kotlin:kotlin-gradle-plugin:${Versions.kotlin}"
const val ktlintGradle = "org.jlleitschuh.gradle:ktlint-gradle:${Versions.ktlintGradle}"
const val pig = "org.partiql:pig-gradle-plugin:${Versions.pig}"
const val shadow = "com.github.johnrengelman:shadow:${Versions.shadow}"
}

dependencies {
Expand All @@ -44,6 +46,7 @@ dependencies {
implementation(Plugins.kotlinGradle)
implementation(Plugins.ktlintGradle)
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.ShadowPlugin
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPlugin
Expand All @@ -38,7 +40,7 @@ import java.io.File

/**
* Gradle plugin to consolidates the following publishing logic
* - Maven Publising
* - Maven Publishing
* - Signing
* - SourcesJar
* - Dokka + JavadocJar
Expand All @@ -51,6 +53,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 @@ -85,58 +88,98 @@ abstract class PublishPlugin : Plugin<Project> {
from(tasks.named("dokkaHtml"))
}

tasks.getByName<ShadowJar>("shadowJar") {
// Use the default name for published shadow jar
archiveClassifier.set("")
}

tasks.getByName<Jar>("jar") {
// Rename jar for `project` dependencies; not published to Maven
archiveClassifier.set("original")
}

// 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")
}
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
afterEvaluate {
val publishing = extensions.getByType(PublishingExtension::class.java).apply {
publications {
create<MavenPublication>("maven") {
// Publish the shadow jar; create dependencies separately since `ShadowExtension.component`
// does not include non-shadowed in POM dependencies
artifact(tasks["shadowJar"])
artifact(tasks["sourcesJar"])
artifact(tasks["javadocJar"])
artifactId = ext.artifactId
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")
}
}
// Publish the dependencies
withXml {
val dependenciesNode = asNode().appendNode("dependencies")
val apiDeps = project.configurations["api"].allDependencies
.filter { it.name !in ext.excludedDependencies }
val implDeps = project.configurations["implementation"].allDependencies
.filter { it !in apiDeps && it.name !in ext.excludedDependencies }
// Add Gradle 'api' dependencies; mapped to Maven 'compile'
apiDeps.forEach { dependency ->
val dependencyNode = dependenciesNode.appendNode("dependency")
dependencyNode.appendNode("groupId", dependency.group)
dependencyNode.appendNode("artifactId", dependency.name)
dependencyNode.appendNode("version", dependency.version)
dependencyNode.appendNode("scope", "compile")
}
// Add Gradle 'implementation' dependencies; mapped to Maven 'runtime'
implDeps.forEach { dependency ->
val dependencyNode = dependenciesNode.appendNode("dependency")
dependencyNode.appendNode("groupId", dependency.group)
dependencyNode.appendNode("artifactId", dependency.name)
dependencyNode.appendNode("version", dependency.version)
dependencyNode.appendNode("scope", "runtime")
}
}
}
}
}
}
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 All @@ -146,6 +189,7 @@ abstract class PublishExtension {
var name: String = ""
var description: String = ""
var url: String = "https://github.com/partiql/partiql-lang-kotlin"
var excludedDependencies: Set<String> = setOf()
override fun toString(): String {
return "PublishExtension(artifactId='$artifactId', name='$name', description='$description', url='$url')"
}
Expand Down
5 changes: 4 additions & 1 deletion buildSrc/src/main/kotlin/partiql.conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ java {

tasks.test {
useJUnitPlatform() // Enable JUnit5
jvmArgs.addAll(listOf("-Duser.language=en", "-Duser.country=US"))
jvmArgs(
"-Duser.language=en",
"-Duser.country=US"
)
maxHeapSize = "4g"
testLogging {
events.add(TestLogEvent.FAILED)
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/partiql.versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ object Versions {

// Testing
const val assertj = "3.11.0"
const val jacoco = "0.8.8"
const val jacoco = "0.8.11"
const val junit5 = "5.9.3"
const val junit5PlatformLauncher = "1.9.3"
const val junit4 = "4.12"
Expand Down
1 change: 0 additions & 1 deletion examples/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ application {

dependencies {
implementation(project(":partiql-lang"))
implementation(project(":partiql-types"))
implementation(Deps.kotlinxCoroutines)
implementation(Deps.kotlinxCoroutinesJdk8)
implementation(Deps.awsSdkS3)
Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6 changes: 0 additions & 6 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,6 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand Down
14 changes: 6 additions & 8 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@rem limitations under the License.
@rem

@if "%DEBUG%"=="" @echo off
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
Expand All @@ -25,7 +25,7 @@
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%"=="" set DIRNAME=.
if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand All @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
if "%ERRORLEVEL%" == "0" goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand Down Expand Up @@ -75,15 +75,13 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

:end
@rem End local scope for the variables with windows NT shell
if %ERRORLEVEL% equ 0 goto mainEnd
if "%ERRORLEVEL%"=="0" goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1

:mainEnd
if "%OS%"=="Windows_NT" endlocal
Expand Down
6 changes: 0 additions & 6 deletions partiql-cli/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,7 @@ plugins {

dependencies {
implementation(project(":partiql-lang"))
implementation(project(":partiql-ast"))
implementation(project(":partiql-parser"))
implementation(project(":partiql-plan"))
implementation(project(":partiql-planner"))
implementation(project(":partiql-types"))
implementation(project(":plugins:partiql-local"))
implementation(project(":partiql-spi"))
implementation(Deps.csv)
implementation(Deps.awsSdkBom)
implementation(Deps.awsSdkDynamodb)
Expand Down
20 changes: 19 additions & 1 deletion partiql-lang/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ dependencies {
api(Deps.ionElement)
api(Deps.ionJava)
api(Deps.ionSchema)
implementation(Deps.antlrRuntime)
shadow(Deps.antlrRuntime)
implementation(Deps.csv)
implementation(Deps.kotlinReflect)
implementation(Deps.kotlinxCoroutines)
Expand Down Expand Up @@ -64,6 +64,24 @@ dependencies {
}
}

val relocations = mapOf(
"org.antlr" to "org.partiql.lang.thirdparty.antlr"
)

tasks.shadowJar {
configurations = listOf(project.configurations.shadow.get())
for ((from, to) in relocations) {
relocate(from, to)
}
}

// Workaround for https://github.com/johnrengelman/shadow/issues/651
components.withType(AdhocComponentWithVariants::class.java).forEach { c ->
c.withVariantsFromConfiguration(project.configurations.shadowRuntimeElements.get()) {
skip()
}
}

publish {
artifactId = "partiql-lang-kotlin"
name = "PartiQL Lang Kotlin"
Expand Down
Loading

0 comments on commit 5d49b21

Please sign in to comment.