Excluding a specific file extension from jacoco using sbt - scala

I am trying to exclude specific file extension from the raport of jacoco. According to the documentation: https://www.scala-sbt.org/sbt-jacoco/settings.html I have to specify
jacocoExcludes. So I did it in that way:
jacocoExcludes in Test := Seq(
"**/*.sh"
)
but that does not work... I can still any .sh files in raport of jacoco and then in sonar.
How can I receive that?

Related

How to map files by extension in sbt?

I want to compile WSDL files with the sbt-xjc plugin. By default, it looks for all the *.xsd files and I want to look for *.wsdl files. I tried this syntax:
sources in (Compile, xjc) ++= unmanagedResourceDirectories.value.flatMap(dirs => (dirs ** "*.wsdl").get)
But I get an error at sbt compile:
Reference to undefined setting:
*:unmanagedResourceDirectories from compile:xjc::sources (build.sbt:76)
Did you mean web-assets:unmanagedResourceDirectories ?
How can I add all the *.wsdl files to xjc?

Include generated resources in a jar (SBT)

I've been writing an SBT plugin that generates resources into resource_managed. I'm now looking to include these generated resources in the generated jar as the SBT docs detail:
Generating resources:
By default, generated resources are not included in the packaged source artifact. To do so, add them as you would other mappings. See Adding files to a package
I've read the docs but honestly how to do this I can't figure out. Can anyone explain it or point me to another project that does this so I can see how they do it?
First just to clarify, they are included in jars containing compiled classes. They are not included in jars containing sources.
By default, generated resources are not included in the packaged
source artifact.
For packageBin the generated files should already be included - just make sure you return all generated files from the generator method. Assuming you want to package them in the sources artifact, this is what you have to do.
Let's assume you have a generator that generates a property file.
lazy val generatePropertiesTask = Def.task {
val file = (Compile / resourceManaged).value / "stack-overflow" / "res.properties"
val contents = s"name=${name.value}\nversion=${version.value}"
IO.write(file, contents)
Seq(file)
}
resourceGenerators in Compile += generatePropertiesTask.taskValue
To include that in the generated sources you have to tell sbt to where the res.properties must be copied in the generated sources artefact. The task, which generates the packaged sources is called packageSrc, therefore you have to set mappings scoped to that task.
mappings in (Compile, packageSrc) += {
((resourceManaged in Compile).value / "stack-overflow" / "res.properties") -> "path/in/jar/res.properties"
}
Because your generator can generate many tasks, and mapping each by hand would be a tedious task, sbt gives you an utility to map multiple paths at once.
mappings in (Compile, packageSrc) ++= {
val allGeneratedFiles = ((resourceManaged in Compile).value ** "*") filter { _.isFile }
allGeneratedFiles.get pair relativeTo((resourceManaged in Compile).value)
}
The first line finds all generated files using path finders and second line maps them to their path in the target jar.

What are the options to set base packaged directory for a package using sbt-native-packager?

I am trying to build a Debian package using sbt-native-packager as described in this build.sbt.
I set appName using
val appName = "megamgateway"
in project/Build.scala.
All works well. It is just that the contents are stored in /usr/share/megamgateway.
I'd like to have the contents under /usr/share/megam/gateway.
The only way I could find is to use
linuxPackageMapping
as shown here.
Before following along, I'd like to know about other approaches.
You could try to add to your project settings
name := "gateway"
defaultLinuxInstallLocation := "/usr/share/megam/"

How can I download and add static files to a project using SBT

I want to add some files to test a library that I am writing.
The tests are available in a compressed file in a URI and I just want to download that file and uncompress its contents to a folder before testing.
I was reading the documentation on SBT and there is a Generate sources/resources task.
Also, it seems easy to uncompress a zip file in Scala (see this question).
So I think, I could glue those 2 pieces together, but I wonder if there is some simpler solution.
How about this (syntax for Sbt 0.13.2), in your build.sbt:
resourceGenerators in Test += Def.task {
val location = url("http://path/to/your/zip-file.zip")
IO.unzipURL(location, resourceManaged.value / "my-custom-files").toSeq
}.taskValue

How to add some local maven repo url to global sbt, and make them be tried first?

I want to add some fast local maven repository url to sbt, say:
http://maven.example.com/public
I want to add it to "global", so that I don't need to add them to each of sbt project. And also want to be tried first when sbt downloading some jars.
But I can't find useful information to do this, how to do it?
(My sbt version is 0.13.1)
With the help of a friend, finally I found the solution:
create a new file ~/.sbt/repositories
add content like this:
[repositories]
local
my-maven-repo: http://example.org/repo
my-ivy-repo: http://example.org/ivy-repo/, [organization]/[module]/[revision]/[type]s/[artifact](-[classifier]).[ext]
See official doc: http://www.scala-sbt.org/0.13.2/docs/Detailed-Topics/Library-Management.html#override-all-resolvers-for-all-builds
Modify your global configuration file, which is normally located in ~/.sbt/0.13/global.sbt, if it's not there you can create it.
In the file add following line:
externalResolvers := { ("Fast Repo" at "http://maven.example.com/public") +: externalResolvers.value }
You can confirm it's working by executing show externalResolvers in any project to see the list of resolvers. Your newly added resolver should be first.