jitpack.io icon indicating copy to clipboard operation
jitpack.io copied to clipboard

Add ability to build and publish Kotlin Multiplatform Libraries

Open arkivanov opened this issue 6 years ago • 111 comments

Is your feature request related to a problem? Please describe. We are playing with Kotlin Multiplatform projects at the moment and publishing our artifacts via JitPack. But JitPack builds only on Linux so we can't build some Native targets (e.g. iOS), as it requires macos host. Taking into account that Github Package Registry is coming, I think it would be nice to add macos host to JitPack.

Describe the solution you'd like Add ability to publish Kotlin Multiplatform libraries with Native targets

Describe alternatives you've considered Manual publishing to JCenter, signed up for Github Package Registry beta

Additional context Travis can be configured to build on multiple hosts, perhaps same technique could be used

arkivanov avatar May 26 '19 20:05 arkivanov

Hi,

That's an interesting suggestion, thank you! Would it be enough to build your whole project on macos or do you require some parts built on Linux?

jitpack-io avatar Jun 06 '19 15:06 jitpack-io

At the moment we are targeting JVM, iOS and Linux so Macos would work for us as it can build all our targets. But other people might be interested in Windows and it requires Windows host. So first iteration might be to just allow selection between Linux and Macos (we would just select Macos). Second iteration might be to allow partial selection.

arkivanov avatar Jun 06 '19 16:06 arkivanov

I'll second this. We're investing heavily in Kotlin multi-platform libraries that are published for use on Android and the JVM, but we'll be publishing them for iOS soon, too.

mtrewartha avatar Jul 31 '19 18:07 mtrewartha

Hi,

We've added preliminary support for Kotlin MPP libraries. In particular we now handle Gradle metadata (.module) in our Linux builds.

jitpack-io avatar Apr 26 '20 09:04 jitpack-io

Hi @jitpack-io,

Do you have a sample build.gradle for this Kotlin MPP support? I couldn't find any in your existing repositories.

Thanks!

yslvlln avatar May 18 '20 02:05 yslvlln

@yslvlln Here are some KMP projects: https://github.com/badoo/Reaktive - this one uses regular Groovy Gradle scripts https://github.com/arkivanov/MVIKotlin - this one uses Kotlin Gradle scripts

Hope this helps

arkivanov avatar May 18 '20 12:05 arkivanov

Will look into this. Thanks a lot @arkivanov!

yslvlln avatar May 18 '20 12:05 yslvlln

@yslvlln Recently KMP evolved a bit so might be worth another look. Setting this up got a lot easier. Basically the multiplatform plugin has out of the box support for publish. There have been a few changes to the meta data part and how gradle handles this. E.g. It is able to figure out for a js project to depend on the -js variant.

I have a simple project that I'm trying to publish via jitpack currently. Currently it half works in the sense that I can publish but not depend on the dependencies.

The project is: https://github.com/jillesvangurp/geogeometry & https://jitpack.io/#jillesvangurp/geogeometry

Release 3.1.4 for this was a kotlin multi platform build. See logs + build file in this gist: https://gist.github.com/jillesvangurp/8b1d8bcfa930a0f1a419a11f33462c74

This initially looks like it works. But when I try to depend on the -jvm jar in a different project, I get a 401 from jitpack:

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':compileKotlin'.
> Could not resolve all files for configuration ':compileClasspath'.
   > Could not resolve com.github.jillesvangurp:geogeometry-jvm:v3.1.4.
     Required by:
         project :
      > Could not resolve com.github.jillesvangurp:geogeometry-jvm:v3.1.4.
         > Could not get resource 'https://jitpack.io/com/github/jillesvangurp/geogeometry-jvm/v3.1.4/geogeometry-jvm-v3.1.4.pom'.
            > Could not GET 'https://jitpack.io/com/github/jillesvangurp/geogeometry-jvm/v3.1.4/geogeometry-jvm-v3.1.4.pom'. Received status code 401 from server: Unauthorized

I've also tried depending both:

    implementation("com.github.jillesvangurp:geogeometry-jvm:v3.1.4")

or

    implementation("com.github.jillesvangurp:geogeometry:v3.1.4")

For a different project I use a google storage bucket as a poor man's gradle repository and there it works as it should. So, I know my build file is OK. To me it looks like either files are missing/not uploaded or access to those files is somehow not allowed. Since it seems to be close to working; it might be worth getting this over the finishing line.

KMP is about to be more important now that Kotlin 1.4 is out so fixing this would be really nice. I have several libraries that are probably going to be multi-platform soon.

jillesvangurp avatar Aug 24 '20 15:08 jillesvangurp

Note, for the project above I have now switched to rsyncing a local file repository to my website. This seems to work fine. So the issue is definitely with how jitpack handles the generated artifacts as the exact same artifacts when uploaded unmodified to a website seem to work fine.

jillesvangurp avatar Aug 25 '20 02:08 jillesvangurp

Hello, is there any news on this? It would be super nice to be able to use Jitpack with KMM projects reliably, especially now that they've officially reached alpha (and hopefully won't make significant changes over time).

Zhuinden avatar Oct 16 '20 23:10 Zhuinden

Hey @jitpack-io, any updates 1.5 years after the creation of this issue? 🙂

petersamokhin avatar Nov 25 '20 23:11 petersamokhin

Would really love to see this @jitpack-io

ligi avatar Jan 14 '21 16:01 ligi

Since Jcenter and Bintray are shutting down, it would be really cool to have Jitpack working with Kotlin Multiplatform!

arkivanov avatar Feb 03 '21 22:02 arkivanov

@arkivanov It's almost available for Kotlin Multiplatform. For a multi-module project, the artifacts are published under com.github.USER.REPO:MODULE:VERSION now. And version id is provided through project property.

Let's take https://github.com/ArcticLampyrid/KtJsonRpcPeer as an example You can find the following in log

Running: ./gradlew clean -Pgroup=com.github.ArcticLampyrid -Pversion=master-9459df002c-1 build publishToMavenLocal

We can see that group is wrong (it's in a format for single-module project, but KPP is always a multi module project) but version is correct. Then let's overwrite group in build script but keep version as it is.

group = "com.github.ArcticLampyrid.KtJsonRpcPeer"
if (version.toString() == "unspecified") {
    version = "0.7.0" // set if version is not provided (impossible for JitPack)
}

Finally kotlin should generate the correct metadata.

ArcticLampyrid avatar Feb 10 '21 11:02 ArcticLampyrid

the issue seems to be that for some reason the publishToLocalMaven task doesn't output the multiplatform files:

image

but the publish task does:

image

my solution was to just make the publish task output to local maven:

configure<PublishingExtension> {
    publications {
        // ...
    }
    repositories {
        maven("file://${System.getenv("HOME")}/.m2/repository")
    }
}

but that doesn't help because jitpack runs publishToLocalMaven, not publish. so let's fix that in the jitpack.yml:

install:
  - ./gradlew publish

jitpack should now publish all of the necessary files. if anyone is curious here's the projct where i got it (mostly) working

DetachHead avatar Apr 08 '21 18:04 DetachHead

publishToLocalMaven usually works just fine, used it quite a lot with the maven-publish plugin.

arkivanov avatar Apr 08 '21 19:04 arkivanov

@DetachHead publishToLocalMaven works fine for me with Kotlin multiplatform libraries

ArcticLampyrid avatar Apr 09 '21 14:04 ArcticLampyrid

care to share your config? been tearing my hair out at this for the last few days.

here's mine, it's full of dirty hacks because none of it worked out of the box for me.no idea what i'm doing wrong

DetachHead avatar Apr 09 '21 15:04 DetachHead

lcurl missing error when building KMP with linuxX64 target https://github.com/jitpack/jitpack.io/issues/4523

Shabinder avatar Apr 18 '21 09:04 Shabinder

Any progress on this? I'd absolutely love to be able to publish KMM libraries on Github without the headache of a typical maven publish.

Also for anyone who stumbles across this... I found this great way to self host maven repos. I was super discouraged by the difficulty of hosting on maven central and others... so I came across this, and it's by far the easiest solution I've seen for hosting KMM libraries. Also, you can run it very easily from Docker on something like Digital Ocean. Took me about 5 minutes to configure.

alexwhb avatar Sep 20 '21 23:09 alexwhb

As of Kotlin 1.6.0, Windows targets can be compiled on any host: https://kotlinlang.org/docs/whatsnew16.html#compilation-of-windows-targets-on-any-host

In particular, that means that if JitPack could be configured to run builds on a macOS host, then that single host should be able to compile all necessary native targets for multiplatform projects with Kotlin 1.6.0 and beyond.

alexvanyo avatar Nov 19 '21 21:11 alexvanyo

@jitpack-io Any updates? 😇 🤞

theapache64 avatar Feb 05 '22 14:02 theapache64

I'm a little bit surprised this hasn't gotten more attention.

kierans avatar Apr 13 '22 00:04 kierans

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Sep 16 '22 02:09 github-actions[bot]

Not stale.

ArcticLampyrid avatar Sep 16 '22 02:09 ArcticLampyrid

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Oct 18 '22 02:10 github-actions[bot]

dismissing the objection ☝️

mariuszmarzec avatar Oct 18 '22 07:10 mariuszmarzec

What is blocking this? Is this a resource problem? Would it be feasible to donate to this effort somehow if that helps?

stefanhaustein avatar Nov 05 '22 14:11 stefanhaustein

Does KMP support now? I've been doing this for a long time, But I never did it well

https://github.com/ltttttttttttt/ComposeViews

Prompt when importing:

:common:desktopMain: Could not resolve com.github.ltttttttttttt.ComposeViews:compose_views-android:1.3.2.7.test_kmp.
Required by:
    project :common > com.github.ltttttttttttt:ComposeViews:1.3.2.7.test_kmp

:common:commonMain: Could not resolve com.github.ltttttttttttt.ComposeViews:compose_views-android:1.3.2.7.test_kmp.
Required by:
    project :common > com.github.ltttttttttttt:ComposeViews:1.3.2.7.test_kmp

Prompt at runtime:

Execution failed for task ':common:compileKotlinDesktop'.
> Error while evaluating property 'filteredArgumentsMap' of task ':common:compileKotlinDesktop'
   > Could not resolve all files for configuration ':common:desktopCompileClasspath'.
      > Could not resolve com.github.ltttttttttttt.ComposeViews:compose_views-android:1.3.2.7.test_kmp.
        Required by:
            project :common > com.github.ltttttttttttt:ComposeViews:1.3.2.7.test_kmp
         > No matching variant of com.github.ltttttttttttt.ComposeViews:compose_views-android:1.3.2.7.test_kmp was found. The consumer was configured to find an API of a library, preferably optimized for standard JVMs, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm' but:
             - Variant 'releaseApiElements-published' capability com.github.ltttttttttttt.ComposeViews:compose_views-android:1.3.2.7.test_kmp declares an API of a library:
                 - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm'
                 - Other compatible attribute:
                     - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)
             - Variant 'releaseRuntimeElements-published' capability com.github.ltttttttttttt.ComposeViews:compose_views-android:1.3.2.7.test_kmp declares a runtime of a library:
                 - Incompatible because this component declares a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'androidJvm' and the consumer needed a component, as well as attribute 'org.jetbrains.kotlin.platform.type' with value 'jvm'
                 - Other compatible attribute:
                     - Doesn't say anything about its target Java environment (preferred optimized for standard JVMs)

ltttttttttttt avatar Nov 26 '22 10:11 ltttttttttttt

@ltttttttttttt On the first glance, it appears that you compile common against jvm target. And common depends on com.github.ltttttttttttt.ComposeViews:compose_views-android, which is only for android. jvm targets can't have android dependencies.

arkivanov avatar Nov 27 '22 18:11 arkivanov