How does one build a custom Bootstrap WebJar with sbt? - sbt

I want to build a WebJar that contains a brand-customized version of Bootstrap from LESS source. I have sbt.version=0.13.5-M4 in project/build.properties and addSbtPlugin("com.typesafe.sbt" % "sbt-less" % "1.0.0-M2a") in project/plugins.sbt. My build.sbt looks like this:
import com.typesafe.web.sbt.WebPlugin
import com.typesafe.jse.sbt.JsEnginePlugin
import com.typesafe.web.sbt.WebPlugin.WebKeys
name := "brand-assets"
organization := "com.example"
version := "0.0.1-SNAPSHOT"
WebPlugin.webSettings
JsEnginePlugin.jsEngineSettings
lazy val root = (project in file(".")).addPlugins(SbtWeb)
excludeFilter in Assets := new PatternFilter("""[^_].*\.less""".r.pattern)
The errors I get are:
build.sbt:1: error: object web is not a member of package com.typesafe
import com.typesafe.web.sbt.WebPlugin
^
build.sbt:2: error: object sbt is not a member of package com.typesafe.jse
import com.typesafe.jse.sbt.JsEnginePlugin
^
build.sbt:15: error: value addPlugins is not a member of sbt.Project
lazy val root = (project in file(".")).addPlugins(SbtWeb)
^
sbt.compiler.EvalException: Type error in expression
What am I missing?

So far i unserstand your question, you should add the following line to plugin.sbt:
resolvers += Resolver.typesafeRepo("releases")
as disused at https://github.com/sbt/sbt-less/issues/31

Related

Adding sbt native packager plugin in SBT

I have a very organized build file that is composed of the following scala files:
Build.scala - the main Build file
Dependencies.scala - where I define the dependencies and the versions
BuildSettings.scala - where I define the build settings
plugins.sbt
A snippet of the Build.scala is as below:
import sbt._
import Keys._
object MyBuild extends Build {
import Dependencies._
import BuildSettings._
import NativePackagerHelper._
// Configure prompt to show current project
override lazy val settings = super.settings :+ {
shellPrompt := { s => Project.extract(s).currentProject.id + " > " }
}
// Define our project, with basic project information and library dependencies
lazy val project = Project("my-project", file("."))
.settings(buildSettings: _*)
.settings(
libraryDependencies ++= Seq(
Libraries.scalaAsync
// Add your additional libraries here (comma-separated)...
)
).enablePlugins(JavaAppPackaging, DockerPlugin)
}
All the 4 files that I mentioned above are in the same directory which is inside the project directory. But when I run this build file, I get the following error:
not found value: NativePackagerHelper
Any clues why his this?
I figured out what the problem was. I had to use the following in my build.properties
sbt.version=0.13.11
I originally had 0.13.6 and it was causing the import statements to fail!

Include a simple val in sbt build files from global.sbt

I wish to set my version numbers externally across several build.sbt files through a single include file.
Within build.sbt I can do this
val base = "1.1"
version := base + ".8-SNAPSHOT"
This works fine as a first step.
According the the online help I should be able to create a file global.sbt in my ~/.sbt/0.13 folder
I created the file global.sbt with single line
val base = "1.1"
and removed the corresponding line from build.sbt
But when I start up my sbt I get "error: not found: value base"
So either it's not finding the global sbt or this form of global setting doesn't work.
Any suggestions as to how I can resolve this?
Can I make an explicit include command in my build.sbt files?
It seems from your test that vals in global ~/.sbt/0.13/*.sbt files don't propagate to local *.sbt files.
Here's a setup that works:
~/.sbt/0.13/plugins/VersionBasePlugin.scala
import sbt._, Keys._
object VersionBasePlugin extends AutoPlugin {
override def requires = plugins.CorePlugin
override def trigger = allRequirements
object autoImport {
val versionBase = settingKey[String]("version base")
}
import autoImport._
override def projectSettings = Seq(versionBase := "1.1")
}
and then in your build.sbt:
version := (versionBase.value + ".8-SNAPSHOT")
Does that work for you?

Imports and ill-behaved SBT plugins

I'm trying to define parsers in a build.sbt file.
I'm using this plugin, by adding this line in plugins.sbt:
addSbtPlugin("com.gilt" % "sbt-dependency-graph-sugar" % "0.7.4")
When specifiying this in build.sbt:
import sbt.complete.DefaultParsers._
val servers = token(
literal("desarrollo") |
literal("parametrizacion")
)
SBT complains with this error message:
reference to literal is ambiguous;
reference to token is ambiguous;
it is imported twice in the same scope by
import sbt.complete.DefaultParsers._
and import _root_.gilt.DependencyGraph._
How can I avoid this namespace clashing of basic SBT classes?.
One solution is this:
import sbt.complete.{DefaultParsers ⇒ DP}
import sbt.complete.DefaultParsers._
val servers = DP.token(
DP.literal("desarrollo") |
DP.literal("parametrizacion")
)
I don't fully like it, because it adds clutter.
The ideal solution is to hide unwanted imports.
This solution creates a new scope, so there's no interference with imports:
name := "MyProject"
{
import sbt.complete.DefaultParsers._
val servers = token(
"desarrollo" | "parametrizacion"
)
}

Trouble building a simple SparkSQL application

This is a pretty noob question.
I'm trying to learn about SparkSQL. I've been following the example described here:
http://spark.apache.org/docs/1.0.0/sql-programming-guide.html
Everything works fine in the Spark-shell, but when I try to use sbt to build a batch version, I get the following error message:
object sql is not a member of package org.apache.spark
Unfortunately, I'm rather new to sbt, so I don't know how to correct this problem. I suspect that I need to include additional dependencies, but I can't figure out how.
Here is the code I'm trying to compile:
/* TestApp.scala */
import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._
import org.apache.spark.SparkConf
case class Record(k: Int, v: String)
object TestApp {
def main(args: Array[String]) {
val conf = new SparkConf().setAppName("Simple Application")
val sc = new SparkContext(conf)
val sqlContext = new org.apache.spark.sql.SQLContext(sc)
import sqlContext._
val data = sc.parallelize(1 to 100000)
val records = data.map(i => new Record(i, "value = "+i))
val table = createSchemaRDD(records, Record)
println(">>> " + table.count)
}
}
The error is flagged on the line where I try to create a SQLContext.
Here is the content of the sbt file:
name := "Test Project"
version := "1.0"
scalaVersion := "2.10.4"
libraryDependencies += "org.apache.spark" %% "spark-core" % "1.0.0"
resolvers += "Akka Repository" at "http://repo.akka.io/releases/"
Thanks for the help.
As is often the case, the act of asking the question helped me figure out the answer. The answer is to add the following line in the sbt file.
libraryDependencies += "org.apache.spark" %% "spark-sql" % "1.0.0"
I also realized there is an additional problem in the little program above. There are too many arguments in the call to createSchemaRDD. That line should read as follows:
val table = createSchemaRDD(records)
Thanks! I ran into a similar problem while building a Scala app in Maven. Based on what you did with SBT, I added the corresponding Maven dependencies as follows and now I am able to compile and generate the jar file.
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.11</artifactId>
<version>1.2.1</version>
</dependency>
I got the similar issue, in my case, i just copy pasted the below sbt setup from online with scalaVersion := "2.10.4" but in my environment, i actually have the scala version 2.11.8
so updated & executed sbt package again, issue fixed
name := "Test Project"
version := "1.0"
scalaVersion := "2.10.4"
libraryDependencies += "org.apache.spark" %% "spark-core" % "1.0.0"
resolvers += "Akka Repository" at "http://repo.akka.io/releases/"

How configure aspectj compilation in playframework 2.1.1

I have added to plugins.sbt this declaration
addSbtPlugin("com.typesafe.sbt" % "sbt-aspectj" % "0.9.0")
Now I would like to configure this plugin to compile my java controller classes using aspect library org.springframework:spring-aspects:3.1.4 as with aspectj-maven-plugin
I have set this configuration :
import sbt._
import Keys._
import play.Project._
import com.typesafe.sbt.SbtAspectj._
import com.typesafe.sbt.SbtAspectj.AspectjKeys._
object ApplicationBuild extends Build {
val appDependencies = Seq(javaCore)
val main = play.Project(appName, appVersion, appDependencies).settings(
AspectjKeys.verbose in Aspectj := true,
AspectjKeys.showWeaveInfo in Aspectj := true,
AspectjKeys.inputs in Aspectj <+= compiledClasses
)
}
But it does fail.
[error] Reference to undefined setting:
[error]
[error] aspectj:inputs from aspectj:inputs
I am really a newbie with the sbt thing.
The plugin github page : https://github.com/sbt/sbt-aspectj
Ok, I make it works, thanks to sbt mailing list, cf. https://groups.google.com/forum/?fromgroups=#!topic/simple-build-tool/MUXyfKigC7w
and the playframework mailing list also, cf. https://groups.google.com/forum/?fromgroups=#!topic/play-framework/RfJFEwVbUUk
It was not very hard in fact but something you can't see things.
import sbt._
import Keys._
import play.Project._
import com.typesafe.sbt.SbtAspectj._
import com.typesafe.sbt.SbtAspectj.AspectjKeys._
object ApplicationBuild extends Build {
val appDependencies = Seq(javaCore, filters)
val main = play.Project(appName, appVersion, appDependencies)
.settings(aspectjSettings: _*)
.settings(
libraryDependencies += "org.springframework" % "spring-aspects" % "3.1.4.RELEASE",
libraryDependencies += "org.springframework.security" % "spring-security-aspects" % "3.1.4.RELEASE",
sourceLevel := "-1.7",
verbose in Aspectj := false,
showWeaveInfo in Aspectj := false,
inputs in Aspectj <+= compiledClasses,
binaries in Aspectj <++= update map { report =>
report.matching(
moduleFilter(organization = "org.springframework", name = "spring-aspects")
|| moduleFilter(organization = "org.springframework.security", name = "spring-security-aspects")
)
},
products in Compile <<= products in Aspectj,
products in Runtime <<= products in Compile
)
}
Don't forget to add this in in plugins.sbt, with a new line separator between declaration
addSbtPlugin("com.typesafe.sbt" % "sbt-aspectj" % "0.9.0")

Resources