pfn / kotlin-plugin

Build kotlin code using sbt

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Kotlin sources are not packaged with sbt publish

unoexperto opened this issue · comments

@pfn
I noticed that Kotlin sources are not packaged with sbt publish or publishLocal. As result my maven source artifact is empty. Could you please suggest how I can fix it ?

Here is what I tried so far
https://stackoverflow.com/questions/59256494/how-do-i-make-sbt-include-non-java-sources-to-published-artifact

It affects me for javadoc artifact too. Any updates on this?

To workaround this, I made following: https://github.com/makiftutuncu/e/blob/master/project/Settings.scala#L105

Basically, I added following setting in SBT to properly generate sources artifact:

// Include Kotlin files in sources
    packageConfiguration in Compile := {
      val old = (packageConfiguration in Compile in packageSrc).value
      val newSources = (sourceDirectories in Compile).value.flatMap(_ ** "*.kt" get)

      new Package.Configuration(
        old.sources ++ newSources.map(f => f -> f.getName),
        old.jar,
        old.options
      )
    }

For the documentation artifact, I added Gradle build to my Kotlin module. I set it up as shown here https://github.com/makiftutuncu/e/blob/master/e-kotlin/build.gradle.kts. This way, I make Gradle build generate the Dokka documentation. And finally, added following setting in SBT to run Gradle while building docs:

// Delegate doc generation to Gradle and Dokka
    doc in Compile := {
      import sys.process._
      Process(Seq("./gradlew", "dokkaJavadoc"), baseDirectory.value).!
      target.value / "api"
    }

I admit, this is a lot of work just to get 2 artifacts but it did the trick for me. 🤷🏻 Hope this helps.