Compile Scala code 2.8.x with Apache Buildr

I am trying to get Buildr to compile my Scala 2.8 project, and I was hoping that someone might already figure this out.

I currently have a standard HelloWorld application with an assembly file, for example:

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
HelloWorld Construction
Compiling HelloWorld in C: / Users / Travis / eclipse_ws / HelloWorld / target / classes
Buildr aborted!
← [31mScala compiler crashed:
# ← [0m

The first problem is NoClassDefFoundError - it cannot find the main class of the Scala compiler. The second problem is that Scala.version prints 2.7.5. This is not true because the SCALA_HOME path points to release 2.8.

Finally, using the -trace flag shows me that Buildr generates a somewhat correct scalac command, and when I run this command manually, everything compiles. I say this somewhat correctly, 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 / Library / scala -library.jar; C: / scala -2.8.0.Beta1-RC6 / Library / 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 the wrong builder) installed the following (which I thought was not required with SCALA_HOME):

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

So any ideas?

Here is a short list of my system information: Win 7 64 bit JDK 6 32 bit installed locally for buildr, but JDK 6 64-bit throughout Ruby 1.8.6 32 bit Buildr 1.3.5 32 bit Scala 2.8.0.Beta1-RC6

Another thing I'm going to do is reinstall my 32-bit JDK and extract it from the directory with (x86) in the name. I found that there are screws with bat Scala files, although I'm not sure if this applies to my current problems.

Thanks in advance!

+7
scala buildr
source share
3 answers

Figured it out. Stupid question. In Buildr (or maybe more general in Ruby?), The call to the require method should be at the top of the file (or at least not inside the define block).

require 'buildr / scala'

Thus, both NoClassDefFoundError and the incorrect version displayed using Scala.version are fixed. The following was what my script should look 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 pretty nice (fast, concise, conditional over config, etc.) as soon as you determine what you are doing :-)

+3
source share

With version 1.4 at the moment you can do

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

And he will use scala 2.8.

+2
source share

Buildr 1.4 supports Scala 2.8 and 1.4.2 uses 2.8 by default.

+1
source share

All Articles