Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile just some files with sbt?

Tags:

scala

sbt

I've come pretty well along with sbt, the Scala Build Tool. If you only have small problems in the code, it's easy.

Now, after a major feature add, much of my code is broken and I sbt seems to be confused as to how the dependencies are. I could help it, compiling the fundamental modules first, but it does not seem to let me.

It's help system is... notorious.

> help compile
Compiles sources.

Yeah, well. I guessed that.

What I wanted to hear was: how do I compile only - say - src/module/A.scala.

This might not even be possible (hello again, make, never abandoned you!). At least I cannot find any reference on the Internet to applying sbt compile just to a single file.

I'm using sbt from the command line prompt, not an IDE.

UPDATE:

It was my fault. :/ Had split a source file into multiple, but forgot to copy a package clause to each of the new ones. Oooops.

Will keep this open for a while, since compiling just a single file (i.e. something like sbt compile filename) would imho not be a bad thing.

like image 752
akauppi Avatar asked Nov 30 '12 14:11

akauppi


1 Answers

You could define a Multi-Project Build where the files you want to compile separately are encapsulated in a project. According to the docs, the following is then possible:

At the sbt interactive prompt, type projects to list your projects and project to select a current project. When you run a task like compile, it runs on the current project. So you don't necessarily have to compile the root project, you could compile only a subproject.

like image 79
fresskoma Avatar answered Sep 27 '22 18:09

fresskoma