Reputation: 11752
I want to create a skeleton console app for Scala i.e. a single entry class with a main function that prints "Hello world".
I was able to create a Scala library init project by executing:
gradle init --type scala-library
however there seems to be no scala-application, running:
gradle init --type scala-application
The requested build setup type 'scala-application' is not supported. Supported types: 'basic', 'groovy-application', 'groovy-library', 'java-application', 'java-library', 'pom', 'scala-library'.
Is there no Scala console app template for Gradle?
Upvotes: 13
Views: 2561
Reputation: 18864
On top of what you have for Java
you pretty much only need to add apply plugin: 'scala'
and change Main
to be:
object Main extends App {
println('Hello, World!')
}
I ended up doing just that.
Additionally, if you want joint compilation (and have compiler understand Java
and Scala
in the same place) you can add the below snippet (one block per source set: main
, test
, jmh
, etc.):
sourceSets.main {
java.srcDirs = []
scala.srcDirs = ['src/main/scala', 'src/main/java']
scala.include '**/*.*'
}
sourceSets.test {
java.srcDirs = []
scala.srcDirs = ['src/test/scala', 'src/test/java']
scala.include '**/*.*'
}
Upvotes: 2
Reputation: 1289
No, there is no scala application template, however it is easy to make your generated "scala-library" project into a scala application in two steps:
For example, you add src/main/scala/com/example/myapp/Main.scala:
package com.example.myapp
object Main {
def main(args: Array[String]): Unit = {
println("Hello")
}
}
Then to your gradle.build you add:
apply plugin: 'application'
mainClassName='com.example.myapp.Main'
Upvotes: 5