flonso / kotlin-scalajs-gradle-plugin

A Gradle plugin for running the Kotlin to ScalaJS compiler

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using the plugin

You need to clone the Kotlin-Scala.js compiler and publish it locally using sbt publishM2. (You might need to append the version number with SNAPSHOT if you intend to make changes to the plugin)

Then, publish the plugin locally by doing gradle publish from this project directory.

Finally you can launch the example project build by typing gradle k2sjs.

Available tasks

This section lists the main available tasks defined by the plugin. A full list of these tasks and the ones generated by Gradle can be obtained by running gradle tasks in the project root folder.

  • build This is the standard Gradle build task which builds the sources of project. It depends on the k2sjs task defined below.

  • build-original This task provides an easy way to call the original Kotlin compiler in case one needs to compile a project with both compilers (for benchmarking purposes for instance).

  • clean This is the standard Gradle clean task. It will erase the content of the build/ folder generated by the build command.

  • k2sjs This is the main compilation task defining the compilation steps detailed previously.

Available options

Various options are available in order to adapt the kotlin2sjs plugin to one's needs. They must be declared and used inside the k2sjs configuration block.

Example configuration :

  // Inside the build.gradle file
  k2sjs {
    kotlinHome = "/usr/share/kotlin"
    dstFile = "./web/js/mycode.js"
    compilerOptions = "-verbose"
    optimize = "fullOpt"
  }
  • kotlinHome Allows to specify the path to the local Kotlin installation directory. This option defaults either to the content of the environment variable $KOTLIN_HOME or to /usr/share/kotlin.

  • dstFile This option contains the path and name of the .js file output by the linker. This must match the pattern path/to/output.js. This option defaults to path/to/projectname/build/projectname.js.

  • optimize This option defines the optimization level desired for the output JavaScript code. It can contain one of the three following values : "noOpt", "fastOpt" or "fullOpt". Its default value is "fastOpt".

  • compilerOptions Allows to specify custom compiler arguments. Those arguments must be contained in a String and be separated by spaces. By default it is empty.

  • linkerOptions Just like the compilerOptions, this field allows to pass custom command line arguments to the Scala.js linker. They must be separated by spaces as well. By default it is empty. Note that the option -c to check the consistency of the SJSIR files is always enabled.

About

A Gradle plugin for running the Kotlin to ScalaJS compiler


Languages

Language:Groovy 97.5%Language:Kotlin 2.5%