How to capture compilation errors and warnings in SBT - sbt

My purpose is to write all compile warnings and errors to a file, that will be shown as a report file in Jenkins.
In this way, it is more clear to see the output of many tasks running in parallel.
How can I accomplish this with the compile task?
UPDATE:
I've researched a little and found:
compilerReporter, but is is declared as private. So it cannot be used.
bspReporter task, that I don't know how to override

The clue is to use the compilerReporter task.
As this task is defined as private[sbt], the only choice is to create within the project an AutoPlugin in the sbt package.
This plugin will be responsible of overriding the default value of the task, and will have no problems as it is in the same package.
More info here: https://github.com/sbt/sbt/pull/5948

Related

How to include the application's version number in a Scala.js program?

Basically, I'm curious if something like SBT including the version number in a program is possible for Scala.js. The proposed solution doesn't work in scala.js, apparently due the the absence of the getPackage method:
[error] Referring to non-existent method java.lang.Class.getPackage()java.lang.Package
Use sbt-buildinfo for that. The Usage section of the readme contains everything you need.

Node.js externs for closure compiler?

Firstly: The "official" (?) node.js externs are located here: https://github.com/google/closure-compiler/tree/master/contrib/nodejs
But i can't use it because the high amount of warnings (and errors sometimes) that are generated. For example: The declaration of "process" module is very "thin"; Only has one property defined on his prototype, besides not inherit from EventEmitter, so i can't register callback when, for example, i want to do a clean job on process SIGINT (process.on('SIGINT', callback)).
When i mix several externs files declaring the core modules of node.js, more and more warnings and errors are raised (i always respect the deps tree between externs). For example: If i include the events.js and stream.js externs files, an error is raised because the "event" global var is redeclared: Once in events and again in stream.
So: What am i doing wrong?
The closure compiler that i am using is the latest git, whit --new_type_inf and --env flags activated, among others.
For example: If i include the events.js and stream.js externs files, an error is raised because the "event" global var is redeclared: Once in events and again in stream.
This highlights the core of the problem - and why they are not well maintained. The compiler doesn't recognize that these variables are in fact NOT global. The compiler currently does not have a method to correctly interpret externs as modules. The were originally contributed and consumed by a fork of the project that could understand externs as modules.
I am currently working on adding support to the compiler for this and hope to some day soon be able to completely rewrite this answer.
In the mean time, you might be able to work around some of this by adding #suppress {duplicate} annotations to the files. However keep in mind that they will still be global types.
If you wish to improve the files (like having process properly extend EventEmitter), I will happily review pull requests for such changes.

Configure an sbt build for a test framework of your own

In one vein of thought I would like to configure a build with a custom task that will serve instead of the test default task. I will not be registering it as an "sbt test framework" as I'd like to avoid the syntax, limitations and history that comes with that. For example I'd like more flexibility in formatting, storing and sending test results.
Would it be possible introducing an sbt task to mimic sbt's default test task, in the following essential senses:
depend on compilation
be a dependency for other tasks such as artifact publishing tasks, and have them depend on a success return value from it
be able to provide it with library dependencies which will be excluded from final publishable artifacts
be able to control it just like any other task dependency
etc
Alternatively, are you able to delineate the structure of the mostly undocumented sbt TestFramework interface to a level that it's straightforward having your own formatting, test output logic, and test results publishing code, in your TestFramework implementation? I have mostly failed locating scalaTest's implementation of it.
Thanks in advance for you answers on both techniques.

Packages not defined

i wrote a script in javascript and used it in rules (share). The script start with:
var ctx = Packages.org.springframework.web.context.ContextLoader.getCurrentWebApplicationContext();
I m getting an error telling me that "Reference error: Packages is not defined".
How can i solve this issue?
The Packages object is only available for code which is considered "secure". This is most likely failing because the code is from a node in the Repository/Data-Dictionary. Put it somewhere in the classpath (e.g. classes/alfresco/templates/webscripts/...).
I don't think you can use this object in javascript, you won't find that code anywhere in Share javascript files. According to this link, Package root scope object is only available for web script implementations placed into the Java classpath, due to security reasons.
Try writing Java code for your rule.

Setting system properties with "sbt run"

I'm using a pretty recent version of SBT (seems to be hard to figure out what the version is). I want to pass system properties to my application with sbt run as follows:
sbt -Dmyprop=x run
How could I do that?
SBT's runner doesn't normally create new processes, so you also have to tell it to do this if you want to set the arguments that are passed. You can add something like this to your build settings:
fork := true
javaOptions := Seq("-Dmx=1024M")
There's more detail on forking processes in the SBT documentation.
I found the best way to be adding this to build.sbt:
// important to use ~= so that any other initializations aren't dropped
// the _ discards the meaningless () value previously assigned to 'initialize'
initialize ~= { _ =>
System.setProperty( "config.file", "debug.conf" )
}
Related: When doing this to change the Typesafe Configuration that gets loaded (my use case), one needs to also manually include the default config. For this, the Typesafe Configuration's suggested include "application" wasn't enough but include classpath("application.conf") worked. Thought to mention since some others may well be wanting to override system properties for precisely the same reason.
Source: discussion on the sbt mailing list
Thanks for the pointer, this actually helped me solve a somewhat related problem with Scala Tests.
It turned out that sbt does fork the tests when there are sub-projects (see my code) and some of the tests fail to pick up the system property.
So in sbt -Dsomething="some value" test, some of the tests would fail when failing to find something in the system properties (that happened to be my DB URI, so it kinda mattered!)
This was driving me nuts, so I thought I'd post it here for future reference for others (as #akauppi correctly noted, chances are high that "others" may well be me in a few weeks!).
The fix was to add the following to build.st:
fork in Test := false
I think the best is to use the JAVA_OPTS environment variable:
#update the java options (maybe to keep previous options)
export JAVA_OPTS="${JAVA_OPTS} -Dmyprop=x"
#now run without any extra option
sbt run
You can pass system properties at the end of the sbt command:
sbt run -Dmyprop=x
If you have to pass program parameters into a stage, just pass system properties after the quotes again:
sbt "runMain com.example.MyClass -p param-value" -Dmyprop=x

Resources