setting run / baseDirectory from command line - sbt

The run / baseDirectory can be set in build.sbt as follows:
run / baseDirectory := file("path")
Is it possible to set this path from the command line? If not, it would be a very useful feature to add. Thanks.

It is possible:
sbt> set run/baseDirectory := sbt.file("path")
or
> sbt 'set run/baseDirectory := sbt.file("path")' shell # or other command

Related

Build docker image with custom config with sbt-native-packager

I am building my docker image for my scale application with sbt-native-packager.
Now I need to introduce staging and followed the recipe from the sbt-native-packager site. The problem is, that the the mapped application.conf is not picked up on boot.
I have adjusted the build.sbt from the recipe by the main class.
lazy val testPackage = project
.in(file("build/test"))
.enablePlugins(JavaAppPackaging)
.settings(
name := "app-dev",
mainClass := Some("Main"),
resourceDirectory in Compile := (resourceDirectory in (app, Compile)).value,
mappings in Universal += {
((resourceDirectory in Compile).value / "test.conf") -> "conf/application.conf"
}
).dependsOn(app)
I build the docker image as followed: testPackage/docker:publishLocal
I also played around with the bash_template file and added the -D parameter to pass the config file location (-Dconfig.file=${{chdir}}/conf/application.conf), but I did not get it running this way either.
How is it possible to add the custom application.conf to the class path?

sbt aspectj with native packager

I'm attempting to use the sbt-aspectj plugin with the sbt native packager and am running into an issue where the associated -javaagent path to the aspectj load time weaver jar references an ivy cache location rather than something packaged.
That is, after running sbt stage, executing the staged application via bash -x target/universal/stage/bin/myapp/ results in this javaagent:
exec java -javaagent:/home/myuser/.ivy2/cache/org.aspectj/aspectjweaver/jars/aspectjweaver-1.8.10.jar -cp /home/myuser/myproject/target/universal/stage/lib/org.aspectj.aspectjweaver-1.8.10.jar:/home/myuser/myproject/target/universal/stage/lib/otherlibs.jar myorg.MyMainApp args
My target platform is Heroku where the artifacts are built before being effectively 'pushed' out to individual 'dynos' (very analogous to a docker setup). The issue here is that the resulting -javaagent path was valid on the machine in which the 'staged' deployable was built, but will not exist where it's ultimately run.
How can one configure the sbt-aspectj plugin to reference a packaged lib rather than one from the ivy cache?
Current configuration:
project/plugins.sbt:
addSbtPlugin("com.typesafe.sbt" % "sbt-aspectj" % "0.10.6")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.1.5")
build.sbt (selected parts):
import com.typesafe.sbt.SbtAspectj._
lazy val root = (project in file(".")).settings(
aspectjSettings,
javaOptions in Runtime ++= { AspectjKeys.weaverOptions in Aspectj }.value,
// see: https://github.com/sbt/sbt-native-packager/issues/598#issuecomment-111584866
javaOptions in Universal ++= { AspectjKeys.weaverOptions in Aspectj }.value
.map { "-J" + _ },
fork in run := true
)
Update
I've tried several approaches including pulling the relevant output for javaOptions from existing mappings, but the result is a cyclical dependency error thrown by sbt.
I have something that technically solves my problem but feels unsatisfactory. As of now, I'm including an aspectjweaver dependency directly and using the sbt-native-packager concept of bashScriptExtraDefines to append an appropriate javaagent:
updated build.sbt:
import com.typesafe.sbt.SbtAspectj._
lazy val root = (project in file(".")).settings(
aspectjSettings,
bashScriptExtraDefines += scriptClasspath.value
.filter(_.contains("aspectjweaver"))
.headOption
.map("addJava -javaagent:${lib_dir}/" + _)
.getOrElse(""),
fork in run := true
)
You can add the following settings in your sbt config:
.settings(
retrieveManaged := true,
libraryDependencies += "org.aspectj" % "aspectjweaver" % aspectJWeaverV)
AspectJ weaver JAR will be copied to ./lib_managed/jars/org.aspectj/aspectjweaver/aspectjweaver-[aspectJWeaverV].jar in your project root.
I actually solved this by using the sbt-javaagent plugin to adding agents to the runtime

How does sbt filter dependencies

I'm trying to add appengine-maven-plugin to my plugin as a compile time dependency.
If I run
show update
in the sbt console the dependecy is there, but if I run
show managedClasspath
it is not there anymore and I cannot figure out why.
Here is a minimal build.sbt file which shows this behaviour.
sbtPlugin := true
name := "test1"
organization := "com.cornim"
version := "0.1"
libraryDependencies += "com.google.appengine" % "appengine-maven-plugin" % "1.9.51"
Any ideas would be much appreciated.
P.S.: I'm on sbt v0.13.15

How to download sbt plugin depdendency without SBT version in the dependency URL?

I'm trying to use an sbt plugin that I've published in my private mavenrepository
The plugin is configured as following :
val buildSettings = Defaults.defaultSettings ++
Seq (organization := buildOrganization,
scalaVersion := buildScalaVersion,
version := buildVersion,
publishMavenStyle := true,
pomIncludeRepository := { _ => true },
scalacOptions ++= Seq("-deprecation", "-unchecked", "-encoding", "utf8"),
publishTo := Some("External" at "http://xx.yy.net/archiva/repository/external"),
credentials += Credentials(Path.userHome / ".sbt" / ".credentials")
)
With "sbt publish", the plugin is deployed here :
http://xx.yy.net/archiva/repository/external/templemore/sbt-cucumber-parent_2.10/0.8.0/sbt-cucumber-parent_2.10-0.8.0.pom
Then I use my plugin from another SBT app. In my plugins.sbt, I add :
addSbtPlugin("templemore" %% "sbt-cucumber-plugin" % "0.8.0")
But it fails because SBT (or Ivy) is looking at an URL with teh SBT version of the plugin (0.13) inside :
tried
[warn] http://xx.yy.net/archiva/repository/external/templemore/sbt-cucumber-plugin_2.10_0.13/0.8.0/sbt-cucumber-plugin-0.8.0.pom
1) How can I prevent SBT to add its version in the dependency URL?
2) Or, if 1 is not possible, how can I set my SBT plugin configuration to deploy the artifact to archiva with the right URL pattern?
Thanks :)
Based on your comment, you have to publish it with sbt-cucumber-plugin/publish, which will execute publish in a sub-project sbt-cucumber-plugin of the parent project.

Specifying rootProject in build.sbt

In my Build.scala, I have:
override def rootProject = Some(frontendProject)
I'm trying to convert to the newer build.sbt format, but don't know the equivalent of this line. How do I set the project for sbt to load by default when using build.sbt?
I'm still not sure that I understood you right, but you said about multi-project build, so I assume that you want to define a root project which aggregates subprojects. Here is how you can do that (in your root build.sbt):
lazy val root = project.in( file(".") ).aggregate(subProject1, subProject2)
lazy val subProject1 = project in file("subProject1")
lazy val subProject2 = project in file("subProject2")
See sbt documentation about multi-projects.
Then if you want to set the default project to load on sbt startup to a sub-project, in addition to your answer to this SO question, I can suggest
run sbt with sbt "project XXX" shell command
or adding this line to your build.sbt:
onLoad in Global := { Command.process("project XXX", _: State) } compose (onLoad in Global).value
In both cases sbt first loads the root project and then the subproject.
I've found the following script to be helpful:
#!/usr/bin/env bash
exec "sbt" "project mysubproject" "shell"
exit $?

Resources