Skip to content

Commit eb8c52a

Browse files
authored
update jar packing in publish (#47)
* optimize release binary * jar packing * fix tar * fix ci as well * fix invalid path * jar with lib * skip build during copy * update dependency * update and use tree cmd * fix jar extension
1 parent 608ca88 commit eb8c52a

File tree

3 files changed

+101
-96
lines changed

3 files changed

+101
-96
lines changed

.github/workflows/build.yml

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
name: Build
22
on:
33
push:
4-
branches: [ "*" ]
4+
branches: ["*"]
55
pull_request:
6-
branches: [ "*" ]
6+
branches: ["*"]
77
jobs:
88
rust:
99
strategy:
1010
matrix:
11-
os: [ "ubuntu-latest", "macos-latest" ]
11+
os: ["ubuntu-latest", "macos-latest"]
1212
runs-on: ${{ matrix.os }}
1313
steps:
1414
- uses: actions/checkout@v2
@@ -72,19 +72,22 @@ jobs:
7272
uses: actions/download-artifact@v3
7373
with:
7474
name: datafusion-jni-ubuntu-latest
75-
path: datafusion-jni/target/release
75+
path: datafusion-java/build/jni_libs/linux-x86_64
7676

77-
# - name: Download windows artifacts
78-
# uses: actions/download-artifact@v3
79-
# with:
80-
# name: datafusion-jni-windows-latest
81-
# path: datafusion-jni/target/release
77+
# - name: Download windows artifacts
78+
# uses: actions/download-artifact@v3
79+
# with:
80+
# name: datafusion-jni-windows-latest
81+
# path: datafusion-jni/target/release
8282

8383
- name: Download macos artifacts
8484
uses: actions/download-artifact@v3
8585
with:
8686
name: datafusion-jni-macos-latest
87-
path: datafusion-jni/target/release
87+
path: datafusion-java/build/jni_libs/osx-x86_64
88+
89+
- name: List downloaded artifacts
90+
run: tree datafusion-java/build/jni_libs
8891

8992
- name: Publish to Maven Local
9093
run: ./gradlew publishToMavenLocal

.github/workflows/release.yml

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
name: Release
22
on:
33
release:
4-
types: [ created ]
4+
types: [created]
55
push:
6-
branches: [ main ]
6+
branches: [main]
77
jobs:
88
rust:
99
strategy:
1010
matrix:
11-
os: [ "ubuntu-latest", "macos-latest" ]
11+
os: ["ubuntu-latest", "macos-latest"]
1212
runs-on: ${{ matrix.os }}
1313
steps:
1414
- uses: actions/checkout@v2
@@ -72,19 +72,22 @@ jobs:
7272
uses: actions/download-artifact@v3
7373
with:
7474
name: datafusion-jni-ubuntu-latest
75-
path: datafusion-jni/target/release
75+
path: datafusion-java/build/jni_libs/linux-x86_64
7676

77-
# - name: Download windows artifacts
78-
# uses: actions/download-artifact@v3
79-
# with:
80-
# name: datafusion-jni-windows-latest
81-
# path: datafusion-jni/target/release
77+
# - name: Download windows artifacts
78+
# uses: actions/download-artifact@v3
79+
# with:
80+
# name: datafusion-jni-windows-latest
81+
# path: datafusion-jni/target/release
8282

8383
- name: Download macos artifacts
8484
uses: actions/download-artifact@v3
8585
with:
8686
name: datafusion-jni-macos-latest
87-
path: datafusion-jni/target/release
87+
path: datafusion-java/build/jni_libs/osx-x86_64
88+
89+
- name: List downloaded artifacts
90+
run: tree datafusion-java/build/jni_libs
8891

8992
- name: Publish to Sonatype
9093
run: ./gradlew publish

datafusion-java/build.gradle

+75-76
Original file line numberDiff line numberDiff line change
@@ -37,97 +37,85 @@ javadoc {
3737
}
3838

3939
task cargoReleaseBuild(type: Exec) {
40-
workingDir '../datafusion-jni'
40+
workingDir "$rootDir/datafusion-jni"
4141
executable "${System.getProperty('user.home')}/.cargo/bin/cargo"
4242
args += ['build', '--release']
4343
}
4444

45-
@SuppressWarnings('GrMethodMayBeStatic')
46-
String getLibExtension() {
47-
if (osdetector.os == "windows") {
48-
return "dll"
49-
} else if (osdetector.os == "linux") {
50-
return "so"
51-
} else if (osdetector.os == "osx") {
52-
return "dylib"
53-
} else {
54-
throw new GradleException("Unsupported OS ${osdetector.os}")
55-
}
45+
def extensionMapping = [
46+
"osx" : "dylib",
47+
"linux" : "so",
48+
"windows": "dll"
49+
]
50+
51+
task copyBuiltLibrary(type: Copy) {
52+
def extension = extensionMapping[osdetector.os]
53+
from "${rootDir}/datafusion-jni/target/release/libdatafusion_jni.$extension"
54+
into layout.buildDirectory.dir("jni_libs/${osdetector.classifier}")
55+
dependsOn cargoReleaseBuild
5656
}
5757

58-
PublishArtifact getArtifact(String extension, String classifier) {
59-
def jniFile = layout.buildDirectory.file("../../datafusion-jni/target/release/libdatafusion_jni.$extension")
60-
return artifacts.add('archives', jniFile.get().asFile) {
61-
type = extension
62-
extension = extension
63-
classifier = classifier
64-
}
58+
def classifierOsx = 'osx-x86_64'
59+
def extensionOsx = 'dylib'
60+
def jniLibOsx = layout.buildDirectory.file("jni_libs/$classifierOsx/libdatafusion_jni.$extensionOsx")
61+
62+
def classifierLinux = 'linux-x86_64'
63+
def extensionLinux = 'so'
64+
def jniLibLinux = layout.buildDirectory.file("jni_libs/$classifierLinux/libdatafusion_jni.$extensionLinux")
65+
66+
task jarWithOsxLib(type: Jar) {
67+
from sourceSets.main.output
68+
from jniLibOsx
69+
rename "libdatafusion_jni.$extensionOsx", "jni_libs/libdatafusion_jni.$extensionOsx"
70+
archiveClassifier.set(classifierOsx)
71+
}
72+
73+
task jarWithLinuxLib(type: Jar) {
74+
from sourceSets.main.output
75+
from jniLibLinux
76+
rename "libdatafusion_jni.$extensionLinux", "jni_libs/libdatafusion_jni.$extensionLinux"
77+
archiveClassifier.set(classifierLinux)
78+
}
79+
80+
task jarWithLib(type: Jar) {
81+
from sourceSets.main.output
82+
from jniLibOsx
83+
rename "libdatafusion_jni.$extensionOsx", "jni_libs/libdatafusion_jni.$extensionOsx"
84+
from jniLibLinux
85+
rename "libdatafusion_jni.$extensionLinux", "jni_libs/libdatafusion_jni.$extensionLinux"
6586
}
6687

6788
publishing {
6889
publications {
69-
def artifactId = 'datafusion-java'
70-
if (System.getenv("CI") != null) {
71-
mavenJava(MavenPublication) {
72-
artifactId
73-
from(components.java)
74-
artifact getArtifact("so", "linux-x86_64")
75-
artifact getArtifact("dylib", "osx-x86_64")
76-
pom {
77-
name = 'DataFusion Java'
78-
description = 'A Java binding to Apache Arrow DataFusion library'
79-
url = 'https://github.com/datafusion-contrib/datafusion-java'
80-
licenses {
81-
license {
82-
name = 'The Apache License, Version 2.0'
83-
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
84-
}
85-
}
86-
developers {
87-
developer {
88-
id = 'dev'
89-
name = 'Apache Arrow Developers'
90-
91-
}
90+
mavenJava(MavenPublication) {
91+
artifactId 'datafusion-java'
92+
artifact sourcesJar
93+
artifact javadocJar
94+
artifact jarWithLib
95+
pom {
96+
name = 'DataFusion Java'
97+
description = 'A Java binding to Apache Arrow DataFusion library'
98+
url = 'https://github.com/datafusion-contrib/datafusion-java'
99+
licenses {
100+
license {
101+
name = 'The Apache License, Version 2.0'
102+
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
92103
}
93-
scm {
94-
connection = 'scm:git:[email protected]:datafusion-contrib/datafusion-java.git'
95-
developerConnection = 'scm:git:https://github.com/datafusion-contrib/datafusion-java.git'
96-
url = 'https://github.com/datafusion-contrib/datafusion-java'
104+
}
105+
developers {
106+
developer {
107+
id = 'dev'
108+
name = 'Apache Arrow Developers'
109+
97110
}
98111
}
99-
}
100-
} else {
101-
mavenJava(MavenPublication) {
102-
artifactId
103-
from(components.java)
104-
artifact getArtifact(getLibExtension(), osdetector.classifier)
105-
pom {
106-
name = 'DataFusion Java'
107-
description = 'A Java binding to Apache Arrow DataFusion library'
112+
scm {
113+
connection = 'scm:git:[email protected]:datafusion-contrib/datafusion-java.git'
114+
developerConnection = 'scm:git:https://github.com/datafusion-contrib/datafusion-java.git'
108115
url = 'https://github.com/datafusion-contrib/datafusion-java'
109-
licenses {
110-
license {
111-
name = 'The Apache License, Version 2.0'
112-
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
113-
}
114-
}
115-
developers {
116-
developer {
117-
id = 'dev'
118-
name = 'Apache Arrow Developers'
119-
120-
}
121-
}
122-
scm {
123-
connection = 'scm:git:[email protected]:datafusion-contrib/datafusion-java.git'
124-
developerConnection = 'scm:git:https://github.com/datafusion-contrib/datafusion-java.git'
125-
url = 'https://github.com/datafusion-contrib/datafusion-java'
126-
}
127116
}
128117
}
129118
}
130-
131119
}
132120
repositories {
133121
maven {
@@ -136,13 +124,24 @@ publishing {
136124
def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
137125
url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
138126
credentials {
139-
username = System.getenv("MAVEN_USERNAME") != null ? System.getenv("MAVEN_USERNAME") : findProperty('ossrhUsername')
140-
password = System.getenv("MAVEN_PASSWORD") != null ? System.getenv("MAVEN_PASSWORD") : findProperty('ossrhPassword')
127+
username = findProperty('ossrhUsername') ?: System.getenv("MAVEN_USERNAME")
128+
password = findProperty('ossrhPassword') ?: System.getenv("MAVEN_PASSWORD")
141129
}
142130
}
143131
}
144132
}
145133

134+
def artifacts = publishing.publications.mavenJava.artifacts
135+
136+
if (jniLibLinux.get().asFile.exists()) {
137+
artifacts.artifact jarWithLinuxLib
138+
}
139+
140+
if (jniLibOsx.get().asFile.exists()) {
141+
artifacts.artifact jarWithOsxLib
142+
}
143+
144+
146145
signing {
147146
required { !version.endsWith("SNAPSHOT") && gradle.taskGraph.hasTask("publish") }
148147
def signingKeyId = findProperty("signingKeyId")

0 commit comments

Comments
 (0)