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

Draft: Introduce basic Kotlin MPP project layout #77

Merged
merged 6 commits into from
Mar 22, 2021

Conversation

TheTeXnician
Copy link
Contributor

This PR tries to tackle the ROADMAP item of introducing MPP project layout. It does not do much more than renaming. I have run the tests but did not do much more. Some aspects that I have not refactored which will need refactoring:

  • publishing: Kotlin MPP has to be published using multiple artifacts. Look at https://kotlinlang.org/docs/reference/mpp-publish-lib.html for a short introduction. However, I have not been able to get through all of the publication code.
  • sources: Kotlin MPP produces sources JARs in the publication process (cf. link above). The current code using source set main does not work as that source set is empty.
  • javadoc: This project produces a javadoc JAR but as I have not seen javadoc annotations, I have not done anything there. Currently, the javadocJAR is as empty as the sourcesJAR. If there were documentation comments I would recommend moving to dokka and using the output of the dokkaJavadoc task.
  • snakeYaml: This project (obviously) needs snakeYaml which is needed for the core components. One would probably rewrite those using expect and actual classes and use other serialization libraries based on the platform.

So, please see this as a starter in the direction of making kaml a MPP. If the publication code would be fixed, one could apply this layout to a JVM-only library as well until there is enough time for making it really platform-independent.

@TheTeXnician TheTeXnician changed the title Introduce basic Kotlin MPP project layout Draft: Introduce basic Kotlin MPP project layout Jan 3, 2021
Copy link
Owner

@charleskorn charleskorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @TheTeXnician! This looks good to me. I've added a couple of comments on the Gradle configuration that I'm not sure about.

Also, is there a reason why some of the test files (YamlNodeReaderTest, YamlReadingTest and YamlWritingTest) are in jvmTest rather than commonTest?

In terms of the remaining work, I think you're correct in your assessment that the main thing is to get the publishing code working before this can be merged. Is that something you're willing to look into?

build.gradle.kts Outdated

apply { id("com.github.ben-manes.versions") version "0.36.0" }
kotlin("multiplatform") version "1.4.10"
id("org.jetbrains.kotlin.plugin.serialization") version "1.4.10"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know I wasn't using it before, but it might be good to switch to the kotlin("plugin.serialization") method here as well, as described in the kotlinx.serialization readme.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Of course it should.

}
val jvmMain by getting {
dependencies {
implementation(project.dependencies.platform("org.jetbrains.kotlin:kotlin-bom"))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be applied to kotlinMain?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't know what's kotlinMain. The source sets are named like the targets (i.e. js, jvm, common, linuxX64, …) where there is no kotlin target. As per this forum post it seems that the platform is nothing that's even supposed to be used in Kotlin/MPP (maybe yet). So this seems to be the currently most viable workaround.

build.gradle.kts Outdated
implementation(project.dependencies.platform("org.jetbrains.kotlin:kotlin-bom"))
implementation(kotlin("stdlib-jdk8"))
implementation("org.snakeyaml:snakeyaml-engine:${Versions.snakeYaml}")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-core:${Versions.serialization}")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be applied again if it's already in commonMain?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another good catch. It does not. jvmMain depends on commonMain automatically.

val jvmTest by getting {
dependencies {
implementation("org.spekframework.spek2:spek-dsl-jvm:${Versions.spek}")
implementation("ch.tutteli.atrium:atrium-fluent-en_GB:${Versions.atrium}")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing again - does this need to be here if it's also in commonTest? (I haven't worked extensively with a MPP project before, so forgive me if this is a dumb question 😄)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite the opposite. jvmTest does not depend on commonTest and it would not make much sense as the JVM implementations of the frameworks are usually more powerful and you don't need conflicting definitions in your classpath. I'd leave it here as it does no harm (version is centralized elsewhere…).


package com.charleskorn.kaml.build

object Versions {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does Renovate support updating versions when configured like this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know about Renovate (never heard of it) but you apply the versions plugin which I'm also using in a number of projects configured this way. That plugin works with such a versions object.

@TheTeXnician
Copy link
Contributor Author

Thanks for the PR @TheTeXnician! This looks good to me. I've added a couple of comments on the Gradle configuration that I'm not sure about.

Thanks for the comments. Great pointers to things I overlooked :)

Also, is there a reason why some of the test files (YamlNodeReaderTest, YamlReadingTest and YamlWritingTest) are in jvmTest rather than commonTest?

Yes. Those tests (as far as I could see) depend on components that are JVM-only at the moment, e.g. YamlParser as they use SnakeYaml features. As soon as there is reliance on components from jvmMain they cannot be tested in commonTest but have to be tested in jvmMain. One should change this once there are expect definitions for these components so that the tests are available on all platforms.

In terms of the remaining work, I think you're correct in your assessment that the main thing is to get the publishing code working before this can be merged. Is that something you're willing to look into?

Unfortunately, I don't think I'll have the time at the moment. Your publishing code looks quite complex to me. I'm part of the Island of TeX which published a MPP library some weeks ago (see very simplistic build file of that publication in the repo). So if you would want to tackle it, you should ;)
Otherwise, I could try around April when I've got more time for open source again to address publishing code.

Base automatically changed from master to main February 6, 2021 22:16
@charleskorn charleskorn marked this pull request as draft February 22, 2021 07:46
@charleskorn charleskorn merged commit f0e7e59 into charleskorn:main Mar 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants