Specify plugins in Build.scala - scala

If I want to use a build.scala file in order to build my project (instead of build.sbt)
how do I specify the plugins?
I want to use the sbt-assmbly plugin. and I am aware that I can create a plugins.sb file and do a addSbtPlugin there.
But i want to put all my build logic in build.scala instead of the sbt files.

No, you can't. You can put it in project/project/Build.scala, which would let you avoid .sbt files, but probably isn't what you want.
The thing is, project directory is itself an SBT project, and SBT handles project/*.sbt files and project/project/*.scala files in it just the same as it does on the top level; but by the time it's working with project/Build.scala, it's too late to add plugins.

Related

How to split build.sbt in a Play Framework Project?

I am not sure how to split the build.sbt file in a Play project. Usually in the Play projects I have seen only one build.sbt file, but the project I am referring to have multiple build files in addition to the build.sbt file like:
build.checkstyle.sbt
build.findbugs.sbt
build.junit.sbt
I am not sure if they have split the build.sbt file or is it something else all together. Can anybody help me understand what is happening here?
One more thing is I know what are the purpose of these files like the checkstyle file is used for code style checking and the junit file is for the unit testing. These functions are working perfectly fine, but what I am struggling to understand is how/where did they configure it. I mean these files are not imported by the base build.sbt file so how is the configuration done?
This is just how sbt works. It scans your project for .sbt files, not only a build.sbt file. From sbt docs:
Any time files ending in .scala or .sbt are used, naming them build.sbt and Build.scala are conventions only. This also means that multiple files are allowed.
So, basically, at the mentioned project, people decided that it would be better to split the settings in different files. There is nothing special to do and sbt will handle that for you. Another example is Playframework itself:
https://github.com/playframework/playframework/tree/master/framework
See how it have a build.sbt and a version.sbt files. This is also just a convention so that you can configure the project version at a separated file (which is understood by some sbt plugins, like sbt-release).

How to import directory of .scala files in sbt (unmanaged)?

I have a directory that I want to use as a dependancy for an sbt project however its comprised of .scala files which means I can't place it inside a jar (from what I understand) so then how can I use it as a dependancy for my project?
(sbt doesn't have it as a managed dependancy)
thanks in advance
as written in the manual, you can customize the sources (or source directories) pretty freely. by default, sbt will expect to have scala and java sources under a source directory.
you can customize that too. depending on your exact use case, maybe you want these sources under a different configuration? if it's just extra sources to compile and package, you can simply use:
sourceDirectories in Compile += file("/path/to/your/sources")
or:
unmanagedSourceDirectories in Compile += file("/path/to/your/sources")
use the first when the sources are managed, e.g: if these sources are generated by some other program, or retrieved as a dependency, etc'...
use the second when these are plain sources not managed by anything.

Scala SBT custom lib managed path

Is it possible set custom "lib_managed" path in build.sbt? I would want that command update the puts jar files to the my web folder web/WEB-INF/lib. If sbt does not allows setup custom folder(google finds nothing), what i must add to the build.sbt to copy files from lib_managet folder to my web/.../lib folder?
lib_managed is only a build-local cache and it contains jars for all configurations, such as Test and Compile. It is not appropriate to list its contents and use it as a classpath. There may be duplicates or libraries that shouldn't be on the classpath of interest.

SBT: Simplest way to separate plugins.sbt

This is a very simple question, but I surprisingly havn't gotten an answer for it yet.
Simply put, in most non trivial SBT projects you will have a plugins.sbt file that contains plugins that are required to run your project (like a web container plugin if your SBT project is a website). However in the same file (plugins.sbt), plugins which have nothing to do with actually running your project (such as ensime/intellij/eclipse project generators) are also typically placed in plugins.sbt
I have seen this behavior for many SBT projects which are placed into github
This ideally speaking is not the correct way to do things, ideally plugins which have nothing to do with actually running/compiling your project should be in a separate file which is put into a .gitignore
What is the idiomatic SBT way of dealing with this (I assume it should be something that consists of having 2 separate plugins.sbt files, one with actual project plugins and the other with IDE generators and whatnot)
You can install plugins globally by placing them in ~/.sbt/0.13/plugins/. .sbt or .scala files located here are loaded for every project that you have.
You can also use addSbtPlugin() in a .sbt file to add other plugins.
Check out http://www.scala-sbt.org/release/docs/Getting-Started/Using-Plugins.html

Sbt building distribution for a project

Is there an easy way to create a distribution for a SBT project, which collects all dependency jars into a single directory like lib and the main project jar file refers to all its dependencies using manifest entries? It would be nice if one could define a main class.
This answere says how to do part of what you want. Namely get the managed dependencies into lib_managed directory. Basically just add:
retrieveManaged := true
to your build.sbt file.
Alternatively you could look at a One-jar plugin https://github.com/sbt/sbt-onejar It might do a bit more than you want though.