Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shade antlr dependency for partiql-parser and partiql-lang #1439

Merged
merged 11 commits into from
May 14, 2024
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 ktlint = "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 ktlint = "org.jlleitschuh.gradle:ktlint-gradle:${Versions.ktlint}"
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.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,7 @@

package org.partiql.gradle.plugin.publish

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 @@ -38,7 +39,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 +52,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 +88,71 @@ 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")
}
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
artifact(tasks["shadowJar"])
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")
project.configurations["api"].allDependencies.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")
}
}
}
}
}
}
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
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 @@ -49,7 +49,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
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
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.thirdparty.antlr"
johnedquinn marked this conversation as resolved.
Show resolved Hide resolved
)

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()
}
}

alancai98 marked this conversation as resolved.
Show resolved Hide resolved
publish {
artifactId = "partiql-lang-kotlin"
name = "PartiQL Lang Kotlin"
Expand Down
39 changes: 36 additions & 3 deletions partiql-parser/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,27 @@ dependencies {
api(project(":partiql-ast"))
api(project(":partiql-types"))
implementation(Deps.ionElement)
implementation(Deps.antlrRuntime)
shadow(Deps.antlrRuntime)
}

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

tasks.shadowJar {
dependsOn(tasks.named("generateGrammarSource"))
configurations = listOf(project.configurations.shadow.get())
archiveClassifier.set("shaded")
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()
}
}

tasks.generateGrammarSource {
Expand All @@ -42,8 +62,21 @@ tasks.compileKotlin {
dependsOn(tasks.generateGrammarSource)
}

tasks.findByName("sourcesJar")?.apply {
dependsOn(tasks.generateGrammarSource)
tasks.compileTestKotlin {
dependsOn(tasks.withType<AntlrTask>())
}

tasks.withType<Jar>().configureEach {
// ensure "generateGrammarSource" is called before "sourcesJar".
dependsOn(tasks.withType<AntlrTask>())
}

tasks.withType<org.jetbrains.dokka.gradle.DokkaTask>().configureEach {
dependsOn(tasks.withType<AntlrTask>())
}

tasks.runKtlintCheckOverTestSourceSet {
dependsOn(tasks.withType<AntlrTask>())
}

tasks.processResources {
Expand Down
43 changes: 35 additions & 8 deletions partiql-planner/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,46 @@ tasks.register<Copy>("copyUtils") {
//
// !! IMPORTANT !! — only run manually, as this will overwrite the existing ir/Nodes.kt.
//
tasks.register<Copy>("copyNodes") {
includeEmptyDirs = false
dependsOn("codegen")
filter { it.replace(Regex("public (?!(override|(fun visit)))"), "internal ") }
from("$buildDir/tmp")
include("**/Nodes.kt")
into("src/main/kotlin")
}
// tasks.register<Copy>("copyNodes") {
// includeEmptyDirs = false
// dependsOn("codegen")
// filter { it.replace(Regex("public (?!(override|(fun visit)))"), "internal ") }
// from("$buildDir/tmp")
// include("**/Nodes.kt")
// into("src/main/kotlin")
// }

tasks.register("generate") {
dependsOn("codegen", "copyUtils")
}

tasks.compileKotlin {
dependsOn("generate")
dependsOn(tasks.withType<Copy>())
johnedquinn marked this conversation as resolved.
Show resolved Hide resolved
}

tasks.withType<org.jlleitschuh.gradle.ktlint.tasks.KtLintFormatTask>().configureEach {
dependsOn(tasks.withType<Copy>())
}

tasks.withType<org.jlleitschuh.gradle.ktlint.tasks.KtLintCheckTask>().configureEach {
dependsOn(tasks.withType<Copy>())
}

tasks.withType<Jar>().configureEach {
dependsOn(tasks.withType<Copy>())
}

tasks.detekt {
dependsOn(tasks.withType<Copy>())
}

tasks.withType<org.jetbrains.dokka.gradle.DokkaTask>().configureEach {
dependsOn(tasks.withType<Copy>())
}

configure<org.jlleitschuh.gradle.ktlint.KtlintExtension> {
filter {
exclude { it.file.path.contains("Nodes.kt") }
}
}
Loading