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

Working example with kotlin-multiplatform #1

Open
avwie opened this issue Dec 4, 2019 · 5 comments
Open

Working example with kotlin-multiplatform #1

avwie opened this issue Dec 4, 2019 · 5 comments

Comments

@avwie
Copy link

avwie commented Dec 4, 2019

Is it possible to generate a working example with kotlin-multiplatform project? Preferably with a build.gradle.kts file.

I've tried a lot of different ways to make it work, but I can not get ts-defs from commonMain.

@ayedo
Copy link
Owner

ayedo commented Dec 4, 2019

Hi avwie,

I'm not sure I understand your use case. If you are using Kotlin multi-platform doesn't the Kotlin compiler already generate JavaScript for you?

This plugin is meant to be used together with a TypeScript based frontend (for example, an angular based UI), so that you do not have to rewrite your definitions on the backend, and frontend. It's like a 'Swagger lite' kind of tool.

@avwie
Copy link
Author

avwie commented Dec 4, 2019

Hi ayedo,

you are exactly right. I generate a JS common library which I use in the frontend. As I use Typescript in my frontend I would really like Typescript definitions and I came upon your project.

However, when using the kotlin-multiplatform plugin as described here I run into problems because I am unable to run it alongside with your plugin:
https://kotlinlang.org/docs/tutorials/mpp/multiplatform-library.html

I think I lack in gradle experience, because I can't get your Gradle plugin to work. Because with the multiplatform plugin the buildscript part shouldn't be used anymore.

@ayedo
Copy link
Owner

ayedo commented Dec 6, 2019

OK. Do you get an exception, or some message in the console?

The plugin depends on a library that is not published on Maven-Central, and therefore the buildscript part is absolutely required. Gradle plugins are not built as fat JARs, and by default only Maven-Central artifacts are supported as dependencies.

A future version of the plugin might bundle the dependencies as a fat JAR, so that the buildscript part won't be required any more.

@itslenny
Copy link

itslenny commented Dec 6, 2019

@ayedo

I'm having (maybe) a similar problem. Maybe some of what I've seen will shed some light on this.

I'm also doing a mutlti-platform app, but I'm not doing JS. Just Android and iOS. I have some typedefs that I want to share from kotlin to a webview.

I originally used the default typescriptGenerator { } specified in your readme. I only updated packageName to use the correct package name for my project.

My project is an android app, and has a second module that contains the files I want to create typedefs from. The main module is called "app" (default in android studio). The module I want is called "WebViewEventProxy"

When I ran it with the default settings it ran without issue, but created an empty d.ts file because it didn't see my files.

when I log getProject().sourceSets.main.runtimeClasspath it is:

.../android/build/classes/java/main
.../android/build/resources/main
~/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-script-runtime/1.3.60/eb1f56fb1b58a8dc481a6e5beeb73931d80d08be/kotlin-script-runtime-1.3.60.jar

If I manually set the class path to:

classPath = layout.files([project.projectDir.toPath().resolve("WebViewEventProxy/build/classes/kotlin/android/main")])

It seems to run and find my files, but it fails because it can't find a class.

@avwie this might fix your issue.

This seems to work, but is there a more correct way in gradle to get this module path (other than hard coding it)?


The other issue I'm having I think has to do with using the kotlinx serialize which uses reflection.

Is there a way to tell it to ignore that or do I need to include the plugin in some way?

This is the error I receive:

Execution failed for task ':generateTypescriptDefinitions'.
> kotlinx/serialization/internal/GeneratedSerializer

The class it's failing to create typedefs for looks like this:

import kotlinx.serialization.*

@Serializable
data class ClientInitProxyEvent(
    val clientBuild: String,
    override val eventId: String? = null,
    override val type: String? = null
): ProxyEvent { }

I also tried adding:

typeMappings = [
  "kotlinx.serialization.internal.GeneratedSerializer": "any"
]

but then I get the errror

java.lang.ClassNotFoundException: kotlinx.serialization.internal.GeneratedSerializer

thanks in advance for any help.

@ayedo
Copy link
Owner

ayedo commented Jan 8, 2020

thanks for your detailed description, but without reproduction it's kind of difficult to pinpoint the problem. Do you have a public repository, or a minimal project which I could look into?

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

3 participants