Adding Scalastyle in a Multi-Module SBT Scala Project

Table of contents
Reading Time: 2 minutes

Nowadays, building a Multi-Module SBT project is becoming very common. It helps us to keep multiple related projects in a single build. Moreover, each sub-project in the build has its own SBT default directory. Also, it generates its own build and works like any other project. But, adding Scalastyle in a Multi-Module SBT Scala project is not easy because Scalastyle does not support Multi-Module SBT projects yet. So, in this post we will see how to add Scalastyle in a Multi-Module SBT project in an easy way.

In this following example we have a main project called parent and two sub-projects – child1 and child2. Now, lets get started with building the parent project.

1. To create multiple projects in a single build, we must first declare each project and also that how they relate in Build.scala file. So, here’s an example of a Build.scala file which defines a root project parent, where the parent project aggregates two sub-projects, child1 and child2.

This code resides under parent/project/Build.scala. Having common buildSettings for all projects helps in managing all common settings for all projects under one object. Besides we also have commonSettings which contains Scalastyle settings in it, so that we don’t have to add it separately in all projects.

2. Next we have added commonSettings in all sub-projects

By adding commonSettings in all sub-projects we get Scalastyle settings added in all of them. So, we don’t have to add Scalastyle settings in sub-projects separately.

3. Now we have to add following line of code in parent/project/plugins.sbt file

This code will help SBT to add Scalastyle as a Plugin in the project.

4. At last we need to add scalastyle-config.xml file in the parent folder.

5. Now if we run – sbt scalastyle command on the parent project we can see the warnings on the terminal for all sub-projects in a single go.

So, we saw in this post that how easy it is to add Scalastyle in a Multi-Module SBT Scala Project.

Written by 

Himanshu Gupta is a software architect having more than 9 years of experience. He is always keen to learn new technologies. He not only likes programming languages but Data Analytics too. He has sound knowledge of "Machine Learning" and "Pattern Recognition". He believes that best result comes when everyone works as a team. He likes listening to Coding ,music, watch movies, and read science fiction books in his free time.

1 thought on “Adding Scalastyle in a Multi-Module SBT Scala Project3 min read

Comments are closed.