Build kotlin code using sbt
Current version 3.0.3
- for sbt 0.13.6+, add following in project/plugins.sbt:
- resolvers += "jitpack" at "https://jitpack.io"
- libraryDependencies += "com.github.tmtsoftware" % "kotlin-plugin" % "3.0.3"
- Kotlin code will build automatically from
src/XXX/kotlin
- If necessary, add
kotlinLib("stdlib")
, it is not included by default.- Loading standard kotlin libraries and plugins: use
kotlinLib(NAME)
as above to load standard kotlin modules provided by JetBrains. For JetBrains kotlin compiler plugins, usekotlinPlugin(NAME)
(e.g.kotlinPlugin("android-extensions")
). The difference is that the latter marks the module as acompile-internal
dependency and will be excluded from the final build product. - Any other libraries can be loaded using the normal
libraryDependencies
mechanism. Compiler plugins should be added as a normallibraryDependency
but specified to be% "compile-internal"
- Loading standard kotlin libraries and plugins: use
- If a non-standard Classpath key needs to be added to the kotlin compile step,
it can be added using the
kotlinClasspath(KEY)
function- For example, to compile with the android platform using
android-sdk-plugin
:kotlinClasspath(Compile, bootClasspath in Android)
- For example, to compile with the android platform using
kotlincPluginOptions
: specifies options to pass to kotlin compiler plugins. Useval plugin = KotlinPluginOptions(PLUGINID)
andplugin.option(KEY, VALUE)
to populate this settingkotlinSource
: specifies kotlin source directory, defaults tosrc/main/kotlin
andsrc/test/kotlin
kotlinVersion
: specifies versions of kotlin compiler and libraries to use, defaults to1.5.20
kotlinLib(LIB)
: load a standard kotlin library, for examplekotlinLib("stdlib")
; the library will utilize the version specified inkotlinVersion
pluginkotlincOptions
: options to pass to the kotlin compiler
- See the test cases for this plugin
- kotlin compilation runs outside of the normal sbt compilation infrastructure.
As a result, sbt is unaware of classes generated during kotlin compilation.
run
andtest
will not work automatically since kotlin classes will not have been discovered.runMain <main-class>
can be used in place ofrun
.testOnly <test-class>
may be able to test individual classes/suites in place oftest
. Any other tasks which rely on automatically detecting classes will fail similarly.