Skip to content

Commit

Permalink
Build: Add iceberg-bom artifact (apache#8065)
Browse files Browse the repository at this point in the history
BOMs are pretty useful to align dependencies of a project. Their usage is optional though.
  • Loading branch information
snazy authored Jan 16, 2024
1 parent ea30d36 commit 13e108b
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 42 deletions.
5 changes: 5 additions & 0 deletions baseline.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ allprojects {
}

subprojects {
if (it.name == 'iceberg-bom') {
// the BOM does not build anything, the below plugins are not necessary (and can fail)
return
}

// Currently, if any subproject applies the blanket Baseline plugin, it forces the Baseline plugin
// to be applied to ALL projects. And we are not prepared to address all of the build errors that
// occur as a result at this time. Furthermore, baseline-format will not work out of the box for
Expand Down
43 changes: 43 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ allprojects {
}

subprojects {
if (it.name == 'iceberg-bom') {
// the BOM does not build anything, the code below expects "source code"
return
}

apply plugin: 'java-library'

if (project.name in REVAPI_PROJECTS) {
Expand Down Expand Up @@ -1008,3 +1013,41 @@ apply from: 'baseline.gradle'
apply from: 'deploy.gradle'
apply from: 'tasks.gradle'

project(':iceberg-bom') {
apply plugin: 'java-platform'

dependencies {
constraints {
// The Iceberg-Build builds for only one Scala version at a time, so the BOM would also
// only contain artifacts for that single Scala version. The following code ensures that
// the BOM references the artifacts for all Scala versions.
def sparkScalaPattern = ~"(.*)-([0-9][.][0-9]+)_([0-9][.][0-9]+)"
def sparkScalaVersions = [
"3.3": ["2.12", "2.13"],
"3.4": ["2.12", "2.13"],
"3.5": ["2.12", "2.13"],
]
rootProject.allprojects.forEach {
// Do not include ':iceberg-spark', the bom itself and the root project.
if (it.name != 'iceberg-bom' && it != rootProject && it.childProjects.isEmpty()) {
if (it.name.startsWith("iceberg-spark-")) {
def sparkScalaMatcher = sparkScalaPattern.matcher(it.name)
if (!sparkScalaMatcher.find()) {
throw new GradleException("Expected a Spark/Scala version combination in Gradle project name ${it.name}")
}
def prjName = sparkScalaMatcher.group(1)
def sparkVer = sparkScalaMatcher.group(2)
for (def scalaVer in sparkScalaVersions[sparkVer]) {
add("api", "${it.group}:$prjName-${sparkVer}_$scalaVer:${it.version}")
}
} else {
add("api", project(it.path))
}
}
}
}
}

// Needed to get the "faked" Scala artifacts into the bom
javaPlatform { allowDependencies() }
}
86 changes: 47 additions & 39 deletions deploy.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,62 +22,70 @@ if (project.hasProperty('release') && jdkVersion != '8') {
}

subprojects {
def isBom = it.name == 'iceberg-bom'

apply plugin: 'maven-publish'
apply plugin: 'signing'
afterEvaluate {

task sourceJar(type: Jar, dependsOn: classes) {
archiveClassifier.set('sources')
from sourceSets.main.allSource
group 'build'
}

task javadocJar(type: Jar, dependsOn: javadoc) {
archiveClassifier.set('javadoc')
from javadoc.destinationDir
group 'build'
}
if (!isBom) {
task sourceJar(type: Jar, dependsOn: classes) {
archiveClassifier.set('sources')
from sourceSets.main.allSource
group 'build'
}

task testJar(type: Jar) {
archiveClassifier.set('tests')
from sourceSets.test.output
}
task javadocJar(type: Jar, dependsOn: javadoc) {
archiveClassifier.set('javadoc')
from javadoc.destinationDir
group 'build'
}

artifacts {
archives sourceJar
archives javadocJar
archives testJar
testArtifacts testJar
}
task testJar(type: Jar) {
archiveClassifier.set('tests')
from sourceSets.test.output
}

// add LICENSE and NOTICE
[jar, sourceJar, javadocJar, testJar].each { task ->
task.dependsOn rootProject.tasks.buildInfo
task.from("${rootDir}/build") {
include 'iceberg-build.properties'
artifacts {
archives sourceJar
archives javadocJar
archives testJar
testArtifacts testJar
}
task.from(rootDir) {
include 'LICENSE'
include 'NOTICE'

// add LICENSE and NOTICE
[jar, sourceJar, javadocJar, testJar].each { task ->
task.dependsOn rootProject.tasks.buildInfo
task.from("${rootDir}/build") {
include 'iceberg-build.properties'
}
task.from(rootDir) {
include 'LICENSE'
include 'NOTICE'
}
}
}

publishing {
publications {
apache(MavenPublication) {
if (tasks.matching({task -> task.name == 'shadowJar'}).isEmpty()) {
from components.java
if (isBom) {
from components.javaPlatform
} else {
project.shadow.component(it)
}
if (tasks.matching({task -> task.name == 'shadowJar'}).isEmpty()) {
from components.java
} else {
project.shadow.component(it)
}

artifact sourceJar
artifact javadocJar
artifact testJar
artifact sourceJar
artifact javadocJar
artifact testJar

versionMapping {
allVariants {
fromResolutionResult()
versionMapping {
allVariants {
fromResolutionResult()
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

rootProject.name = 'iceberg'
include 'bom'
include 'api'
include 'common'
include 'core'
Expand All @@ -42,6 +43,7 @@ include 'snowflake'
include 'delta-lake'
include 'kafka-connect'

project(':bom').name = 'iceberg-bom'
project(':api').name = 'iceberg-api'
project(':common').name = 'iceberg-common'
project(':core').name = 'iceberg-core'
Expand Down
7 changes: 4 additions & 3 deletions tasks.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@


task aggregateJavadoc(type: Javadoc) {
dependsOn subprojects.javadoc
source subprojects.javadoc.source
def javadocTasks = subprojects.findAll { it.name != 'iceberg-bom' }.javadoc
dependsOn javadocTasks
source javadocTasks.source
destinationDir project.rootProject.file("site/docs/javadoc/${getJavadocVersion()}")
classpath = project.rootProject.files(subprojects.javadoc.classpath)
classpath = project.rootProject.files(javadocTasks.classpath)

final JAVADOC_FIX_SEARCH_STR = '\n\n' +
'getURLPrefix = function(ui) {\n' +
Expand Down

0 comments on commit 13e108b

Please sign in to comment.