How to add missing SNAPSHOT dependency to Heroku? - scala

I have a Scala Play 2.7.x application which I deploy to Heroku. However, the build fails due to a missing dependency "com.github.tototoshi" %% "play-joda-routes-binder" % "1.3.1-SNAPSHOT" and that's correct because this one I built locally. How do I make this missing dependency available to Heroku?
The dependency I need is this one https://github.com/tototoshi/play-joda-routes-binder but it had a bug which I fixed here https://github.com/tototoshi/play-joda-routes-binder/pull/6. However, the author of that project seems afk for several months now. I can build my PR locally but how do I add it to Heroku for my project to work?

You can put the compiled jar into a subfolder in the project for example: /lib. Sbt will automatically look for jars in this directory. If you want to configure it as something else you can define the key unmanagedBase:
unmanagedBase := baseDirectory.value / "custom_lib"
There's more documentation about sbt lib management here: https://www.scala-sbt.org/1.x/docs/Library-Dependencies.html.
Also playframework documents this, but it's basically the same:
https://www.playframework.com/documentation/2.7.1/SBTDependencies

Another solution is to not use the automatic deployment with connection to Github but rather the SBT Heroku CLI and then build / deploy locally and simply upload the binary artifacts to Heroku like so:
sbt stage deployHeroku
heroku open --app myapp
after adding the following two entries into the project/plugins.sbt file (latest versions as of today):
addSbtPlugin("com.heroku" % "sbt-heroku" % "2.1.2")
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.4.1")

Related

Building jars with sbt

I'm following this tutorial to create a scala jar to upload to streamsets to use in a spark evaluator.
I'm using Intellij 2017.3.4.
If I use Intellij to build the artifact into the out folder, it's over 100mb in size.
If i use the 'sbt clean package' option from the command line, the jar is 3mb.
They both work fine.
Could anyone tell me why there's such a difference, and how I'd setup my Intellij so I create the smaller version?
Thanks
Matt
Without further knowledge of your build.sbt and your IntelliJ settings I can only guess that your build.sbt contains a line like this:
libraryDependencies += "org.apache.spark" %% "spark-core" % "2.3.0" % Provided
Notice the Provided. It means that spark is not bundled in the jar that sbt prepares, but is expected to already be present at the server in which you run your program (on your class path).
IntelliJ uses all the jars (including those marked provided) so that you can debug/run your program via IntelliJ. Since you did not add your build settings in IntelliJ this is the best I can do for now.
If you use sbt assembly to package your artifact, and you want to do this with a run configuration in IntelliJ you can go to Run/Debug Configurations, click the + button, select sbt task and fill in assembly as the task.
Read more about packaging your spark app here.
I hope that helps :)

SBT Plugin in an unmanaged jar file

The requirement: an SBT plugin code is in an unmanaged jar, for example in lib/unmanaged-sbt-plugin-0.0.1.jar.
I was expecting the jar file would be picked up by SBT automatically and the plugin would work out-of-the-box, i.e.: the tasks would be accessible from SBT command line, but that is not the case.
The jar file has the sbt/sbt.autoplugins file in it and the plugin works if pulled from a remote repo into the local one and imported via addSbtPlugin(...). Please note I cannot do that - it's a requirement to get it to load from the lib/unmanaged-sbt-plugin-0.0.1.jar and not from the local/remote repo.
Putting the following line in the build.sbt doesn't make the plugin work (there's not error either):
unmanagedJars in Compile += file("lib/unmanaged-sbt-plugin-0.0.1.jar")
The implementation of addSbtPlugin(...) is simply (according to http://www.scala-sbt.org/0.12.2/docs/Getting-Started/Using-Plugins.html):
def addSbtPlugin(dependency: ModuleID): Setting[Seq[ModuleID]] =
libraryDependencies <+= (sbtBinaryVersion in update, scalaBinaryVersion in update)
{ (sbtV, scalaV) => sbtPluginExtra(dependency, sbtV, scalaV) }
I'm wondering if the above info can be used to resolve my issue?
Thank you in advance!
So you can specify an explicit URL for library dependencies (ModuleID):
addSbtPlugin("org.my-org" % "unmanaged-sbt-plugin" % "0.0.1"
from "file:///./lib/unmanaged-sbt-plugin-0.0.1.jar")
Have been struggling to get this to work.
Could not get it to work with proposed solution using from "file://.." (using sbt 1.0.4).
Got it to work by putting the plugin in project/lib folder and adding all the plugin dependencies to plugins.sbt using libraryDependencies ++= Seq(..) like in build.sbt. You can find the plugin dependencies by looking at the plugin pom file, usually in .ivy2/local/<org>/<pluginname>/poms folder.

Using sbt plugin from Bintray

I'm experiencing a kind of impedance mismatch between sbt and bintray-sbt plugin. The plugin is published via bintray-sbt at https://bintray.com/artifact/download/synapse/sbt-plugins/me/synapse/my-sbt-plugin/0.0.1/my-sbt-plugin-0.0.1.pom (publishMavenStyle set to true. If set to false a different directory structure is created but still not the one sbt expects). Test project has
resolvers += Resolver.bintrayRepo("synapse", "sbt-plugins")
addSbtPlugin("me.synapse" % "my-sbt-plugin" % "0.0.1")
in project/plugins.sbt and sbt tries to download https://dl.bintray.com/synapse/sbt-plugins/me/synapse/my-sbt-plugin_2.10_0.13/0.0.1/my-sbt-plugin-0.0.1.pom
What settings should be used in plugin build definition to a) be able to test it from current repository and b) to be able to link it to sbt-plugin-releases repo when the time comes?
UPD: It looks like after the package was linked to sbt-plugin-releases it ended up in proper directory structure.

How to create standalone jar file for elastic4s from sources?

I'm trying to create a standalone jar file from the elastic4s sources on github. I've used sbt compile as detailed on the github page, but I can't find the jar file.
How do I use sbt to create the jar file so I can import it into my projects as a dependency?
The compile task will only compile the project.
> help compile
Compiles sources.
If you want to create a jar file and use it as a dependency in your project, you have two ways of doing that.
Unmanaged dependency (not recommended)
Unmanaged dependency run +package, which will create a jar file for each supported scala version, which you can use in your projects as an unmanaged dependency. Copy the package-generated jar to lib folder in your project.
The jar files will be located in target/scala-2.11 and target/scala-2.10, depending on the Scala version you want to use it with.
Publish to Local Repository (recommended yet imperfect)
If you want to include your custom-built elastic4s, as a managed dependency, you have to run +publishLocal. This will do the same as above, but additionally it will publish the artifact to your local repository. Assuming you've built it with version := "1.2.1.1-SNAPSHOT", you can include it in your project by just adding:
libraryDependencies += "com.sksamuel.elastic4s" %% "elastic4s" % "1.2.1.1-SNAPSHOT"
What makes the approach imperfect is that once you shared the project on GitHub (or any other project sharing platform), people will have to do publishLocal themselves to be able to build your project. The dependency should therefore go to one of the official binary repositories so when a dependency is needed, it's downloaded from Internet. Consult Publishing.
What is the + character in front of the commands
The + in the commands is for cross-building, if you don't use it the command will be executed only using scalaVersion declared in the build.sbt of the project.

How to setup eclipse-ide work on the playframework 2.0

On Github there is an description how to build the framework from scratch. How ever I want to understand how somethings work internally so I want to setup the Eclipse-IDE to make this as comfortable as possible. Has anyone a description how this can be easily done?
To make it clear, I don't want to know how to setup eclipse for working on play-project.
THIS SOLUTION WAS FOR PLAY 2.0, you can't use it directly in 2.1! at least the command build-repository isn't valid anymore.
git clone git://github.com/playframework/Play20.git
Add
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.0.0")
to play20/framework/project/plugins.sbt, so you get
logLevel := Level.Warn
resolvers += Classpaths.typesafeResolver
addSbtPlugin("com.typesafe.sbtscalariform" % "sbtscalariform" % "0.3.0")
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.0.0")
Then make the normal build processes.
$ cd Play20/framework
$ ./build
> build-repository
> eclipse
Create a Scala-IDE give her enough Space, choose the 64-bit variant if you can!
Import projects from play20/framework/src
Add /Play/target/scala-2.9.1/src_managed/main as source folder.
You will end up with less than 10 compilation errors :-(, but will have the most of the code in eclipse.
When building against 2.1 snapshot, Eclipse keeps the .ivy2/cache jar of play 2.0.1, which is where, in my case the errors were coming from.
The solution is to remove play 2.0.1 jar from eclipse build path, and add in the 2.1 snapshot jar that you build (in your-play20/repository/local/play/play_2.9.1/2.1-SNAPSHOT/jars)
Got an error free Eclipse + Scala-IDE setup, nice ;-)
Take a look at the Sbt eclipse Plugin. It will generate an eclipse project for you. It should be rather easy. Just follow the instruction on the plugins git page. Regards. Jan