Skip to content

Instantly share code, notes, and snippets.

@DamianReeves
Last active April 21, 2022 15:11
Show Gist options
  • Save DamianReeves/4a3f7330b6c2dff6061c4f4ddda8dc9c to your computer and use it in GitHub Desktop.
Save DamianReeves/4a3f7330b6c2dff6061c4f4ddda8dc9c to your computer and use it in GitHub Desktop.
Using Scala Compiler Plugins From Gradle
plugins {
id 'scala'
}
configurations {
scalaCompilerPlugin
}
dependencies {
// Use Scala 2.11 in our library project
compile 'org.scala-lang:scala-library:2.12.6'
compile 'io.estatico:newtype_2.12:0.4.2'
scalaCompilerPlugin 'org.scalamacros:paradise_2.12.6:2.1.1'
// Use Scalatest for testing our library
testCompile 'junit:junit:4.12'
testCompile 'org.scalatest:scalatest_2.12:3.0.5'
// Need scala-xml at test runtime
testRuntime 'org.scala-lang.modules:scala-xml_2.12:1.1.0'
}
repositories {
jcenter()
}
tasks.withType(ScalaCompile){
// Map plugin jars to -Xplugin parameter
List<String> parameters =
configurations.scalaCompilerPlugin.files.collect {
'-Xplugin:'+ it.absolutePath
}
// Add existing parameters
List<String> existingParameters = scalaCompileOptions.additionalParameters
if (existingParameters) {
parameters.addAll(existingParameters)
}
// Add whatever flags you typically add
parameters += [
'-language:implicitConversions',
'-language:higherKinds'
]
// Finally set the additionalParameters
scalaCompileOptions.additionalParameters = parameters
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment