How to add newest Akka-HTTP and Akka-stream to build.sbt - sbt

I'm using Typesafe/Lightbend Activator, and created a project with 'minimal-akka-scala-seed'. Then I'd changed akka version from 2.3.11 to 2.4.2 (current stable version).
Now I want to add newest stable Akka-HTTP and Akka-stream to my project. What I should write in build.sbt to do this?

Some of the artifacts are no longer marked as experimental, with the 2.4.2 release.
I believe, that the dependency list should look like this:
libraryDependencies ++= Seq(
// akka
"com.typesafe.akka" %% "akka-actor" % "2.4.2",
"com.typesafe.akka" %% "akka-testkit" % "2.4.2" % "test",
// streams
"com.typesafe.akka" %% "akka-stream" % "2.4.2",
// akka http
"com.typesafe.akka" %% "akka-http-core" % "2.4.2",
"com.typesafe.akka" %% "akka-http-experimental" % "2.4.2",
"com.typesafe.akka" %% "akka-http-testkit" % "2.4.2" % "test",
// the next one add only if you need Spray JSON support
"com.typesafe.akka" %% "akka-http-spray-json-experimental" % "2.4.2",
"org.scalatest" %% "scalatest" % "2.2.4" % "test")

Check this example https://github.com/theiterators/akka-http-microservice. It use newest akka-http version

Related

AspectJ weaving external jar file provided by sbt throws can't determine superclass of missing type

I'm trying to weave the testing library scalatest (https://mvnrepository.com/artifact/org.scalatest/scalatest_2.12/3.2.0-SNAP10). This library dependency is in my build.sbt:
enablePlugins(SbtAspectj)
libraryDependencies += "org.scalactic" %% "scalactic" % "3.0.5"
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % "test"
aspectjInputs in Aspectj ++= update.value.matching(moduleFilter(organization = "com.typesafe.akka", name = "akka-actor*"))
aspectjInputs in Aspectj ++= update.value.matching(moduleFilter(organization = "org.scalatest", name = "scalatest*"))
fullClasspath in Runtime := aspectjUseInstrumentedClasses(Runtime).value ++ aspectjUseInstrumentedClasses(Test).value
Looking at the maven website it lists several other optional dependencies such as org.jmock, etc.
The problem is that SBT only downloads scalatest.jar and not jmock.jar (along the other optional dependencies). Printing out the aspectjInputs indeed does show scalatest.jar, but not jmock.jar.
Because of that reason (?), it gives me the following errors:
[error] error at (no source information available)
[error] /Users/jonas/.ivy2/cache/org.scalatest/scalatest_2.12/bundles/scalatest_2.12-3.0.5.jar:0::0 can't determine superclass of missing type org.jmock.Expectations
[error] when weaving type org.scalatest.jmock.JMockExpectations
[error] when weaving classes
[error] when weaving
[error] when batch building BuildConfig[null] #Files=1 AopXmls=#0
[error] [Xlint:cantFindType]
I'm assuming that I somehow need the .jar file of the optional dependencies of ScalaTest, but as they are not downloaded by sbt, I'm lost on how to solve this.
So, how can I resolve them or add them to the classpath when the weaving happens?
I'm using the aspectj-sbt plugin.
You can include the optional dependencies with a configuration mapping like this:
libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % "test->compile,optional"

How to disable Kamon logging for tests?

Is there a way to use Kamon logging only in running the code, not in tests?
I'm using kamon-log-reporter and kamon-scala on Scala 2.12. My code-under-test uses the Kamon API so I want to have kamon-core both in Runtime and Test. However, I'm not interested in console logging in tests, and sbt-aspectj-runner plugin doesn't seem to launch AspectJ for sbt test (a separate issue).
My setup:
/project/plugins.sbt
resolvers += Resolver.bintrayIvyRepo("kamon-io", "sbt-plugins")
 
addSbtPlugin("io.kamon" % "sbt-aspectj-runner" % "1.0.1")
build.sbt
val kamonVer= "0.6.5"

val kamon = "io.kamon" %% "kamon-core" % kamonVer

val kamonLogging = "io.kamon" %% "kamon-log-reporter" % kamonVer
val kamonAspectJ = "io.kamon" %% "kamon-scala" % kamonVer
libraryDependencies ++= Seq(
kamon, akkaHttp, typesafeConfig, akkaHttpTestkit, scalaTest)
libraryDependencies ++= Seq(kamonLogging, kamonAspectJ)
I've tried this, but it makes logging disappear also in sbt run:
libraryDependencies in Runtime ++= Seq(kamonLogging, kamonAspectJ)

I would recommend trying
addSbtPlugin("com.lightbend.sbt" % "sbt-javaagent" % "0.1.2")
In https://github.com/Workday/prometheus-akka/blob/master/build.sbt, I use this to enable aspectjweaver in tests.

Ambiguous reference when using sbt-native-packager

I am trying to use the sbt-native-packager to create a deb file. When I run sbt it complains about ambiguous references as it loads build.sbt:
mydir/build.sbt:21: error: reference to maintainer is ambiguous;
it is imported twice in the same scope by
import NativePackagerKeys._
and import _root_.com.typesafe.sbt.SbtNativePackager.autoImport._
maintainer in Debian := "Your Name <your#email.com>"
[error] Type error in expression
Project loading failed: (r)etry, (q)uit, (l)ast, or (i)gnore?
My build.sbt is:
import com.typesafe.sbt.SbtNativePackager._
import NativePackagerKeys._
organization := "org.bodhi"
name := "HelloRemote"
version := "1.0"
scalaVersion := "2.11.4"
resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
libraryDependencies ++= Seq(
"com.typesafe.akka" %% "akka-actor" % "2.3.4",
"com.typesafe.akka" %% "akka-remote" % "2.3.4"
)
packageArchetype.java_application
maintainer in Debian := "Your Name <your#email.com>"
I am using sbt 0.13.7; My packager.sbt file contains:
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.0.0-M3")
Thanks
Just remove import NativePackagerKeys._

How to add assets from dependency to local project

My Play! -java project is using another play project (module) as a dependency.
After moving from Play 2.2. to Play 2.3 assets from the sub project are not seen.
In build.sbt I added jar with assets to dependencies
libraryDependencies ++= Seq(
javaJdbc,
javaEbean,
cache,
javaWs,
"com.company" % "project-sub-module_2.11" % "2.3.3"
"com.company" % "project-sub-module_2.11" % "2.3.3" artifacts(Artifact("project-sub-module_2.11","asset", "jar", "assets"))
)
I can see this jar in dependencies. But its contents seems do not appear in public directory then launching "run" command.
I think I need to add something like
packagedArtifacts in publish:= {
val artifacts: Map[sbt.Artifact, java.io.File] = (packagedArtifacts in publish).value
val assets: java.io.File = (playPackageAssets in Compile).value
artifacts + (Artifact("project-sub-module_2.11", "asset", "jar", "assets") -> assets)
}
but for the compilation process.
Thanks in advance!
#mount_ash is right about using
"com.company" % "project-sub-module_2.11" % "2.3.3" classifier "assets"
in your build.sbt to import assets into your project.
On the other hand to publish your assets when compiling, you need to add
the following to the build.sbt of your modules.
packagedArtifacts += ((artifact in playPackageAssets).value -> playPackageAssets.value)
By following these two things I was able to use/discover the assets of my module X in my application host Y.
To solve the above problem the code should be like that
libraryDependencies ++= Seq(
javaJdbc,
javaEbean,
cache,
javaWs,
"com.company" % "project-sub-module_2.11" % "2.3.3"
"com.company" % "project-sub-module_2.11" % "2.3.3" classifier "assets"
)

How to add Poi Scala library to Play project?

I want use Poi Scala library in the my Play framework project, And I added Poi Scala library to libraryDependencies in build.sbt:
libraryDependencies ++= Seq(
jdbc,
anorm,
cache,
"info.folone" %% "poi-scala" % "0.11",
"com.typesafe.slick" %% "slick" % "2.0.0-RC1",
"com.typesafe.slick" %% "slick-testkit" % "2.0.0-RC1" % "test",
"com.typesafe.play" %% "play-slick" % "0.5.0.8",
"com.novocode" % "junit-interface" % "0.10" % "test",
"ch.qos.logback" % "logback-classic" % "0.9.28" % "test",
"postgresql" % "postgresql" % "9.1-901.jdbc4",
"postgresql" % "postgresql" % "9.1-901.jdbc4" % "test",
"org.webjars" %% "webjars-play" % "2.2.0",
"org.webjars" % "bootstrap" % "2.3.1"
)
by instruction Poi Scala
but, when I do command "play update" appear following error:
[warn] module not found: info.folone#poi-scala_2.10;0.11
[warn] ==== local: tried
[warn] c:\tools\play-2.2.1\repository\local\info.folone\poi-scala_2.10\0.11\iv
ys\ivy.xml
[warn] ==== Maven2 Local: tried
[warn] file:/C:/Users/boyfox/.m2/repository/info/folone/poi-scala_2.10/0.11/po
i-scala_2.10-0.11.pom
[warn] ==== public: tried
[warn] http://repo1.maven.org/maven2/info/folone/poi-scala_2.10/0.11/poi-scala
_2.10-0.11.pom
[warn] ==== Typesafe Releases Repository: tried
[warn] http://repo.typesafe.com/typesafe/releases/info/folone/poi-scala_2.10/0
.11/poi-scala_2.10-0.11.pom
Anybody know how to fix this problem?
Thanks in Advance!
#gourlaysama said:
It seems like the last version of poi-scala that was published was
0.9, see bintray (bintray.com/bintray/jcenter/…), sonatype (oss.sonatype.org/index.html#nexus-search;quick~folone), and maven
central (repo1.maven.org/maven2/info/folone/poi-scala_2.10). Maybe
this is an oversight, or maybe they moved to a different maven repo.
I'd recommend opening an issue at github.com/folone/poi.scala.
This is right, library is indeed not in maven repository. And I opened an issue at github.com/folone/poi.scala by recomendation of #gourlaysama :
Issue

Resources