tags:

views:

526

answers:

3

I have been struggling to get Buildr to compile my Scala 2.8 project and I was hoping someone might have figured this out already.

Currently I have the standard HelloWorld application with a buildfile like the following:

ENV['JAVA_HOME'] = 'C:\Program Files (x86)\Java\jdk1.6.0_17'
ENV['SCALA_HOME'] = 'C:\scala-2.8.0.Beta1-RC6'

define "HelloWorld" do

  #artifact_ns['Buildr::Compiler::Scalac'].library = '2.8.0'
  require 'buildr/scala'

  puts Scala.version

end

When I run buildr I get the following output:

(in C:/Users/Travis/eclipse_ws/HelloWorld, development)
2.7.5
Building HelloWorld
Compiling HelloWorld into C:/Users/Travis/eclipse_ws/HelloWorld/target/classes
Buildr aborted!
←[31mScala compiler crashed:
#←[0m

The first problem is the NoClassDefFoundError - it cannot find the scala compiler's main class. The second problem is that Scala.version is printing out 2.7.5. This is incorrect because the SCALA_HOME path is pointing to a 2.8 release.

Finally, using the --trace flag shows me that Buildr is generating a somewhat correct scalac command and when I run that command manually everything compiles. I say it's somewhat correct only because some cp entries are duplicated. See the following:

scalac -classpath C:/scala-2.8.0.Beta1-RC6/lib/scala-library.jar;C:/scala-2.8.0.Beta1-RC6/lib/scala-compiler.jar;C:/scala-2.8.0.Beta1-RC6/lib/scala-library.jar;C:/scala-2.8.0.Beta1-RC6/lib/scala-compiler.jar -sourcepath C:/Users/Travis/eclipse_ws/HelloWorld/src/main/scala -d C:/Users/Travis/eclipse_ws/HelloWorld/target/classes -verbose -g C:/Users/Travis/eclipse_ws/HelloWorld/src/main/scala/hw/HelloWorld.scala

One more thing I tried (but errored out builder) was setting the following (which I thought wasn't required w/ the presence of SCALA_HOME):

#artifact_ns['Buildr::Compiler::Scalac'].library = '2.8.0'

So any ideas?

Here is a quick list of my system info: Win 7 64 bit JDK 6 32 bit set locally for buildr but JDK 6 64 bit system-wide Ruby 1.8.6 32 bit Buildr 1.3.5 32 bit Scala 2.8.0.Beta1-RC6

One more thing I'm thinking of doing is reinstalling my 32 bit JDK and getting it out the the directory with the (x86) in the name. I've found that screws with the Scala bat files although I'm not sure if this is relevant to my current problems.

Thanks in advance!

+3  A: 

Figured it out. Silly problem. In Buildr(or maybe more generically in Ruby?), the require method call must come at the top of the file (or at least not inside the define block).

require 'buildr/scala'

So both the NoClassDefFoundError and the incorrect version displayed by puts Scala.version were corrected by this. The following is what my script should have looked like:

require 'buildr/scala'

ENV['JAVA_HOME'] = 'C:\Program Files (x86)\Java\jdk1.6.0_17'
ENV['SCALA_HOME'] = 'C:\scala-2.8.0.Beta1-RC6'

define 'HelloWorld' do

  puts Scala.version

end

BTW: Buildr seems to be pretty sweet (fast, concise, convention over config, etc.) once you figure what you are doing :-)

Travis
I'm glad you figured this out. Thanks for posting. I got this to work for a test project on OS X with JRuby and Buildr 1.4.0 (RC).
Jay Conrod
+1  A: 

Buildr 1.4 has support for Scala 2.8 and 1.4.2 will use 2.8 by default.

Antoine Toulme
A: 

With version 1.4, at the moment you can do

Buildr.settings.build['scala.version'] = "2.8.0"
require 'buildr/scala'

And it will use scala 2.8.

Rafa de Castro