pfn / kotlin-plugin

Build kotlin code using sbt
MIT License
136 stars 35 forks source link

Kotlin sources are not packaged with sbt publish #38

Open unoexperto opened 4 years ago

unoexperto commented 4 years ago

@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

makiftutuncu commented 4 years ago

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

makiftutuncu commented 4 years ago

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.