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 multiple target machines with Gradle to a binary repository. The library has no dependencies, and the build has a minimal configuration.

In this sample, we are publishing a JNI library with multiple machines 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'
	id 'dev.nokee.samples.jni-library-publish'
}

group = 'com.example.greeter'
version = '4.2'

library {
	targetMachines = [
		machines.windows.x86_64,
		machines.macOS.x86_64,
		machines.linux.x86_64
	]
}

afterEvaluate {
	publishing {
		publications {
			jniLibrary(MavenPublication) {
				from components.jni
				artifactId = project.name
			}
			jniLibraryMacos(MavenPublication) {
				from components.getByName('jniMacos')
				artifactId = "${project.name}-macos"
			}
			jniLibraryLinux(MavenPublication) {
				from components.jniLinux
				artifactId = "${project.name}-linux"
			}
			jniLibraryWindows(MavenPublication) {
				from components.jniWindows
				artifactId = "${project.name}-windows"
			}
		}
		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")
	id("dev.nokee.samples.jni-library-publish")
}

group = "com.example.greeter"
version = "4.2"

library {
	targetMachines.set(listOf(
		machines.windows.x86_64,
		machines.macOS.x86_64,
		machines.linux.x86_64
	))
}


afterEvaluate {
	publishing {
		publications {
			create<MavenPublication>("jniLibrary") {
				from(components.getByName("jni"))
				artifactId = project.name
			}
			create<MavenPublication>("jniLibraryMacos") {
				from(components.getByName("jniMacos"))
				artifactId = "${project.name}-macos"
			}
			create<MavenPublication>("jniLibraryLinux") {
				from(components.getByName("jniLinux"))
				artifactId = "${project.name}-linux"
			}
			create<MavenPublication>("jniLibraryWindows") {
				from(components.getByName("jniWindows"))
				artifactId = "${project.name}-windows"
			}
		}
		repositories {
			maven {
				url = uri("${buildDir}/publishing-repository")
			}
		}
	}
}

To publish the library:

$ ./gradlew publishJniLibraryPublicationToMavenRepository publishJniLibraryMacosPublicationToMavenRepository

BUILD SUCCESSFUL
11 actionable tasks: 11 executed
$ tree ./build/publishing-repository
./build/publishing-repository
└── com
    └── example
        └── greeter
            ├── publish-jni-library-with-target-machines
            │   ├── 4.2
            │   │   ├── publish-jni-library-with-target-machines-4.2.jar
            │   │   ├── publish-jni-library-with-target-machines-4.2.jar.md5
            │   │   ├── publish-jni-library-with-target-machines-4.2.jar.sha1
            │   │   ├── publish-jni-library-with-target-machines-4.2.jar.sha256
            │   │   ├── publish-jni-library-with-target-machines-4.2.jar.sha512
            │   │   ├── publish-jni-library-with-target-machines-4.2.module
            │   │   ├── publish-jni-library-with-target-machines-4.2.module.md5
            │   │   ├── publish-jni-library-with-target-machines-4.2.module.sha1
            │   │   ├── publish-jni-library-with-target-machines-4.2.module.sha256
            │   │   ├── publish-jni-library-with-target-machines-4.2.module.sha512
            │   │   ├── publish-jni-library-with-target-machines-4.2.pom
            │   │   ├── publish-jni-library-with-target-machines-4.2.pom.md5
            │   │   ├── publish-jni-library-with-target-machines-4.2.pom.sha1
            │   │   ├── publish-jni-library-with-target-machines-4.2.pom.sha256
            │   │   └── publish-jni-library-with-target-machines-4.2.pom.sha512
            │   ├── maven-metadata.xml
            │   ├── maven-metadata.xml.md5
            │   ├── maven-metadata.xml.sha1
            │   ├── maven-metadata.xml.sha256
            │   └── maven-metadata.xml.sha512
            └── publish-jni-library-with-target-machines-macos
                ├── 4.2
                │   ├── publish-jni-library-with-target-machines-macos-4.2.jar
                │   ├── publish-jni-library-with-target-machines-macos-4.2.jar.md5
                │   ├── publish-jni-library-with-target-machines-macos-4.2.jar.sha1
                │   ├── publish-jni-library-with-target-machines-macos-4.2.jar.sha256
                │   ├── publish-jni-library-with-target-machines-macos-4.2.jar.sha512
                │   ├── publish-jni-library-with-target-machines-macos-4.2.module
                │   ├── publish-jni-library-with-target-machines-macos-4.2.module.md5
                │   ├── publish-jni-library-with-target-machines-macos-4.2.module.sha1
                │   ├── publish-jni-library-with-target-machines-macos-4.2.module.sha256
                │   ├── publish-jni-library-with-target-machines-macos-4.2.module.sha512
                │   ├── publish-jni-library-with-target-machines-macos-4.2.pom
                │   ├── publish-jni-library-with-target-machines-macos-4.2.pom.md5
                │   ├── publish-jni-library-with-target-machines-macos-4.2.pom.sha1
                │   ├── publish-jni-library-with-target-machines-macos-4.2.pom.sha256
                │   └── publish-jni-library-with-target-machines-macos-4.2.pom.sha512
                ├── maven-metadata.xml
                ├── maven-metadata.xml.md5
                ├── maven-metadata.xml.sha1
                ├── maven-metadata.xml.sha256
                └── maven-metadata.xml.sha512

7 directories, 40 files
The other publish tasks will need to be called on each platform that can build the JNI library.

For more information, see JNI Library Plugin and Maven Publish Plugin reference chapters.