https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
e

Edouard Goossens

02/04/2019, 2:35 PM
Hi! Is it possible to publish multiplatform libraries (with GRADLE_METADATA enabled) to JitPack? If I understand correctly, JitPack relies on the build task, which doesn’t produce the .module files... Is there a way to get around this? Thanks!
h

h0tk3y

02/04/2019, 2:56 PM
In the JitPack docs, https://jitpack.io/docs/BUILDING/, they say:
With maven-publishing plugin it will run
./gradlew build publishToMavenLocal
So I think it should include the
*.module
files, too. Does it not?
I believe they expose the contents of the local Maven repo after the build.
e

Edouard Goossens

02/04/2019, 3:26 PM
I played with the publishing settings and you’re right it seems the files are present. I’m now getting errors of the type: Required org.jetbrains.kotlin.platform.type ‘js’ and found incompatible value ‘jvm’. I’m still investigating but maybe you can point me in the right direction?
h

h0tk3y

02/04/2019, 3:30 PM
This particular statement says that the consumer wants a JS artifact and the producer's variant is a JVM one. So if it says so for each configuration, then it didn't find the JS target's variant (does your library have a JS variant? do you specify a dependency on the library 'root' module, not the JVM one?). Gradle usually prints a big and detailed error output listing all of the candidate variants explaining why each didn't match. Could you please share that?
e

Edouard Goossens

02/04/2019, 3:34 PM
./gradlew build --refresh-dependencies
Configure project :
Kotlin Multiplatform Projects are an experimental feature.
Task :compileKotlinJs FAILED
FAILURE: Build failed with an exception. * What went wrong: Execution failed for task ‘:compileKotlinJs’.
Could not resolve all files for configuration ‘:jsCompileClasspath’.
> Could not resolve com.github.egoossens.firestore-kotlin-mppbuild jvm3c94011c06. Required by: project : > com.github.egoossensfirestore kotlin mpp3c94011c06 > Unable to find a matching variant of com.github.egoossens.firestore-kotlin-mppbuild jvm3c94011c06: - Variant ‘jvm-api’: - Found artifactType ‘jar’ but wasn’t required. - Found org.gradle.status ‘release’ but wasn’t required. - Required org.gradle.usage ‘kotlin-api’ and found compatible value ‘java-api’. - Required org.jetbrains.kotlin.platform.type ‘js’ and found incompatible value ‘jvm’. - Variant ‘jvm-runtime’: - Found artifactType ‘jar’ but wasn’t required. - Found org.gradle.status ‘release’ but wasn’t required. - Required org.gradle.usage ‘kotlin-api’ and found compatible value ‘java-runtime-jars’. - Required org.jetbrains.kotlin.platform.type ‘js’ and found incompatible value ‘jvm’. - Variant ‘metadata-api’: - Found artifactType ‘jar’ but wasn’t required. - Found org.gradle.status ‘release’ but wasn’t required. - Required org.gradle.usage ‘kotlin-api’ and found compatible value ‘kotlin-api’. - Required org.jetbrains.kotlin.platform.type ‘js’ and found incompatible value ‘common’. > Could not resolve com.github.egoossens.firestore-kotlin-mppbuild metadata3c94011c06. Required by: project : > com.github.egoossensfirestore kotlin mpp3c94011c06 > Unable to find a matching variant of com.github.egoossens.firestore-kotlin-mppbuild metadata3c94011c06: Variant ‘metadata-api’: - Found artifactType ‘jar’ but wasn’t required. - Found org.gradle.status ‘release’ but wasn’t required. - Required org.gradle.usage ‘kotlin-api’ and found compatible value ‘kotlin-api’. - Required org.jetbrains.kotlin.platform.type ‘js’ and found incompatible value ‘common’. * Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights. * Get more help at https://help.gradle.org
This is the firestore-kotlin-mpp-0.1.0.module file. It seems to reference js variants correctly though... but I’m pretty new to this so I might be missing something
h

h0tk3y

02/04/2019, 3:39 PM
So do you explicitly declare a dependency on
com.github.egoossens.firestore-kotlin-mpp:build-jvm:3c94011c06
and
com.github.egoossens.firestore-kotlin-mpp:build-metadata:3c94011c06
? This is what the log looks like: it says Gradle tried to resolve a dependency on
com.github.egoossens.firestore-kotlin-mpp:build-jvm:...
for a JS consumer (
jsCompileClasspath
), which failed quite as expected. Did you try to replace them with a single dependency on
com.tastyelectrons.firestore-kotlin-mpp:build:...
?
The
Build artifacts: ...
part of the JitPack output tells me the library must have published correctly, with
com.github.egoossens.firestore-kotlin-mpp:build:3c94011c06
being the 'root' module's coordinates. This is the module which you should specify as a dependency, so that Gradle will choose one of its variant for each of the platforms.
e

Edouard Goossens

02/04/2019, 3:43 PM
hmm could there be a clash in my versioning? The .module file is referencing 0.1.0 but I’m using commit hashes on JitPack
h

h0tk3y

02/04/2019, 3:45 PM
Not sure if this kind of mismatch can influence anything at all; since Gradle found and listed the library's variants, it didn't object to the version in metadata not matching the Maven module version.
e

Edouard Goossens

02/04/2019, 3:47 PM
To answer your previous question, I’m only referencing the dependency in commonMain (not in the platform source sets). Note that I’m using the new MPP format with platform specific source sets instead of modules.
h

h0tk3y

02/04/2019, 3:50 PM
Then your dependency declaration should like like this:
Copy code
commonMain {
    dependencies {
        implementation 'com.github.egoossens.firestore-kotlin-mpp:build:3c94011c06'
    }
}
Note that it references the module named
build
with no platform suffix (not
build-jvm
or
build-js
). The dependency kind,
api
or
implementation
, doesn't make difference, both should work.
e

Edouard Goossens

02/04/2019, 3:52 PM
yeah I think this was part of the problem. I tried that and I’m now getting Could not find com.tastyelectrons.firestore-kotlin-mppbuild js0.1.0. which I think comes from the version mismatch
The thing is, as I’m using a commit hash as a version, I don’t know it before I commit to github... so I can’t set it in build.gradle. Do you think there’s a way around that or I should use a pre-determined version and have a corresponding release on github?
h

h0tk3y

02/04/2019, 3:54 PM
Yeah maybe I'm starting to understand why:
The root module's Gradle metadata (https://jitpack.io/com/github/egoossens/firestore-kotlin-mpp/build/3c94011c06/build-3c94011c06.module) says:
Copy code
{
      "name": "js-api",
      "attributes": {
        "artifactType": "jar",
        "org.gradle.usage": "kotlin-api",
        "org.jetbrains.kotlin.platform.type": "js"
      },
      "available-at": {
        "url": "../../build-js/0.1.0/build-js-0.1.0.module",
        "group": "com.tastyelectrons.firestore-kotlin-mpp",
        "module": "build-js",
        "version": "0.1.0"
      }
    },
The
available-at
part is a hint for Gradle on where to look for the platform module, and here, it clearly doesn't match the repository layout.
As a workaround, you might use JitPack build from Github tags rather than commits, so that you can control the version.
e

Edouard Goossens

02/04/2019, 3:56 PM
Let me try that and see what happens
h

h0tk3y

02/04/2019, 3:58 PM
I'm not sure whether JitPack passes the version into the build somehow – if it does, you could also set the project's version from the commit ID and make those match.
Here in the Build environment part (https://jitpack.io/docs/BUILDING/#build-environment) they say:
Each build will have these environment variables:
...
And the following project specific environment variables:
* VERSION=<version being built> # A tag or commit
So I guess you may set the project version as follows:
Copy code
version = System.getenv("VERSION")
This should solve the versions mismatch.
e

Edouard Goossens

02/04/2019, 4:05 PM
cool, let me try that instead
We’re making progress, but now I think my group is the problem... I set it as
Copy code
group = "com.tastyelectrons.firestore-kotlin-mpp"
but my JitPack urls use com/github/egoossens...
h

h0tk3y

02/04/2019, 4:17 PM
Does it lead to the same error, Could not find com.tastyelectrons.firestore-kotlin-mppbuild js0.1.0?
e

Edouard Goossens

02/04/2019, 4:17 PM
Similar yeah except the version is correct now
It’s looking for
Copy code
<https://jitpack.io/com/tastyelectrons/firestore-kotlin-mpp/build-js/4bf33d302c/build-js-4bf33d302c.module>
but the file is at
Copy code
<https://jitpack.io/com/github/egoossens/firestore-kotlin-mpp/build-js/4bf33d302c/build-js-4bf33d302c.module>
h

h0tk3y

02/04/2019, 4:20 PM
I see. If publishing under the group ID chosen by JitPack is fine with you, then you may set the project's group in a similar way.
e

Edouard Goossens

02/04/2019, 4:20 PM
yeah I don’t mind... but I’m curious if there’s a way around that?
h

h0tk3y

02/04/2019, 4:26 PM
I believe Gradle relies on the module metadata of the variant written in the 'root' module's publication (https://jitpack.io/com/github/egoossens/firestore-kotlin-mpp/build/4bf33d302c/build-4bf33d302c.module), which points it to the incorrect Maven coordinates, see the
available-at
part:
Copy code
{
      "name": "js-api",
      "attributes": {
        "artifactType": "jar",
        "org.gradle.usage": "kotlin-api",
        "org.jetbrains.kotlin.platform.type": "js"
      },
      "available-at": {
        "url": "../../build-js/4bf33d302c/build-js-4bf33d302c.module",
        "group": "com.tastyelectrons.firestore-kotlin-mpp",
        "module": "build-js",
        "version": "4bf33d302c"
      }
    },
Maybe they must always match. I personally didn't try to publish a module under mismatching Maven coordinates, so thanks for sharing your experience, that definitely needs to be taken into consideration.
I don't know if there's a way to force JitPack to use your preferred group ID.
e

Edouard Goossens

02/04/2019, 4:29 PM
h

h0tk3y

02/04/2019, 4:30 PM
Yes it seems so.
e

Edouard Goossens

02/04/2019, 4:43 PM
Anyway I think the dependency problem is solved 🙂 Thanks a lot for your time, I really appreciate it!
h

h0tk3y

02/04/2019, 4:43 PM
You're welcome.
5 Views