The point is missed

Museum of public mistakes and unfinished projects

Phasing over from java to scala pt. 2 – Buildr

with 2 comments

Yesterday I started converting parts of my pet-project to Scala. Without any other ambition than to make the java-class compile in Scala, roughly 30 lines of java-code became 18 lines of Scala code! Most of the save could be attributed to constructor properties that removed the need for declared fields and assigning them in a constructor. I also managed to run my old test-suite with my new scala replacement together with the rest of the java-code in eclipse. Talk about seamless transition!

The next obstacle is to build my scala project with Buildr – the build system that doesn’t suck, their words, we’ll see about that now. For java-projects Buildr can create a skeleton-project just by buildr in the root. Let’s try that:

jocke@euroblok:~/dev/publisher/publisher-scala$ buildr
To use Buildr you need a buildfile. Do you want me to create one?:
1. From directory structure
2. Skip
?  1

Ok, so far so good, a buildfile is generated. Without further examination let’s try if the generated script actually works:

jocke@euroblok:~/dev/publisher/publisher-scala$ buildr package
(in /home/jocke/dev/publisher/publisher-scala)
Building publisher-scala
Testing publisher-scala
Packaging publisher-scala
Running integration tests...

Can it really be this simple? No it wasn’t, I had to update builder to version 1.3 since that is when scala-support was added:

jocke@euroblok:~/dev/publisher/publisher-scala$ buildr --version
Buildr, version 1.2.10
jocke@euroblok:~/dev/publisher/publisher-scala$ sudo gem update buildr
Updating installed gems...
Attempting remote update of buildr
Select which gem to install for your platform (i486-linux)
 1. buildr 1.3.2 (java)
 2. buildr 1.3.2 (ruby)
 3. buildr 1.3.1.1 (ruby)
 4. buildr 1.3.1.1 (java)
 5. Skip this gem
 6. Cancel installation
> 2
Install required dependency rake? [Yn]  Y
Install required dependency net-ssh? [Yn]  Y
Install required dependency net-sftp? [Yn]  Y
Install required dependency rubyforge? [Yn]  Y
Install required dependency hoe? [Yn]  Y
Install required dependency Antwrap? [Yn]  Y
Select which gem to install for your platform (i486-linux)
 1. Antwrap 0.7.0 (ruby)
 2. Antwrap 0.7.0 (java)
 3. Skip this gem
 4. Cancel installation
> 2
Install required dependency rspec? [Yn]  Y
Install required dependency archive-tar-minitar? [Yn]  Y
Successfully installed buildr-1.3.2
...

After that I tried again:

jocke@euroblok:~/dev/publisher/publisher-scala$ rm buildfile
jocke@euroblok:~/dev/publisher/publisher-scala$ buildr
To use Buildr you need a buildfile. Do you want me to create one?:
1. From directory structure
2. Skip
?  1
Created /home/jocke/dev/publisher/publisher-scala/buildfile
jocke@euroblok:~/dev/publisher/publisher-scala$ buildr
(in /home/jocke/dev/publisher/publisher-scala, development)
Building publisher-scala
Compiling publisher-scala into /home/jocke/dev/publisher/publisher-scala/target/classes
rake aborted!
scala/tools/nsc/Main
(See full trace by running task with --trace)

Much, much better. I bet this problem will be fixed if I just point SCALA_HOME to the correct location. And it was! But we have another problem:

jocke@euroblok:~/dev/publisher/publisher-scala$ buildr
(in /home/jocke/dev/publisher/publisher-scala, development)
Building publisher-scala
Compiling publisher-scala into /home/jocke/dev/publisher/publisher-scala/target/classes
/home/jocke/dev/publisher/publisher-scala/src/main/scala/com/agical/publisher/content/site/PublishSiteGraph.scala:5: error: SiteGraphNode is not a member of com.agical.publisher.content
import com.agical.publisher.content.SiteGraphNode;
       ^

This was expected, the API-classes I use are in another project. So it’s time to figure out how to make a Buildr multi-project build. It turns out that it’s quite easy. This is the resulting buildfile:

VERSION_NUMBER = "0.0.1"
NEXT_VERSION = "0.0.2"
GROUP = "com.agical.publisher"
COPYRIGHT = "Agical AB"
# Specify Maven 2.0 remote repositories here, like this:
repositories.remote << "http://www.ibiblio.org/maven2/"

desc "Agical publisher"
define "publisher" do
  desc "the abstract api of the publisher"
  define "api" do
    project.version = VERSION_NUMBER
    project.group = GROUP
    manifest["Implementation-Vendor"] = COPYRIGHT
    package :jar
  end

  desc "the scala core"
  define "scala-core" do
    project.version = VERSION_NUMBER
    project.group = GROUP
    manifest["Implementation-Vendor"] = COPYRIGHT
    compile.with project('publisher:api')
    package :jar
  end
end

Most of this was generated by Buildr with slight modifications from my side:

  1. copy the scala-core define to an api define
  2. wrap the two projects in a surrounding publisher definition
  3. add a dependency from scala-core to api (the compile.with project(‘publisher:api’)
  4. add package :jar to both projects

So far I can agree that buildr doesn’t suck :) Now I will get busy trying to include the java-core into the build as well.

If you’re note tired of my ramblings yet the next part is here.

About these ads

Written by johlrogge

September 2, 2008 at 5:13 pm

Posted in java, Ruby, scala

Tagged with , , ,

2 Responses

Subscribe to comments with RSS.

  1. […] so some of you may wonder what I’m doing about the tests. I mentioned that all tests pass in pt. 2 but I have not written about how I test. Well, it probably comes as no surprise that the current […]

  2. […] The next part is here. […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: