2

I am trying to replace simple Maven project to SBT project. But I have faced few problems. In maven I have several profiles for project like

 <profile>
                <id>name</id>
                <properties>
                    <tomcatHome>/apache-tomcat-7.0.42</tomcatHome>
                    <config.folder>/conf/</config.folder>
                    <data.folder>/conf/data</data.folder>
                </properties>
            </profile>

this profiles can be changed for different builds in maven

mvn package -P name

or can be used by Intellij Idea for embedded maven build and server launching

Also properties can be used in spring config (through placeholders).

<context:property-placeholder location="file:${config.folder} />

How can i write similar configuration for sbt? I did not find anything similar in the documentation Thanks

Alexandr
  • 349
  • 1
  • 4
  • 13

1 Answers1

2

In sbt file you can use scala syntax.

Simple example.

val akkaVersion = util.Properties.propOrNone("akka.version").getOrElse("2.4.3")

libraryDependencies += "com.typesafe.akka" %% "akka-actor" % akkaVersion

When you call sbt the version will be set to default "2.4.3". But when you call:

sbt -Dakka.version=2.3.13 you version 2.3.13 will be used.

Next example with xsbt-web-plugin. You can choose either JettyPlugin or TomcatPlugin.

val containerPlugin = util.Properties.propOrNone("use.tomcat").
                    map(_ => TomcatPlugin).getOrElse(JettyPlugin)

enablePlugins(containerPlugin)

When you call: sbt -Duse.tomcat TomcatPlugin will be used. Otherwise JettyPlugin.

Andrzej Jozwik
  • 14,331
  • 3
  • 59
  • 68
  • main question is: how can I pass arguments from **.sbt** file (like `/conf/data` from **.pom** file) to **spring** context (` – Alexandr Apr 14 '16 at 00:22