Compile Scala 2.8.x code with Apache Buildr
Asked Answered
R

3

7

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!

Recrystallize answered 30/12, 2009 at 2:59 Comment(4)
I don't see the PATH to Scala binaries (scripts, actually) being set.Gyp
It's set globally as a System variable which should be available inside the script... I will test out setting it locally in the script when I get back to my home computer. Thanks for the quick response!Recrystallize
Even when I insert the following line into my buildfile the problem still exists. ENV['PATH'] = ENV['SCALA_HOME'] + '\bin;' + ENV['JAVA_HOME'] + '\bin;' + ENV['PATH']Recrystallize
Tried switching to Scala 2.7.7 still does not work - same error. Tried mutilating the SCALA_HOME env var to something invalid which forces Buildr to retrieve the scala compiler from maven - same error. At this point I'm about out of ideas. My poor HelloWorld program isn't saying much these days :-(Recrystallize
R
3

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 :-)

Recrystallize answered 31/12, 2009 at 2:8 Comment(1)
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).Congenial
S
2

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.

Shantae answered 15/9, 2010 at 23:12 Comment(0)
I
1

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

Icy answered 1/8, 2010 at 11:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.