SBT - What is the difference between name and id? - scala

I was wondering if there is a difference in SBT between a project's name and id.
I noticed example build.sbt files with the following key:
name := "My Project"
And I noticed Build.scala files with:
Project(id = "My Project", base = file("."))
Is there a difference? Should the two be the same or is it irrelevant? What are they used for?
Thanks!

Project name should be used for the name of your project, the visible title for any documentation.
Id is used to refer to the project to modify settings or in terms of dependancy management, i.e to connect a subproject to a root project you can say subproject.dependsOn(rootProjectId)

In your build.sbt file you have a single project definition. You can also pass a name attribute to the settings of a Project in your build.scala. As you can have several sub projects in a build file, you have to provide an id for each of them, while the project name remains the same.

Related

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/"

sbt task to increment project version

Is there an SBT task to increment a project's version?
Given an initial configuration of something like the following build.sbt
name := 'My Project'
organization := 'org.example'
version := '0.1.0'
and a versioning nomenclature of major.minor.patch, I was hoping for an SBT task like
> incrementVersionPatch
that would result in a version of 0.1.1.
(Ideally also the corresponding incrementVersionMinor and incrementVersionMajor.)
I feel like this must already exist but cannot find a way to do it.
I think what you need is sbt-release plugin that "provides a customizable release process that you can add to your project." with "the setting release-version-file, which is set to file("version.sbt") by default and points to $PROJECT_ROOT/version.sbt".

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.

Change 'play dist' output file name via command-line

Is it possible to change play dist output file name apart from modifying appName on Build.scala?
I'm trying to automate the creation of two different zip files from the same project tree, e.g.: myapp-production-1.0-SNAPSHOT.zip and myapp-integration-1.0-SNAPSHOT.zip.
Thank you very much!
For Play Framework 2.4 changing the name of the output file worked like this in build.sbt:
packageName in Universal := "dist"
In Play Framework 2.2, you can add the following line to the build.sbt file:
name in Universal := "dist"
Your app will be packaged in target/universal/dist.zip
You can modify the output by changing the build.sbt file in your project directory.
name := "myname"
version := "1.0-SNAPSHOT"
Remember to recompile, might have to clean too.

Missing required library classes_managed

Im using play 2.0 and trying to modularize the project into a subproject.
In $project_home, created folder structure ${project_home}/data/app/models/MyModel.java
The Build.scala looks
val dataDependencies = Seq(
)
val dataProject = PlayProject(appName + "-data", appVersion, dataDependencies, path = file("data"), mainLang = JAVA)
val main = PlayProject(appName, appVersion, appDependencies, mainLang = JAVA).settings(
// Add your own project settings here
).dependsOn(dataProject).aggregate(dataProject)
I run a play eclpsify command.
In eclipse, I've imported two projects, the main project and the data project.
The data project shows the following error
Project '-data' is missing required library: '/path/to/myprojects/data/target/scala-2.9.1/classes_managed'
What am I doing wrong here? Any help would be appreciated
This is what worked for me (on Windows).
Edit .classpath, there should be an entry similar to this:
<classpathentry path="D:\your_play_project_folder\target\scala-2.10\classes_managed" kind="lib"></classpathentry>
Remove the path portion before "target" to get this:
<classpathentry path="target\scala-2.10\classes_managed" kind="lib"></classpathentry>
Refresh Eclipse.
I encountered the similar problem when building a project with play 2.0.2
I created manually the target/scala-2.9.1/classes_managed folder and I run clean all projects in eclipse
I hope it helps
I think you have 3 possibilities:
create data/target/scala-2.9.1/classes_managed manually.
Remove the path from class-path (if not necessary)
Switch to 2.1-snapshot
For me helped:
manually removed target/scala-2.9.1/classes_managed from the .classpath file
added target/scala-2.9.1/classes_managed via eclipse: project/properties/Java Build Path --> tab Libraries --> Add Class Folder...
Try "play clean" and then "play eclipse", to re-generate the eclipse project files from a command prompt in the project's base folder.
try this:
1) sbt> clean/compile in parent, followed by child project
2) add target/src-managed/main as source folder in eclipse, both projects
3) in child
java build path > projects > (add parent)
project references > (add parent)
What does dataProject do, btw? My base project provides a DAO layer and other nuts & bolts that have nothing to do with Play; therefore, I just define it as a root sbt project, and pull it in to child project via dependsOn(root)
Anyway, hope this gets the issue sorted...