Pages

Showing posts with label intellij. Show all posts
Showing posts with label intellij. Show all posts

Wednesday, July 6, 2011

Quickly converting AndEngine examples to Scala

If you are anxious to get your first AndEngine application running on Scala but your Scala is a little rusty or you are just taking your first steps with Scala, Intellij IDEA offers a nice little feature.
After you have created a base project for yourself with all the necessities (Scala, Android and AndEngine), you can first:
  • import one of the AndEngine examples (written in java) to your project,
  • select the contents of the file,
  • create a new Scala class and
  • paste the contents you copied earlier to that file.
Here comes the nice surprise, you are greeted with the following popup:
image
Well damn right I do! The end result sure isn’t the beautiful functional programming you want to achieve, and it does need some minor adjusting but it sure is a fast way to kick start your AndEngine experience with Scala.

Saturday, July 2, 2011

Enable fast Scala compiler (fsc) on IntelliJ IDEA

Regular compilation with Scala compiler is really slow. Most of the time is spent compiling parts of Scala libraries, instead of your own code though. Solution is to use fsc (fast scala compiler), which is daemon that compiles the required Scala libraries on the first compilation, and stays in memory after that, so your subsequent compilations after a lot faster.

My first guess was to just click the checkbox “Use fsc” in the Scala plugin settings page. This alone only causes exceptions. You also need to create a Scala compilation server instance for yourself.

  1. Open the 'Edit (Run/Debug) Configurations' dialogimage
  2. Click on the [+] in left top corner of the window
  3. Select 'Scala Compilation Server' (should be near the end of the list) 
  4. Give the new launcher a name (e.g. 'my fsc server') and hit OK
  5. Press the Play icon to compile and run as usual.

Your second press of Play should be a lot faster!

Sunday, May 29, 2011

Your first Scala module with Maven

Start by:

  • Installing IntelliJ IDEA
  • Downloading and unpacking Maven
  • Installing Scala
  • Installing Scala plugin to IntelliJ
  • Setting Maven home directory (either with M2_HOME or overriding the settings in IntelliJ)
Next up is creating a project and a module based on scala-archetype-simple:


File -> New project..
Select "Create project from scratch".

Give the project a name and the module a name. Remember that the module name is used as a package name for scala, so no dashes allowed!

Select module type: Maven Module.

Click next.

Make sure the create from archetype is selected and click "Add Archetype..".

Fill in the following details:


Select the archetype you added and click Finish.

In this archetype, the pom.xml contains <repositories> and <pluginRepositories> but they are commented out. Uncomment those blocks.

On the very right side of IntelliJ there's a vertical block that contains a tab called Maven Projects. Open it, open the project you just created and run the "package" maven task. This will compile, test and package your project and it will also download all dependencies required by a scala maven project.

Now you should be all set to create your first maven-based scala project.

Note that the archetype used, also created a simple object for you and some tests for that object to get you started.