Files
allwpilib/shared/jni/publish.gradle
Gold856 3bf67edc34 [build] Refactor zip base name generation for consistency (#8831)
Right now, the `zipBaseName` variable in various publish.gradle files
contains the group ID and artifact ID for use by the combiner, however,
they are also duplicated in `artifactGroupId` and `baseArtifactId`,
leading to potential mistakes if they aren't updated together. This
fixes that by adding a new utility function `makeZipBaseName` to
automatically create the right name given a group ID and artifact ID.
This also fixes publishing for thirdparty subprojects, which didn't
update `zipBaseName`.
2026-04-27 11:46:11 -07:00

130 lines
3.7 KiB
Groovy

import java.security.MessageDigest
apply plugin: 'maven-publish'
def outputsFolder = file("$buildDir/outputs")
def baseArtifactId = nativeName
def artifactGroupId = "org.wpilib.${nativeName}"
def zipBaseName = makeZipBaseName(artifactGroupId, "${baseArtifactId}-cpp")
ext.zipBaseName = zipBaseName
def jniCvStaticBaseName = makeZipBaseName(artifactGroupId, "${nativeName}-jnicvstatic")
def licenseFile = file("$rootDir/license.md")
task cppSourcesZip(type: Zip) {
destinationDirectory = outputsFolder
archiveBaseName = zipBaseName
archiveClassifier = "sources"
duplicatesStrategy = 'exclude'
from(licenseFile) {
into '/'
}
from('src/main/native/cpp') {
into '/'
}
model {
components {
it.all {
if (it in getJniSpecClass()) {
it.jniHeaderLocations.each {
dependsOn it.key
from(it.value) {
into '/jni'
}
}
}
}
}
}
}
task cppHeadersZip(type: Zip) {
destinationDirectory = outputsFolder
archiveBaseName = zipBaseName
archiveClassifier = "headers"
from(licenseFile) {
into '/'
}
ext.includeDirs = [
project.file('src/main/native/include')
]
ext.includeDirs.each {
from(it) {
into '/'
}
}
}
artifacts {
tasks.named("assemble") {
dependsOn(cppHeadersZip)
dependsOn(cppSourcesZip)
}
}
addTaskToCopyAllOutputs(cppSourcesZip)
addTaskToCopyAllOutputs(cppHeadersZip)
model {
publishing {
def taskList = createComponentZipTasks($.components, [
nativeName,
"${nativeName}JNIShared"
], zipBaseName, Zip, project, includeStandardZipFormat)
publications {
cpp(MavenPublication) {
taskList.each {
artifact it
}
artifact cppHeadersZip
artifact cppSourcesZip
artifactId = "${baseArtifactId}-cpp"
groupId = artifactGroupId
version = wpilibVersioning.version.get()
}
}
if (project.hasProperty('cvStaticBuild') && project.getProperty('cvStaticBuild') == true) {
def jniCvTaskList = createComponentZipTasks($.components, ["${nativeName}JNICvStatic"], jniCvStaticBaseName, Zip, project, { task, value ->
value.each { binary ->
if (binary.buildable) {
if (binary instanceof SharedLibraryBinarySpec) {
task.dependsOn binary.tasks.link
task.inputs.file(binary.sharedLibraryFile)
task.from(binary.sharedLibraryFile) {
into nativeUtils.getPlatformPath(binary) + '/shared'
}
def sharedPath = binary.sharedLibraryFile.absolutePath
sharedPath = sharedPath.substring(0, sharedPath.length() - 4)
task.from(new File(sharedPath + '.pdb')) {
into nativeUtils.getPlatformPath(binary) + '/shared'
}
}
}
}
})
publications {
jniCvStatic(MavenPublication) {
jniCvTaskList.each {
artifact it
}
artifactId = "${baseArtifactId}-jnicvstatic"
groupId = artifactGroupId
version = wpilibVersioning.version.get()
}
}
}
}
}