I'm developing a Scalatra web app with Scalate Jade and using sbt 0.11.0
I've been packaging the web app with "com.github.siasia" %% "xsbt-web-plugin" % "0.1.2".
I've also been experimenting with "com.zentrope" %% "xsbt-scalate-precompile-plugin" % "1.6" to compile the Jade files.
Unfortunately if I use the xsbt-web-plugin to package my war it clears the target directory from any precompiled Scalate files.
What is the best way to package a war with precompiled Scalate files?
Thanks to Keith Irwin, the author of xsbt-scalate-precompile-plugin, I now have a solution to my problem.
My Jade/Scalate files are in webapp/WEB-INF/template and webapp/WEB-INF/scalate/layouts directories.
I'm using the xsbt-web-plugin and xsbt-scalate-precompile-plugin sbt plugins.
xsbt-web-plugin provides me with the package-war command.
xsbt-scalate-precompile-plugin pre-compiles my Jade files.
In my plugins.sbt file.
resolvers += "Web plugin repo" at "http://siasia.github.com/maven2"
addSbtPlugin("com.github.siasia" %% "xsbt-web-plugin" % "0.1.2")
resolvers += "zentrope" at "http://zentrope.com/maven"
addSbtPlugin("com.zentrope" %% "xsbt-scalate-precompile-plugin" % "1.7")
In my build.scala file.
import WebPlugin._
import Keys._
import com.zentrope.ScalatePlugin._
...
// WebApp Settings
val webAppSettings = Seq(
jettyPort := 8083,
jettyContext := "/MyWebApp"
)
// Scalate Compile Settings
val scalateCompileSettings = scalateTemplateSettings ++ Seq(
scalateTemplateDirectories in Compile <<= (scalateTemplateDirectories in Compile, baseDirectory) {
(dirs, basedir) => dirs ++ Seq(new File(basedir, "/src/main/webapp/WEB-INF/template"),
new File(basedir, "/src/main/webapp/WEB-INF/scalate/layouts"))
}
)
...
lazy val MyWebApp =
Project("MyWebApp", file("MyWebApp"), settings = shared ++ webAppSettings ++ scalateCompileSettings ++ Seq(
resolvers ++= Seq(sonatypeNexusReleases, scalaToolsNexus, novusRels, scalaToolsSnapshots),
libraryDependencies ++= Seq(
scalatra,
scalate,
...
)
))
The 1.7 version of Keiths' plugin allows for the setting of specific template directories which is what I really needed. The only caveat is that I must do a clean right before I call package-war or my compiled Jade files get removed.
I'm not sure I understand you here. Anything that's source should be in src. One should never put anything in target. Resources would naturally go into src/main/resources. So, are these "precompiled" files something that is being automatically generated, or should they have been in the resources directory?
Related
Is there a standard in place for setting up a Scala project where the build.sbt is contained in a subdirectory?
I've cloned https://github.com/lightbend/cloudflow and opened it in IntelliJ, here is the structure:
Can see core contains build.sbt.
If I open the project core in a new project window then IntelliJ will recognise the Scala project.
How to compile the Scala project core while keeping the other folders available within the IntelliJ window?
EDIT:
If you do want to play around with the project, it should suffice to either import an SBT project and select core as the root. Intellij should also detect the build.sbt if you open core as the root.
Here is the SBT Reference Manual
Traditionally, build.sbt will be at the root of the project.
If you are looking to use their libraries, you should import them in your sbt file, you shouldn't clone the repo unless you intend to modify or fork their repo.
For importing libraries into your project take a look at the Maven Repository for Cloudflow, select the project(s), click on the version you want, and select the SBT tab. Just copy and paste those dependencies into your build.sbt. Once you build the project with SBT, you should have all those packages available to you.
So in [ProjectRoot]/build.sbt something along the lines of
val scalaVersion = "2.13.4"
lazy val root = (project in file("."))
.settings(
name := "Your_Project_Name",
scalaVersion := scalaVersion,
libraryDependencies += "com.lightbend.cloudflow" %% "cloudflow-streamlets" % "2.0.26-RC12",
// Either sequentially
libraryDependencies += "com.lightbend.cloudflow" %% "cloudflow-akka" % "2.0.26-RC12",
// Or as a sequence (note that you can have a trailing comma for these)
libraryDependencies ++= Seq(
"com.lightbend.cloudflow" %% "cloudflow-blueprint" % "2.0.26-RC12",
"com.lightbend.cloudflow" %% "cloudflow-flink" % "2.0.26-RC12", // No next elemenet
)
// Or combo using both like above, just don't forget the commas in between
)
I'm using sbt 1.3.9 and I need to update some libraries that have changed its code but the version stays the same. When I tried to run sbt update command nothing happened the library not downloaded.
I have sbt.build file that looks like the following:
name := """project name"""
organization := "com.example"
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava)
lazy val usr = sys.env("MVN_USER")
scalaVersion := "2.13.1"
javacOptions ++= Seq("-source", "11", "-target", "11")
resolvers ++= Seq(
"Jfrog Artifacts".at("https://artifactory.jfrog.com/")
)
credentials += Credentials(
...
)
updateOptions := updateOptions.value.withCachedResolution(false)
updateOptions := updateOptions.value.withLatestSnapshots(false)
libraryDependencies ++= Seq(
guice,
javaWs,
ehcache,
"com.google.api-client" % "google-api-client" % "1.30.7",
"org.apache.commons" % "commons-lang3" % "3.9",
"redis.clients" % "jedis" % "3.2.0"
)
how can I clear sbt cache?
You can just delete the v1 folder.
The default cache location is platform-dependent:
on Linux, ~/.cache/coursier/v1. This also applies to Linux-based CI
environments, and FreeBSD too.
on OS X, ~/Library/Caches/Coursier/v1.
on Windows, %LOCALAPPDATA%\Coursier\Cache\v1, which, for user Alex,
typically corresponds to
C:\Users\Alex\AppData\Local\Coursier\Cache\v1.
I assuming that you are developing something locally and doing publishLocal - normal repository wouldn't let you override published dependency and snapshots are not cached (sbt checks if newer appeared every time you need to build sth).
In such case start using snapshot versions for the future and/or go to ~/.ivy2/your.organisation/library_scalaVersion and remove whole directory with "bad" version. If library is fetched by Maven (with sbt, unlikely these days) it the same idea but with ~/.m2.
I had experienced this while using IntelliJ. After closing IntelliJ, I used to clear .idea from project folder and reimport project into IntelliJ was helping me.
You can use PrettyClean to clean the all of dev tools caches including SBT.
PrettyClean also cleans the SBT project's target folder.
I am very new to SBT, Breeze and IntelliJ, though I have a decent grasp of Scala and I am trying to install the Breeze library, which I think is managed.
What I've done:
I followed the instructions on this page and added this script to the build.sbt file in my project:
libraryDependencies ++= Seq(
// other dependencies here
"org.scalanlp" %% "breeze" % "0.10",
// native libraries are not included by default. add this if you want them (as of 0.7)
// native libraries greatly improve performance, but increase jar sizes.
"org.scalanlp" %% "breeze-natives" % "0.10"
)
resolvers ++= Seq(
// other resolvers here
"Sonatype Releases" at "https://oss.sonatype.org/content/repositories/releases/"
)
// Scala 2.9.2 is still supported for 0.2.1, but is dropped afterwards.
scalaVersion := "2.11.1" // or 2.10.3 or later
I then ran sbt update in the project directory (via the terminal), and saw that all the pieces of Breeze downloaded.
I then tried re-running sbt update, but this did not trigger another download.
Issue:
The problem is that I cannot access the library via IntelliJ. import breeze._ gives the standard Cannot resolve symbol breeze and I couldn't find any mention of Breeze in "Project Structure." It isn't in the lib directory of the project either.
Am I missing a step?
Sounds like a bug in the IntelliJ project, try removing the .idea directory from the project directory and then re-import the project into IntelliJ using the wizard.
So I've been trying to get IDEA 12.0 to work with Play 2.1.0 and Scala 2.10.0. I've just about given up because it's not working for me the way I want it to. Here is a copy of my build.properties, Build.scala, and plugins.sbt. I followed the approach on the playframework site to execute idea with-sources=yes in the play console. I've also tried adding sbt-idea plugin version 1.3.0-SNAPSHOT as seen in plugins.sbt, but nothing seems to work if I want to reference a new view template I just created or a new route. The only way I can work in IDEA is if I have a console open and run sbt compile, go back to IDEA, and it will refresh itself and recognize the new view templates or routes.
plugins.sbt
logLevel := Level.Warn
scalaVersion := "2.10.0"
// The Typesafe repository
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
// Sonatype snapshots to get sbt-idea 1.3.0-SNAPSHOT
//resolvers += "Sonatype snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/"
// Use the Play sbt plugin for Play projects
addSbtPlugin("play" % "sbt-plugin" % "2.1.0")
//addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.3.0-SNAPSHOT")
build.properties
sbt.version=0.12.2
Build.scala
import sbt._
import Keys._
import play.Project._
object ApplicationBuild extends Build {
val appName = "admin-application"
val appVersion = "1.0-SNAPSHOT"
val appDependencies = Seq(
// Add your project dependencies here,
jdbc,
anorm
)
val main = play.Project(appName, appVersion, appDependencies).settings(
// Add your own project settings here
)
}
If you use IDEA Community edition, there is a SBT Console plugin (see http://plugins.jetbrains.com/plugin?pluginId=5007) that allows you to compile / run your Play project directly in the editor. That's the way I work every day and it is fine (I use the ~run command and then don't care anymore).
You may also add a remote debugger in IDEA that listens to you local server (it it is run with debug mode on) and use it as usual.
If you use IDEA Ultimate edition, JetBrains released a Play Framework plugin that seems to work fine (but I haven't tested it yet). Have a look at these tutorials:
http://confluence.jetbrains.com/display/IntelliJIDEA/Play+Framework+2.0 or
http://www.jamesward.com/2013/01/23/video-create-and-run-play-framework-apps-in-intellij
Hope this helps.
I think this is how it work currently. As suggested by #pedrofurla, you can keep ~run running on sbt/play console. Sadly, IMO there is no other way IntelliJ can compile your scala views automatically.
Just add to project/plugins.sbt the following and re-run play idea
// FIX SBT IDEA PLAY 2.1
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
// Use the Play sbt plugin for Play projects
addSbtPlugin("play" % "sbt-plugin" % "2.1.0")
i'm writing my own scala compiler plugin and using sbt to build the project. is it possible to put the source of that plugin in the same project that needs to be compiled using that plugin?
all the documentation on sbt seems to be concerned with using a plugin that's external to the project. it just seems much easier to test the plugin if they're in the same project. otherwise i have to continuously build the plugin, copy that jar over to the main project, and then compile that.
the documentation i read is at http://code.google.com/p/simple-build-tool/wiki/CompilerPlugins.
Here is an example using SBT 0.13:
object PluginBuild extends Build {
def buildSettings = Seq(
name := "test-compiler-plugin",
scalaVersion := "2.10.3"
)
override def settings = super.settings ++ buildSettings
lazy val codeToBeChecked = project.in(file("code-to-be-checked")).
settings(
scalacOptions += "-Xplugin:" + packageBin.in(Compile).in(thePlugin).value
)
lazy val thePlugin = project.in(file("the-plugin")).settings(
libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value
)
}
I am not shure about what you are doing, but maybe is the project/plugins/src_managed/ diriectory what you are looking for. If the user of the plugin needs some code from the plugin, it can be found there.