Why does Play build give "No trace dependencies for Activator" after adding plugins? - sbt

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.

Related

Execute sbt task without prior compiling (for generating database classes with JOOQ)

I have a PlayFramework 2.7 application which is build by sbt.
For accessing the database, I am using JOOQ. As you know, JOOQ reads my database schema and generates the Java source classes, which then are used in my application.
The application only compiles, if the database classes are present.
I am generating the classes with this custom sbt task:
// https://mvnrepository.com/artifact/org.jooq/jooq-meta
libraryDependencies += "org.jooq" % "jooq-meta" % "3.12.1"
lazy val generateJOOQ = taskKey[Seq[File]]("Generate JooQ classes")
generateJOOQ := {
(runner in Compile).value.run("org.jooq.codegen.GenerationTool",
(fullClasspath in Compile).value.files,
Array("conf/db.conf.xml"),
streams.value.log).failed foreach (sys error _.getMessage)
((sourceManaged.value / "main/generated") ** "*.java").get
}
I googled around and found the script above and modified it a little bit according to my needs, but I do not really understand it, since sbt/scala are new to me.
The problem now is, when I start the generateJOOQ, sbt tries to compile the project first, which fails, because the database classes are missing. So what I have to do is, comment all code out which uses the generated classes, execute the task which compiles my project, generates the database classes and then enable the commented out code again. This is a pain!
I guess the problem is the command (runner in Compile) but I did not find any possibility to execute my custom task WITHOUT compiling first.
Please help! Thank you!
Usually, when you want to generate sources, you should use a source generator, see https://www.scala-sbt.org/1.x/docs/Howto-Generating-Files.html
sourceGenerators in Compile += generateJOOQ
Doing that automatically causes SBT to execute your task first before trying to compile the Scala/Java sources.
Then, you should not really use the runner task, since that is used to run your project, which depends on the compile task, which needs to execute first of course.
You should add the jooq-meta library as a dependeny of the build, not of your sources. That means you should add the libraryDependencies += "org.jooq" % "jooq-meta" % "3.12.1" line e.g. to project/jooq.sbt.
Then, you can simply call the GenerationTool of jooq just as usually in your task:
// build.sbt
generateJOOQ := {
org.jooq.codegen.GenerationTool.main(Array("conf/db.conf.xml"))
((sourceManaged.value / "main/generated") ** "*.java").get
}

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

Apache commons-imaging;1.0-SNAPSHOT: not found

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.

Sbt, local sbt plugin, using jooq code generation plugin

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.

How do you do develop an SBT project, itself?

Background: I've got a Play 2.0 project, and I am trying to add something to do aspectj weaving using aspects in a jar on some of my classes (Java). (sbt-aspectj doesn't seem to do it, or I can't see how). So I need to add a custom task, and have it depend on compile. I've sort of figured out the dependency part. However, because I don't know exactly what I'm doing, yet, I want to develop this using the IDE (I'm using Scala-IDE). Since sbt projects (and therefore Play projects) are recursively defined, I assumed I could:
Add the eclipse plugin to the myplay/project/project/plugins.sbt
Add the sbt main jar (and aspectj jar) to myplay/project/project/build.sbt:
libraryDependencies ++= Seq(
"org.scala-sbt" % "main" % "0.12.2",
"aspectj" % "aspectj-tools" % "1.0.6"
)
Drop into the myplay/project
Run sbt, run the eclipse task, then import the project into eclipse as a separate project.
I can do this, though the build.scala (and other scala files) aren't initially considered source, and I have to fiddle with the build path a bit. However, even though I've got the sbt main defined for the project, both eclipse IDE and the compile task give errors:
> compile
[error] .../myplay/project/Build.scala:2: not found: object keys
[error] import keys.Keys._
[error] ^
[error] .../myplay/project/SbtAspectJ.scala:2: object Configurations is not a member of package sbt
[error] import sbt.Configurations.Compile
[error] ^
[error] .../myplay/project/SbtAspectJ.scala:3: object Keys is not a member of package sbt
[error] import sbt.Keys._
[error] ^
[error] three errors found
The eclipse project shows neither main nor aspectj-tools in its referenced-libraries. However, if I give it a bogus version (e.g. 0.12.4), reload fails, so it appears to be using
the dependency.
So,...
First: Is this the proper way to do this?
Second: If so, why aren't the libs getting added.
(Third: please don't let this be something dumb that I missed.)
If you are getting the object Keys is not a member of package sbt error, then you should check that you are running sbt from the base directory, and not the /project directory.
sbt-aspectj
sbt-aspectj doesn't seem to do it, or I can't see how.
I think this is the real issue. There's a plugin already that does the work, so try making it work instead of fiddling with the build. Using plugins from build.scala is a bit tricky.
Luckily there are sample projects on github:
import sbt._
import sbt.Keys._
import com.typesafe.sbt.SbtAspectj.{ Aspectj, aspectjSettings, compiledClasses }
import com.typesafe.sbt.SbtAspectj.AspectjKeys.{ binaries, compileOnly, inputs, lintProperties }
object SampleBuild extends Build {
....
// precompiled aspects
lazy val tracer = Project(
"tracer",
file("tracer"),
settings = buildSettings ++ aspectjSettings ++ Seq(
// stop after compiling the aspects (no weaving)
compileOnly in Aspectj := true,
// ignore warnings (we don't have the sample classes)
lintProperties in Aspectj += "invalidAbsoluteTypeName = ignore",
// replace regular products with compiled aspects
products in Compile <<= products in Aspectj
)
)
}
How do you do develop an SBT project, itself?
If you're interested in hacking on the build still the first place to go is the Getting Started guide. Specifically, your question should be answered in .scala Build Definition page.
I think you want your build to utilize "aspectj" % "aspectj-tools" % "1.0.6". If so it should be included in myplay/project/plugins.sbt, and your code should go into myplay/project/common.scala or something. If you want to use IDE, you have have better luck with building it as a sbt plugin. That way your code would go into src/main/scala. Check out sbt/sbt-aspectj or sbt/sbt-assembly on example of sbt plugin structure.

Resources