I have a Play project and need to add Swagger to it. Started following this guide: play-swagger and even did thealternative setup steps, but the swagger page is empty. Just a header appears on the page. Where should I look for mistakes or did I miss something?
Also, there is another guide: Swagger UI and Play Framework, but the sbt cannot resolve the given dependency. Does it need a specific resolver?
I've added this dependency:
"org.webjars" % "swagger-ui" % "2.2.0"
and this sbt plugin:
addSbtPlugin("com.iheart" %% "sbt-play-swagger" % "0.7.5")
(Play version 2.6, sbt version 1.x, Scala version 2.12.x)
There is a swagger.yml file in the conf folder. The contents of the Swagger UI dist folder is in the public/swagger folder. The routes file contains these lines:
### NoDocs ###
GET /docs/swagger-ui/*file controllers.Assets.at(path:String="/public/lib/swagger-ui", file:String)
### NoDocs ###
GET /assets/swagger.json controllers.swagger.ApiSpecs.specs
from alternative setup and the controller class specified in the same guide is also present. The Swagger UI index.hml contatins this line:
url: "http://localhost:9000/assets/swagger.json"
Related
I have created basic Scala Play application with https://www.playframework.com/getting-started play-scala-seed. This project compiles and runs with sbt run. But I have another Scala project that compiles and runs and which I have submitted to my local Ivy repository with command sbt publishLocal. This other project was saved at C:\Users\tomr\.ivy2\local\com.agiintelligence\scala-isabelle_2.13\master-SNAPSHOT as a result of this command.
Then I imported (exactly so - imported, no just opened) my Play project in IntelliJ and I used Project - Open Module Settings - Project Settings - Libraries to add com.agiintelligence jar from my ivy2 location. After such operations IntelliJ editor recognizes com.agiintelligence classes. That is fine.
But when I am trying to run my Play application with sbt run, I experience the error message not found: object com that is exactly when compiling import com.agiintelligence line in my Scala controller file of Play application.
Of course - such error has been reported and resolved with, e.g. object play not found in scala application
But that solution suggests to append build.sbt file. My build.sbt file is pretty bare:
name := """agiintelligence"""
organization := "com.agiintelligence"
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayScala)
scalaVersion := "2.13.5"
libraryDependencies += guice
libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "5.0.0" % Test
// Adds additional packages into Twirl
//TwirlKeys.templateImports += "com.skaraintelligence.controllers._"
// Adds additional packages into conf/routes
// play.sbt.routes.RoutesKeys.routesImport += "com.skaraintelligence.binders._"
My Play application contains (as can bee seen from the IntelliJ project pane) some tens of 'external libraries' (it shows my com.agiintelligence jar as well), but why should I add my own ivy2 library in build.sbt file if no other libraries are listed here? What is different with my library? It is on my computer, in the repository as expected already?
Of course, I can try to add it build.sbt and issue sbt update and see what happens, but I can not understand this logic? Can someone explain it and provide some clue to intelligible solution of my error message?
My Play application contains (as can bee seen from the IntelliJ project pane) some tens of 'external libraries'
Those are probably just transitive dependencies of your Play dependency, that is why sbt downloaded all of them and put them in your classpath so you could use them without you needing to tell it about them; because the pom of Play already did.
It is not that the build tool or the IDE magically added all those dependencies for you because they read your mind and magically understood you wanted them. And that for some reason the magic stopped working for your own library.
Why it is not sufficient to list it Project-Setting--External Libraries in IntelliJ only?
That is sufficient for the IDE to work, but not for the build tool. The build tool is independent of the IDE; it doesn't know about it. sbt just knows about the dependencies you configured in your definition file.
Even more, you should always configure your dependencies on your build tool and then import that in the IDE; rather than the opposite. IDEs are graphical tools, so their state can not be committed, can not be shared, can not keep track of changes, can not be used in CI / CD environments; additionally, different teammates may want to use different IDEs.
I resolved the error message by adding line in build.sbt file
libraryDependencies += "de.unruh" %% "scala-isabelle" % "master-SNAPSHOT"
and by subsequent run of sbt update.
Error is solved, but the main question still stand - why I had to do this? Why there are tens of dependencies that are not listed in build.sbt and why should I list my dependency in build.sbt and why it is not sufficient to list it Project-Setting--External Libraries in IntelliJ only?
OK, comment by #Luis_Miguel_Mejía_Suárez gave the explanation, that comment is the actual and expected answer to my question.
I have a play 2.4 subproject that uses sbt-sassify. It works fine, but I want to pull a bower dependency into the project so that my scss files can make use of it. I followed the sbt-sassify instructions for this and added the following dependency to my build.sbt.
"org.webjars.bower" % "bootstrap-sass" % "3.3.6"
However, when I run the project, none of the scss from bootstrap-sass is in the target folder so that I'm able to import it into my scss. If I use a dependency to a classic webjar such as
"org.webjars" % "bootstrap" % "3.3.6"
I will be able to see the bootstrap code in target/public/main/lib.
When I run the sbt-dist command, the bower jars will show up in my universal tar ball.
Is there anything else I need to configure?
activator dist will only package your project in several jars. The contents of all assets can be found in:
target/scala_<scala_version>/<prefix>-web-assets.jar/public/lib/bootstrap-sass
However, none of this makes sense when you're only trying to import the scss files into your own scss files. As of sbt-sassify version 1.4.0+ you can include web-jarred assets into your own files (without relying on the folder structure of your application).
I'm not sure which of the bootstrap files you're trying to import, but for instance if you'd want to the root of the bootstrap code you could use
#import "lib/bootstrap-sass/assets/stylesheets/bootstrap";
P.S.
I'm the author of sbt-sassify and I've tested this with play 2.4.6 and sbt-sassify version 1.4.2. In case this does not solve things for you, can you create a repo on github exhibiting the faulty behaviour?
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.
In a play application I found that "eclipse" command works by default without adding "sbt eclipse" plugin in the plugins.sbt file. However in case of Sbt this works only if this plugin definition is added.
I was just wondering if Play is a wrapper over SBT with additional features available by default?
Indeed, Play is an sbt plugin. You can read about it in the documentation: Create a new application without Activator
You can defined the eclipse plugin globally.
Settings can be placed here: ~/.sbt/0.13/eclipseSettings.sbt
EclipseKeys.eclipseOutput := Some(".target")
Plugins can be placed here: ~/.sbt/0.13/plugins/eclipse.sbt
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "2.5.0")
Activator itself is also built upon sbt: Typesafe Activator, What is it?
how to use JavaCV from SBT (Simple Build Tool) in Scala? I need to use JavaCV so I can write a Scala application using this.
Simple Build Tool is here: http://www.scala-sbt.org/
JavaCV is here: http://code.google.com/p/javacv/
Add the following to your build.sbt file.
resolvers += "JavaCV maven repo" at "http://maven2.javacv.googlecode.com/git/"
libraryDepedencies += "com.googlecode.javacv" % "javacv" % "0.2"
This should pull down javacv for you, as well as any dependencies. Note you will still need to have all the native libraries set up like javacv details, this only gets the jars for your project.
I created an SBT plugin that solves most of this for you in 1 line; no need to set up native libraries etc because this will do it all for you.
https://github.com/lloydmeta/sbt-opencv
Usage:
Add the following in project/plugins.sbt:
addSbtPlugin("com.beachape" % "sbt-opencv" % "1.2")