Skip to content

Instantly share code, notes, and snippets.

@koterpillar
Created November 28, 2019 04:18
Show Gist options
  • Save koterpillar/edea748d363cb73a795c8ed3970e1b9f to your computer and use it in GitHub Desktop.
Save koterpillar/edea748d363cb73a795c8ed3970e1b9f to your computer and use it in GitHub Desktop.
Enable Scala kind projector in a Gradle build
// This enables kind projector (https://github.com/typelevel/kind-projector) in a Gradle build.
// Versions used: Gradle 6.0.1, Scala 2.13.1.
ext {
scalaVersionFull = '2.13.1'
scalaVersion = '2.13'
}
configurations {
kindProjectorPlugin
}
dependencies {
implementation "org.scala-lang:scala-library:${scalaVersionFull}"
kindProjectorPlugin group: 'org.typelevel', name: "kind-projector_${scalaVersionFull}", version: '0.11.0'
}
tasks.withType(ScalaCompile) {
scalaCompileOptions.additionalParameters = [
"-Xplugin:" + configurations.kindProjectorPlugin.asPath,
]
}
@gabrieljones
Copy link

gabrieljones commented Mar 25, 2021

For anyone searching for what this looks like in Kotlin DSL:

build.gradle.kts:

plugins {
  scala
  //...
}

object Versions {
  const val ScalaBinary = "2.13"
  const val Scala = "2.13.5"
  //...
}

val kindProjectorPlugin by configurations.creating

dependencies {
  kindProjectorPlugin("org.typelevel:kind-projector_${Versions.Scala}:0.11.3")
  implementation("org.scala-lang:scala-library:${Versions.Scala}")
  //...
}

tasks {
  compileScala {
    scalaCompileOptions.additionalParameters = listOf(
      "-Xplugin:" + kindProjectorPlugin.asPath
    )
  }
  //...
}
> ./gradlew --version

------------------------------------------------------------
Gradle 6.8.3
------------------------------------------------------------

Build time:   2021-02-22 16:13:28 UTC
Revision:     9e26b4a9ebb910eaa1b8da8ff8575e514bc61c78

Kotlin:       1.4.20
Groovy:       2.5.12
Ant:          Apache Ant(TM) version 1.10.9 compiled on September 27 2020
JVM:          1.8.0_275 (AdoptOpenJDK 25.275-b01)
OS:           Mac OS X 10.15.7 x86_64

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment