Open Noodle05 opened 8 years ago
Fine to publish it, though that may not make it much easier to install/use because of e.g. #3. As far as I can tell, most Java package managers need special coaxing to handle JNI libraries and java.classpath correctly, so it can't simply be included in a pom like a normal Java library and expected to work. If you use Gradle, this approach seems useful: https://github.com/cjstehno/coffeaelectronica/wiki/Going-Native-with-Gradle.
Generally I'm not a huge Java/JVM language user. For this binding, I'll maintain the JNI/C parts of the repo, but am very much relying on the community to help out with packaging, etc. Happy to merge pull requests if you want to give it a shot.
I agree, maybe add JNI library (not libpostal.so) into jar file itself? so reduce one dependency?
That should work.
Just before jpostal was released I was reading about packaging the native lib as part of a jar and came across this blog post, which might be useful (Github repo: https://github.com/adamheinrich/native-utils).
Also possibly of interest are the Gradle docs on publishing custom artifacts: https://docs.gradle.org/current/userguide/publishing_maven.html#sec:publishing_custom_artifacts_to_maven
I've been uploading to our internal third-party maven repo.
It's a simple one-liner in the main directory after the gradle build:
mvn deploy:deploy-file -DgroupId=mapzen -DartifactId=jpostal -Dversion=1.0 -Dpackaging=jar -Dfile=./build/libs/jpostal.jar -DrepositoryId=<repoID> -Durl=<repoUrl>
You can can specify whatever groupId
, artifactId
, and version
you want but I think mapzen & jpostal make the most sense for the first 2.
Hi, would have been nice to get the link to that maven repo if its public :)
Since there hasn't been any activity here, and I was too bothered distributing the library alongside our application, I took up the chore of publishing it on Maven Central. You can find the package there:
https://central.sonatype.com/artifact/com.matchory.packages/jpostal
Since I don't have control of the mapzen.com domain, I took the liberty to rename the namespace to com.matchory.packages
; the code is unmodified otherwise, including the license document. I also added open venues as the original developer and pointed the SCM links to this repository. However, if any of the maintainers are unhappy with the publication, reach out to me via email (my first name, "moritz", below our company domain).
This is the final grade file required for publishing, adapted from the Dockerfile:
import org.gradle.internal.jvm.Jvm
plugins {
id 'c'
id 'java'
id 'java-library'
id 'application'
id 'signing'
id 'maven-publish'
}
group = 'com.matchory.packages'
version = '1.0.0'
repositories {
mavenCentral()
}
java {
withJavadocJar()
withSourcesJar()
}
sourceSets.main.java.srcDirs = ["src/main/java"]
sourceSets.test.java.srcDirs = ["src/test/java"]
model {
platforms {
x64 {
architecture "x86_64"
}
}
components {
jpostal(NativeLibrarySpec) {
binaries.all {
def jvmHome = org.gradle.internal.jvm.Jvm.current().javaHome
if (targetPlatform.operatingSystem.macOsX) {
cCompiler.args '-I', "${jvmHome}/include"
cCompiler.args '-I', "${jvmHome}/include/darwin"
cCompiler.args '-mmacosx-version-min=10.9'
linker.args '-mmacosx-version-min=10.9'
linker.args '-stdlib=libc++'
} else if (targetPlatform.operatingSystem.linux) {
cCompiler.args '-I', "${jvmHome}/include"
cCompiler.args '-I', "${jvmHome}/include/linux"
cCompiler.args '-D_FILE_OFFSET_BITS=64'
} else if (targetPlatform.operatingSystem.windows) {
cCompiler.args "-I${jvmHome}/include"
cCompiler.args "-I${jvmHome}/include/win32"
} else if (targetPlatform.operatingSystem.freeBSD) {
cCompiler.args '-I', "${jvmHome}/include"
cCompiler.args '-I', "${jvmHome}/include/freebsd"
}
linker.args '-lpostal' // Link with libpostal
}
}
}
}
classes.dependsOn 'jpostalSharedLibrary'
application {
applicationDefaultJvmArgs = ["-Djava.library.path=" + file("${buildDir}/libs/jpostal/shared").absolutePath]
}
dependencies {
testImplementation 'junit:junit:4.+'
}
tasks.withType(Test) {
systemProperty "java.library.path", file("${buildDir}/libs/jpostal/shared").absolutePath
}
artifacts {
archives javadocJar, sourcesJar
}
publishing {
publications {
mavenJava(MavenPublication) {
groupId = 'com.matchory.packages'
artifactId = 'jpostal'
version = '1.0.0'
from components.java
versionMapping {
usage('java-api') {
fromResolutionOf('runtimeClasspath')
}
usage('java-runtime') {
fromResolutionResult()
}
}
pom {
name = 'jpostal'
description = 'Java/JNI bindings to libpostal for fast international street address parsing/normalization'
url = 'https://github.com/openvenues/jpostal'
developers {
developer {
id = 'openvenues'
name = 'Open Venues'
url = 'https://github.com/openvenues'
}
}
licenses {
license {
name = 'MIT'
}
}
scm {
connection = 'scm:git:git://github.com/openvenues/libpostal.git'
developerConnection = 'scm:git:ssh://github.com/openvenues/libpostal.git'
url = 'https://github.com/openvenues/libpostal'
}
}
}
}
repositories {
maven {
name = 'com.matchory.packages.jpostal'
url = layout.buildDirectory.dir("repo")
}
}
}
signing {
sign configurations.archives
sign publishing.publications.mavenJava
}
javadoc {
if(JavaVersion.current().isJava9Compatible()) {
options.addBooleanOption('html5', true)
}
}
Currently jpostal released as source code, it's hard to use it in any project. Is it possible to make it available on central maven repository?