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

Fix publication of shaded jars #3125

Merged
merged 1 commit into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ subprojects {
ext {
coreProjectName = "fdb-record-layer-core"
shadedProjectName = "fdb-record-layer-core-shaded"
publishLibrary = true
}

artifacts {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ task shadedSourcesJar(type: Jar) {
archiveClassifier = "sources"
from project(coreProject).sourceSets.main.allSource
from project(':fdb-extensions').sourceSets.main.allSource
dependsOn(project(coreProject).tasks.generateProto)
dependsOn(project(coreProject).tasks.compileJava)
}

task shadedJavadocJar(type: Jar) {
Expand Down Expand Up @@ -79,11 +81,11 @@ def addDependencies(projectObj, dependenciesNode) {
}
}

ext.publishLibrary = false

apply from: rootProject.file('gradle/publishing.gradle')

publishing {
publications.remove(publishing.publications.library)

publications {
shadow(MavenPublication) { publication ->
from project.shadow.component(publication)
Expand Down Expand Up @@ -111,6 +113,7 @@ publishing {
artifact tasks.shadedSourcesJar
artifact tasks.shadedJavadocJar
}

}
artifactoryPublish {
publications (publishing.publications.shadow)
Expand Down
82 changes: 42 additions & 40 deletions gradle/publishing.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,36 +47,32 @@ def addPublishingInfo(publication) {
}
}

ext {
// Make the "addPublishingInfo" method visible from outside this plugin
addPublishingInfo = this.&addPublishingInfo
}
if (ext.publishLibrary) {
publishing {
publications {
library(MavenPublication) { publication ->
from components.java

publishing {
publications {
library(MavenPublication) { publication ->
from components.java

// Test fixtures appear to be placing their dependencies in the wrong scope
// for maven compilation, which means that their dependencies wind up in the
// final project's pom.xml.
// See: https://github.com/gradle/gradle/issues/14936
// Until this is fixed, skip these configurations to avoid polluting the list of dependencies
configurations.each { config ->
if (config.name == 'testFixturesApiElements' || config.name == 'testFixturesRuntimeElements') {
components.java.withVariantsFromConfiguration(config) {
skip()
// Test fixtures appear to be placing their dependencies in the wrong scope
// for maven compilation, which means that their dependencies wind up in the
// final project's pom.xml.
// See: https://github.com/gradle/gradle/issues/14936
// Until this is fixed, skip these configurations to avoid polluting the list of dependencies
configurations.each { config ->
if (config.name == 'testFixturesApiElements' || config.name == 'testFixturesRuntimeElements') {
components.java.withVariantsFromConfiguration(config) {
skip()
}
}
}
}

artifact tasks.sourcesJar
artifact tasks.javadocJar
artifact tasks.testJar
addPublishingInfo(publication)
artifact tasks.sourcesJar
artifact tasks.javadocJar
artifact tasks.testJar
addPublishingInfo(publication)
}
}
}

artifactoryPublish {
// As a safeguard, only actually publish to artifactory if -PpublishBuild=true is passed to gradle
// Note: skip is documented, but onlyIf seems to also be required to make this work for some reason
Expand All @@ -88,7 +84,29 @@ publishing {
}
publications(publishing.publications.library)
}
createDistribution.configure {
afterEvaluate {
dependsOn generatePomFileForLibraryPublication
from tasks.jar, tasks.sourcesJar, tasks.javadocJar, tasks.testJar, tasks.generatePomFileForLibraryPublication
rename { filename ->
GenerateMavenPom pomTask = tasks.generatePomFileForLibraryPublication
Jar jarTask = tasks.jar
if (filename == pomTask.destination.name) {
jarTask.archiveName.replace "jar", "pom"
} else {
filename
}
}
}
}
}

ext {
// Make the "addPublishingInfo" method visible from outside this plugin
addPublishingInfo = this.&addPublishingInfo
}

publishing {
if (Boolean.parseBoolean(publishBuild)) {
repositories {
if (Boolean.parseBoolean(githubPublish)) {
Expand Down Expand Up @@ -137,19 +155,3 @@ if (System.getenv('ARTIFACTORY_USER') != null && System.getenv('ARTIFACTORY_KEY'
}
}
}

createDistribution.configure {
afterEvaluate {
dependsOn generatePomFileForLibraryPublication
from tasks.jar, tasks.sourcesJar, tasks.javadocJar, tasks.testJar, tasks.generatePomFileForLibraryPublication
rename { filename ->
GenerateMavenPom pomTask = tasks.generatePomFileForLibraryPublication
Jar jarTask = tasks.jar
if (filename == pomTask.destination.name) {
jarTask.archiveName.replace "jar", "pom"
} else {
filename
}
}
}
}
Loading