Publish JNI Library
You can open this sample inside an IDE using the IntelliJ native importer or Eclipse Buildship. |
This sample shows how to publish a JNI library with Gradle to a binary repository. The library has no dependencies, and the build has a minimal configuration. If you are looking at publishing a JNI library with multiple target machines, see this other sample.
In this sample, we are publishing a JNI library implemented in Java and C++; however, this applies to other JVM and native languages as well.
build.gradle
plugins {
id 'java'
id 'dev.nokee.jni-library'
id 'dev.nokee.cpp-language'
id 'maven-publish'
}
group = 'com.example.greeter'
version = '4.2'
publishing {
publications {
jniLibrary(MavenPublication) {
from components.java
}
}
repositories {
maven {
url = "${buildDir}/publishing-repository"
}
}
}
build.gradle.kts
plugins {
id("java")
id("dev.nokee.jni-library")
id("dev.nokee.cpp-language")
id("maven-publish")
}
group = "com.example.greeter"
version = "4.2"
publishing {
publications {
create<MavenPublication>("jniLibrary") {
from(components.getByName("java"))
}
}
repositories {
maven {
url = uri("${buildDir}/publishing-repository")
}
}
}
To publish the library:
$ ./gradlew publish BUILD SUCCESSFUL 7 actionable tasks: 7 executed $ tree ./build/publishing-repository ./build/publishing-repository └── com └── example └── greeter └── publish-jni-library ├── 4.2 │ ├── publish-jni-library-4.2.jar │ ├── publish-jni-library-4.2.jar.md5 │ ├── publish-jni-library-4.2.jar.sha1 │ ├── publish-jni-library-4.2.jar.sha256 │ ├── publish-jni-library-4.2.jar.sha512 │ ├── publish-jni-library-4.2.module │ ├── publish-jni-library-4.2.module.md5 │ ├── publish-jni-library-4.2.module.sha1 │ ├── publish-jni-library-4.2.module.sha256 │ ├── publish-jni-library-4.2.module.sha512 │ ├── publish-jni-library-4.2.pom │ ├── publish-jni-library-4.2.pom.md5 │ ├── publish-jni-library-4.2.pom.sha1 │ ├── publish-jni-library-4.2.pom.sha256 │ └── publish-jni-library-4.2.pom.sha512 ├── maven-metadata.xml ├── maven-metadata.xml.md5 ├── maven-metadata.xml.sha1 ├── maven-metadata.xml.sha256 └── maven-metadata.xml.sha512 5 directories, 20 files
For more information, see JNI Library Plugin and Maven Publish Plugin reference chapters.