Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a separate compile task without a separate config, but different scalacOptions?

Tags:

scala

sbt

Departing from this question, I want to be able to compile an sbt projects in two different manners, i.e. with different scalacOptions. The answer to the duplicate questions explains why introducing another configuration doesn't help because you would also need dedicated sources.

So. But I don't want dedicated sources. I want to compile exactly the same sources but with different compiler settings. So I imagine the solution must be to define a new task instead that does the compilation. Like

val myCompile = taskKey[???]("Compiles my way")

scalacOptions in MyCompile ++= Seq("-elide-below", "1")

I would then want the minimum effort to duplicate the default compile task with a separate target directory, and could that feed than into a myCompile:assembly...? How would I do that?

like image 552
0__ Avatar asked Jan 06 '16 13:01

0__


1 Answers

tl;dr Use inspect to learn the return type of compile.

> inspect compile
[info] Task: sbt.inc.Analysis
...

With this, you should have the following in build.sbt:

val myCompile = taskKey[sbt.inc.Analysis]("Compiles my way")
myCompile <<= compile in Compile

scalacOptions in myCompile ++= Seq("-elide-below", "1")
like image 118
Jacek Laskowski Avatar answered Nov 13 '22 12:11

Jacek Laskowski