Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to elegantly compose two tasks with SBT?

Tags:

sbt

I'd like to convert this bash expression:

$ sbt clean lint

into a nice build.sbt expression something like:

precommit := clean <> lint

so that I can run the following bash expression:

$ sbt precommit

For example, this is more-or-less how you'd do it with a Makefile:

lint:
    echo linting
    touch foo.txt

clean:
    echo cleaning
    rm -f foo.txt

precommit: clean lint

The Makefile can be used like:

$ make precommit
echo cleaning
cleaning
rm -f foo.txt
echo linting
linting
touch foo.txt

Any ideas?

like image 338
Steven Shaw Avatar asked Jan 23 '26 22:01

Steven Shaw


2 Answers

Use sequential task

precommit := Def.sequential(clean, lint).value

while wearing a bespoke British suit, driving an Aston Martin on a country road for added elegance.

like image 151
Eugene Yokota Avatar answered Jan 26 '26 23:01

Eugene Yokota


Use a command alias:

addCommandAlias("precommit", ";clean;lint")
like image 20
Dale Wijnand Avatar answered Jan 27 '26 00:01

Dale Wijnand



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!