Gradle for Scala? a bad idea? What about SBT?

In my last post, I explained how I have setup my LibGDX game project to use Scala. No doubt it’s working but if you follow my procedure, you will face the same wall as me: it is unusable in an IDE, or at least in IDEA Intellij: no error displayed when typing, no error displayed when opening a file… The only way to see compilation errors is to ask for a full rebuild of the project each time you modify something…

So who is the culprit?

  • Scala-plugin? Scala support in IDEA Intellij 14.1 is quite good for a new project. It is not as advanced as Java is but time will make the plugin for Scala better i have no doubt on this.
  • Gradle? When launching a build with Gradle, everything compile smooth.  I have tested both desktop and android version and nothing is wrong.
  • Gradle with Scala in IDEA? Gradle is working well in IDEA for java projects but Gradle with the Scala plugin in IDEA seems not really supported. It is working but its working badly. [EDIT] Hopefully, someone from twitter help me to fix the issue: just clean your .idea config folder, upgarde Intellij/Scala plugin/Gradle to their last version and re-import projects: all issues are gone.[/EDIT]

So I decide to have a look to SBT as this is the preferred build tool for Scala projects. Scala plugin in IDEA is supporting SBT and it can’t be worse that Gradle + Scala.

I use a gitter template found on github and get a really simple project with a structure similar to the one i have with Gradle: core, desktop, android, ios. After compiling and checking that the sample project is working properly, i moved my game code in core/src/main/scala and modify two things in the Scala build task all-platforms/build.scala :

  • add the local maven repository:
  • add a new dependency for my personal game framework:
    • add a new parameter in versions.sbt :
    • Modify all-platforms/build.scala  to add this new dependency:

SBT compilation from command line is working well. If you import the project in IDEA, all is running smoothly. Changing library versions in versions.sbt  and refresh the SBT project in IDEA works perfectly like a Maven or a Gradle project.

So my advice for a Scala project is: forget Gradle and Maven and focus on SBT.

 

  • Pingback: Moving from java to scala in my LibGDX-Android game - Game over()

  • A very interesting post for me, as I regularly use both Gradle and SBT in IDEA all the time.

    I must say that you come to conclusion upon point 3 above too fast, as there are examples out in the wild that prove the exact opposite. I have several gradle projects building scala on github that work in IDEA with far less problems than SBT. For reference, please take a look at http://github.com/gvmtool

    One thing to make certain of is that you have the latest version of IDEA, as well as the latest Gradle installed. Also ensure that you completely remove the .idea folder before doing anything else. Then use the Import option from the main menu, and if your build.gradle file is well formed it should import and work seamlessly.

    As I’ve said before, the amount of pain that my team and I have experienced using SBT in IDEA pushed me to using Gradle with Scala. I’ve never looked back.

    Also be sure to check out the contributions that linked in are making to Gradle as they add first class Play framework support to IDEA.

    Hope this helps restoring your faith in Gradle with Scala!

    • Hi Marco,
      Thanks for you comment.
      So i follow your advice:
      – cleaning .idea folder
      – upgrade IntelliJ and Scala plugin
      – upgarde Gradle to version 2.4
      – reimport project in IDE
      All is running well so thanks a lot!
      I will update my post with this info (and change the title a little…)