Donnerstag, 12. November 2015

Easy SBT build in Docker container

When you need to build your Scala project, but have no way to install SBT on your host, you can still do it if you have Docker.

There are few ready to use container images on DockerHub. We create our own.

All we need for that is to prepare a Dockerfile:

 FROM java:latest  
 MAINTAINER Nikolay Kushin nikolay@indoo.rs  
 ENV SCALA_VERSION 2.11.7  
 ENV SBT_VERSION 0.13.9  
 ENV SBT_OPTS -Xmx2G -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -Xss2M -Duser.timezone=GMT  
 # install sbt  
 RUN wget https://dl.bintray.com/sbt/debian/sbt-$SBT_VERSION.deb  
 RUN dpkg -i sbt-$SBT_VERSION.deb  
 # install scala  
 RUN wget https://downloads.typesafe.com/scala/$SCALA_VERSION/scala-$SCALA_VERSION.deb  
 RUN dpkg -i scala-$SCALA_VERSION.deb  
 # fetch base dependencies  
 RUN sbt compile  
 VOLUME /src  
 WORKDIR /src  
 CMD ["sbt"]  

Our Dockerfile is relatively easy and self-explaining.

Next step is to build an image. Save Dockerfile in some folder and execute following commande in terminal:

 docker build -t sbt-docker .  

Now when the image is ready we can create container with mounted source folder, containing our Scala project and run SBT.

 docker run -it --rm -v $(pwd):/src sbt-docker sbt docker:stage  

Thats it! Enjoy!

Samstag, 7. November 2015

RoboVM - way to write cross-platform mobile apps on Java

This weekend I spent some time participating in RoboVM Pull Request contest. Guys from RoboVM prepared demo application and invited people to add new features.

Amongst proposed features to add were:

  • commercial transactions support
  • localisation
  • everything else you can imagine :)

Because I had almost no previous mobile development experience I decided to start with some simple thing.

Typical RoboVM mobile project consists from 3 modules:

  • core - which shares code between platforms
  • android - platform specific UI implementation for Android
  • ios - platform specific UI implementation for iOS

For long time I wanted to give a try to Paypal Java SDK. That was a chance.

Because I wanted to use it for both platforms (iOS and Android) library dependency should be included to core module. Project uses Gradle as a build tool and all you need to do is include following line to build.gradle:
compile 'com.paypal.sdk:rest-api-sdk:1.2.9'
At first I started with simple implementation of payment API (PaymentAPI). I following this reference. Tried following sample requests against my test account. Everything worked perfectly!

Android UI is organised in fragments. I added new one (PaymentDetailsFragment) and changed a bit logic of working with order placement.

That was a pleasure to work with new RoboVM Studio. Most of functions I used to have in JetBrais Idea I had as well because it is just fork of Community Edition.

If you are reading this text before 23rd November 2015 you still have a chance to win one of the prices provided for that RoboVM contest.