Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publishing custom artifacts that are built on multiple hosts #889

Open
Him188 opened this issue Dec 26, 2024 · 0 comments
Open

Publishing custom artifacts that are built on multiple hosts #889

Him188 opened this issue Dec 26, 2024 · 0 comments

Comments

@Him188
Copy link

Him188 commented Dec 26, 2024

Hi, thanks for your hard work!

TL;DR:

My request is, to add a EmptyPlatform or CustomPlatform where the plugin does not configure anything (e.g. components), but let myself setup the only artifacts needed.


Full story:

I'm trying to publish a Java library with JNI natives to Maven Central. It should support Android and desktop JVM ( mac/win/linux), so there will be .dll, .so files for each of the platfrom. Native libraries can only be built on the correct host OS, for example, .dylib can only be built on macOS.

I'm planning to publish the natives with classifiers:

mavenPublishing {
    configure(JavaLibrary(JavadocJar.Empty(), true))
    publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL)
    signAllPublications()
    // pom omitted
}

val nativeJar = tasks.register("nativeJar", Jar::class.java) {
    dependsOn(copyNativeFiles)
    group = "anitorrent"
    archiveClassifier.set(getOsTriple())
    from(copyNativeFiles.map { it.outputs.files.singleFile })
}

publishing {
    publications {
        getByName("maven", MavenPublication::class) {
            artifact(nativeJar)
        }
    }
}

The above works if I only support one single OS.

But I have to run the publishing for each host OS. Since they are all configured with JavaLibrary, they will publish the same .jar and .pom 3 times, resulting to conflicts on Maven Central.

Currently I see no option for the plugin to configure an 'EmptyPlatform' where I can publish only the nativeJar artifact on some OSes.


I've came up with a possible workround that is, to build the native libraries before any publishing logic. Gather the libraries onto one machine, and publish them together:

publishing {
    publications {
        getByName("maven", MavenPublication::class) {
            artifact(macOSArm64NativeJar)
            artifact(macOSX64NativeJar)
            artifact(windowsX64NativeJar)
            artifact(linuxX64NativeJar)
        }
    }
}

I haven't tried this yet. But I think it will be OK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant