Aggregating analyzes on sbt subprojects

In sbt, if I use mapR in the compile task, I can get an Analysis object that will allow me to collect warnings and other information. This allows you to programmatically monitor alert statistics for specific projects.

However, I have many subprojects aggregated in the root project using the sbt aggregation function. Is there an idiomatic way of aggregating this information (or arbitrary information) up the aggregation tree like this? For example, if I wanted to know the total number of warnings in the entire assembly, how can I do this? I can maintain the global Scala state in my sbt project and add AtomicInteger to AtomicInteger after each step of the project, but it seems ugly and I feel that there should be a better way.

In the context, I want to tell TeamCity the total number of warnings in the assembly, so I need to be able to collect information like this.

+1
source share
1 answer

There is an easy way to get the analysis, but only if all the Analysis values ​​you want are in the class path. In sbt, the classpath is of type Seq[Attributed[File]] . The Attributed part attaches metadata to each record. One piece of metadata is Analysis for this record (obviously, only if it was compiled from the source).

So, this would get Seq[Analysis] for the classpath:

 ... (fullClasspath in Compile) map { (cp: Seq[Attributed[File]]) => cp.map(entry => Defaults.extractAnalysis(entry)._2) } 

Note that the implementation of Defaults.extractAnalysis gets an empty Analysis if it is not attached.


In 0.13, the API usually uses the API:

http://www.scala-sbt.org/snapshot/docs/Detailed-Topics/Tasks.html#multiple-scopes

In this case, it will look like this:

 someTask := { val allA: Seq[inc.Analysis] = compile.result.all( ScopeFilter( inAggregates(ThisProject), inConfigurations(Compile) ) ).value ... } 

(The result part does the same as mapR in the direct syntax: http://www.scala-sbt.org/snapshot/docs/Detailed-Topics/Tasks.html#result )

+2
source

Source: https://habr.com/ru/post/1487538/


All Articles