How can SBT builds be made reliable enough to use in a production environment?
Specifically, SBT normally builds without a problem, but every few weeks, the commons-imaging dependency is not found, halting the entire build.
In build.sbt:
libraryDependencies ++= Seq(
, "commons-io" % "commons-io" % "2.4"
, "org.apache.commons" % "commons-imaging" % "1.0-SNAPSHOT" withSources ()
)
resolvers in ThisBuild ++= Seq(
"Apache Development Snapshot Repository" at "https://repository.apache.org/content/repositories/snapshots/"
)
sbt.ResolveException: unresolved dependency: org.apache.commons#commons-imaging;1.0-SNAPSHOT: not found
This usually works fine. But recently started giving:
[warn] Unable to reparse org.apache.commons#commons-imaging;1.0-SNAPSHOT from Apache Development Snapshot Repository
(1) Why would it be so intermittent? Is it the Resolver URL that changes, or the Web site that serves the commons-imaging jar going down? (other maven resources are found without ever experiencing a hiccup.)
(2) What can be done to ensure that clean builds always succeed? (This is crucial for spinning up a new instance and expecting it to succeed.)
Edit: This doesn't answer the question, but I found a workaround for this particular issue in that deleting "withSources()" allows the build to succeed.
Related
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
I'm using spray to create a single page app, and cannot get sbt-web to process any of my inputs. I started with WebJars, because, https://github.com/sbt/sbt-web/blob/master/README.md says:
One last thing regarding the public and public-test folders... any WebJar depended on by the project will be automatically extracted into these folders e.g. target/web/public/lib/jquery/jquery.js.
However, I see no such "web" folder in the target folder. I thought maybe WebJars was too complicated of an example to start with, so I instead added a jquery.js file to the root of the asset folder, and set up sbt-uglify to do some processing on it. Yet, still, I see no evidence that SbtWeb is working. I've run sbt --debug clean run and grepped the output for any output from SbtWeb or Uglify, but no errors or warnings and can't find anything wrt SbtWeb or Uglify. Just acknowledgement that it seems to "deduce" the plugins:
[debug] deducing auto plugins based on known facts [debug] :: sorting:: found:
...
[debug] :: sorted deduced result: List(sbt.plugins.CorePlugin, com.typesafe.sbt.web.SbtWeb, com.typesafe.sbt.jse.SbtJsEngine, net.ground5hark.sbt.concat.SbtConcat, sbt.plugins.IvyPlugin, com.typesafe.sbt.jse.SbtJsTask, sbt.plugins.JvmPlugin, com.typesafe.sbt.uglify.SbtUglify, sbt.plugins.JUnitXmlReportPlugin)
Here is my directory structure:
./build.sbt
./project/plugins.sbt
./src/main/assets/js/jquery.js
./src/main/resources/html/uikit/login.html
./src/main/scala/Boot.scala
./src/main/scala/main.scala
Here is my project/plugins.sbt:
resolvers += Resolver.sonatypeRepo("releases")
addSbtPlugin("com.typesafe.sbt" % "sbt-web" % "1.0.2")
addSbtPlugin("net.ground5hark.sbt" % "sbt-concat" % "0.1.8")
addSbtPlugin("com.typesafe.sbt" % "sbt-uglify" % "1.0.3")
Here is my ./build.sbt:
organization := "com.test123.spray"
version := "0.1"
scalaVersion := "2.11.6"
scalacOptions := Seq("-unchecked", "-deprecation", "-encoding", "utf8")
libraryDependencies ++= {
val akkaV = "2.3.9"
val sprayV = "1.3.3"
Seq(
"io.spray" %% "spray-can" % sprayV,
"io.spray" %% "spray-routing" % sprayV,
"io.spray" %% "spray-testkit" % sprayV % "test",
"com.typesafe.akka" %% "akka-actor" % akkaV,
"com.typesafe.akka" %% "akka-testkit" % akkaV % "test",
// client side dependencies
"org.webjars" % "jquery" % "2.1.4",
"org.webjars" % "uikit" % "2.24.2"
)
}
lazy val root = (project.in(file("."))).enablePlugins(SbtWeb)
pipelineStages := Seq(uglify)
includeFilter in uglify := GlobFilter("js/*.js")
Here is what the root of my ./target folder looks like:
resolution-cache/
scala-2.11/
streams/
No ./target/web folder. Any ideas why?
References:
https://github.com/sbt/sbt-web/blob/master/README.md
http://mariussoutier.com/blog/2014/12/07/understanding-sbt-sbt-web-settings/
That'll learn me. I was using an old version of sbt-web. When I update it to the latest, it works as expected.
The lesson is not to copy/paste snippets like this:
addSbtPlugin("com.typesafe.sbt" % "sbt-web" % "1.0.2")
from the web. But, rather to find the latest version, manually, by one of the following methods:
If the GitHub (et al) page has a "Build Passing" badge, click on it to navigate to the build server where the latest versions are listed.
Look at the branches in GitHub
See if you can navigate to the repository for the dependency, such as Maven Central, and browse there. I didn't have luck with this one. The problem I had is that I knew it wasn't on Maven, and didn't know where else to look.
Plug in some bogus version in SBT, and look at the output for where SBT tried to look and failed:
[warn] module not found: com.typesafe.sbt#sbt-web;3.1.2
[warn] ==== typesafe-ivy-releases: tried
[warn] http://repo.typesafe.com/typesafe/ivy-releases/com.typesafe.sbt/sbt-web/scala_2.10/sbt_0.13/3.1.2/ivys/ivy.xml
[warn] ==== sbt-plugin-releases: tried
[warn] http://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/com.typesafe.sbt/sbt-web/scala_2.10/sbt_0.13/3.1.2/ivys/ivy.xml
I'm positive there are better ways to find the latest versions of things that I'm just unaware of. For those more experienced than me please comment with a better way.
Environment: Play framework; activator-1.3.2; Play-Java Web Application
build.sbt -
name := """ProjectDemoNew"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava)
scalaVersion := "2.11.1"
resolvers +="Local Maven Repository" at "file:///home/shiva/.m2/repository"
libraryDependencies ++= Seq(
javaJdbc,
javaEbean,
cache,
javaWs,
"org.springframework" % "spring-context" % "3.2.3.RELEASE",
"org.springframework" % "spring-aop" % "3.2.3.RELEASE",
"org.springframework" % "spring-expression" % "3.2.3.RELEASE",
"org.springframework" % "spring-test" % "3.2.3.RELEASE",
"com.mycomp.config"%"platform-config"%"0.0.1-SNAPSHOT"
)
$ activator run
gives the following error(s) when the internet is down..
--
--
[info] You probably access the destination server through a proxy server that is not well configured.
[warn] Host repo.typesafe.com not found. url=https://repo.typesafe.com/typesafe/releases/com/mycomp/conf/i/platform-config/0.0.1-SNAPSHOT/...-SNAPSHOT.pom
--
--
I am not seeing any errors in case the internet is up.
There are lots of posts, but the answers seem to vary a lot.
All jars ( spring, application-specific, third party..) are in my local repository. But it always connects internet for refreshing dependencies, build is slow when the internet speed is not good
How to make Play go through Local repository without going through internet/offline? This helps me doing the build quickly with no or weak internet connectivity.
It automatically checks the internet for SNAPSHOT dependencies.
If you don't want it to do it, add :
offline := true
to your build.sbt file.
I started with the latest Typesafe Activator download using the play-scala template.
Activator 1.2.10
Akka 2.3.4
Play 2.3.4
Scala 2.11.1
Then I modified build.sbt file to add play2-reactivemongo with
"org.reactivemongo" % "play2-reactivemongo_2.11" % "0.10.5.akka23-SNAPSHOT"
, but it failed with No trace dependencies for Activator.
I removed play2-reactivemongo and tried play-silhouette and received the same error.
"com.mohiva" % "play-silhouette_2.11" % "1.1-SNAPSHOT"
The app builds with neither plugin added.
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.11.1"
resolvers += "Sonatype Snapshots" at "https://oss.sonatype.org/content/repositories/snapshots/"
libraryDependencies ++= Seq(
// "com.mohiva" % "play-silhouette_2.11" % "1.1-SNAPSHOT",
// "org.reactivemongo" % "play2-reactivemongo_2.11" % "0.10.5.akka23-SNAPSHOT",
jdbc,
anorm,
cache,
ws
)
The output from Play Framework tells me nothing beyond that one line as best I can tell. Maybe there is better information leading to a solution, but I have not been able to find it. Any ideas?
CORRECTION: now when I disable the resolver line, disable the play-silhouette line, and disable the reactivemongo line, the same error message appears. Yet, it once compiled successfully.
The error is from the sbt-echo plugin here:
https://github.com/typesafehub/sbt-echo/blob/3f431a9748a45fcb328efe4d5f989a99b5c8f7f2/akka/src/main/scala/com/typesafe/sbt/echo/EchoRun.scala#L95
I improved this error message just the other day, incidentally, but you don't have it yet:
https://github.com/typesafehub/sbt-echo/blob/master/akka/src/main/scala/com/typesafe/sbt/echo/EchoRun.scala#L118
activator's ui mode (activator ui) adds the sbt-echo plugin in order to power the Inspect tab. You can remove the plugin again (by deleting the .sbt file for it in project/) if you are not currently using UI mode, to fix this.
If you are using UI mode, to fix this you need akka and play to have versions which are understood by sbt-echo. This may mean downgrading to 2.3.3 for now, we are a little behind on updating the tracing.
I'm trying to use jooq-sbt-plugin to generate some code.
I downloaded the code, compiled it and copied jar into lib directory, but on sbt load i get this error:
[warn] Note: Some unresolved dependencies have extra attributes. Check that th
ese dependencies exist with the requested attributes.
[warn] sean8223:jooq-sbt-plugin:1.4 (sbtVersion=0.13, scalaVersion=2.10
)
in project/plugins.sbt i have this
resolvers += Resolver.file("lib-repo", file("lib")) transactional()
addSbtPlugin("lib-repo" %% "jooq-sbt-plugin" % "1.4")
Is this plugin "detected" and cannot be loaded or sbt does't see it?
P.S.
By default plugin does not work because it depends on jooq-3.2.1 which is not available on maven and I get error - unresolved dependencies. According to plugin readme i could set jooqVersion in build.sbt to other version, but this doesn't seem to work.
In my project/plugins.sbt:
resolvers += "sean8223 Releases" at "https://github.com/sean8223/repository/raw/master/releases"
addSbtPlugin("sean8223" %% "jooq-sbt-plugin" % "1.3")
In my build.sbt:
seq(jooqSettings:_*)
jooqVersion := "3.3.1"
And everything is successfully resolved. I didn't run any tasks, but since you say that the problem is in resolving jooq, show your build.sbt if it still doesn't work for you.