Cannot purge old classes when using IntelliJ and Payframework project using sbt - scala

Setup details
1. IntelliJ Idea Community Edition 2018.2.5 with sbt plugin
2. PlayFramework
3. scalaVersion 2.12.8
4. Java 1.8 (open JDK)
5. sbt: bundled sbt with play-scala-hello-world-tutorial
6. Host OS: Limux Mint 18.3, KDE Plasma 5
Issue:
I tried using the hello-world project template from Playframework - using IntelliJ to import it as an sbt project and accepting the default settings. After making some edits I deleted the project in the filesystem directly and replaced it with a fresh copy. However, when I run the project using the sbt_command window with the command 'run', the project launches Play bound to port 9000 and the running project still shows the 'old' modified version of the app.
Steps to reproduce the problem:
Load 2.7.x version of play-scala-hello-world-tutorial
Edit HomeController.scala;
from
def index() = Action { implicit request: Request[AnyContent] =>
Ok(views.html.index())
}
to
def index() = Action { implicit request: Request[AnyContent] =>
Ok("Just Play Scala")
}
sbt_run
Ctrl+D to quit running app (in IDE's sbt command window)
Close IntellijIDEA
Delete project root folder in Idea Workspace
Place with fresh copy of play-scala-hello-world-tutorial scala-seed project template
Import project
Run using sbt 'run' command (in IDE's sbt command window)
view http://localhost:9000/ => results in "Just Play Scala"
Attempted resolutions
- Closed project from IntelliJ and deleted the project root folder from the IntelliJ-Idea workspace on the filesystem
- Performed #1 and deleted .ivy2 and .mvn directories
- Tried to reproduce the problem in a VM running Fedora28 using a text editor to replicate the changes. Everything works as expected. All changes are reloaded dynamically in play and changes are visible in the ruuning app.
Diagnosis
Either IntelliJ does not work as expected/ advertised for recompiling sbt projects or I do not know how to use the IDE to properly purge previously compiled code.

Related

sbt Project name must be valid Scala identifier error while creating new project

I wanted to create a new project in scala in intellij. I have chosen Lightbend Project Starter and then Akka Quickstart Scala. On finish I got this error:
sbt Project name must be valid Scala identifier
The name of my project is "akka-demo" but "akkademo" and default "untitled" don't work either. Empty catalog is created. Same with other templates. How can I overcome this?
Env:
Intellij idea ultimate 18.3.4
sbt 1.2.6
As mentioned, akkademo should indeed work.
It sounds like an IntelliJ problem.
If a project directory was created, you can try to remove the .idea directory and reimport the project.
Furthermore, you can download the Akka Quickstart Scala project from Lightbend's website, and start the sbt shell in this directory.
Try to run and compile to make sure your environment is set up correctly.
If everything works with the sbt shell but not in IntelliJ, then open:
IntelliJ -> Preferences -> Build, Execution, Deployment -> Build Tools -> sbt and check the Use sbt shell for imports and for builds.
Then go to the sbt tab in IntelliJ and refresh.

Scala Play 2.3 InteliJ 14 *community edition - is it possible to run project without cmd line activator command

From http://blog.jetbrains.com/scala/2012/12/28/a-new-way-to-compile/ I understand that Intellij is using sbt to build - so thats 1x build
At the moment I run a separate command line task to run my project -
./activator -jvm-debug 5000 -Dhttp.port=9000
So each code change gets compiled twice (once by InteliJ; once by activator)
Is there a way to use the InteliJ build artifacts when I run, so the code is only compiled once?
Is using the Terminal window in InteliJ any different from a normal terminal window?
The versions I'm at are:
Java 7
Play framework 2.3.4
SBT 0.13.1
InteliJ 14 (community edition)
Thanks
Brent
Yes it's definitelly possible.
Install Play 2.x plugin (with dependencies) and add the run configuration dedicated for Play 2 (note in Intellij 14 Play2 support is combined within the Scala plugin)
Menu > Run > Edit configurations... > Add new configuration (plus icon in the corner) > Play 2 App
After saving you will be able to run your app (also in debug mode) within IntelliJ - i.e. via
Menu > Run > Debug 'Your Project'
btw, you can remove Make (before launch) from there, SBT should handle builds properly without Idea's support
See sample shot

trouble with configuring scala project in intellij

I have been following the getting started with IntelliJ and Scala video from JetBrains and running into two problems.
I can't get it create or start a run configuration
I don't see the scala-test library as a selection under ProjectStructure-Modules-ChooseLibraries
What I've done so far is
Install Scala, add path and environment variables
Install Scala intellij plugin
Create new project set project sdk to java 1.7 and scala home to /usr/local/share/scala-2.10.3
Create an object that extends from App with a simple write line:
The one source file object
object HelloWorld{
def main(args: Array[String]) {
println("hello")
}
}
In the video they right click on the object file and can see a selection of run, but in my case I only see run as Scala Console. I can't seem to get the debugger to work and when I try to create a run configuration as an "Application" it says the src file is "not acceptable"
I'll recommend my simple project skeleton, to get you quickly up and running with Intellij, SBT and even Eclipse setup. Hope it helps!

Eclipse unresolved symbol with Play Framework

I'm a beginner user of Play Framework 2.1.3 and I have just created a new Java application and I have run play eclipse to generate the eclipse project for it. I have also tested so that it works by doing a play run.
So I'm following this tutorial and there is a step where you should add this piece of code:
public static Result index() {
return redirect(routes.Application.tasks());
}
But I'm getting the message "routes cannot be resolved". I have also tried play compile and in Eclipse doing a clean to no avail.
I was having the same trouble after the recent 2.4.X release of Play and the solution of cleaning/compiling/reimporting wasn't working. The solution for me was to:
Add the below keys to build.sbt
Kill eclipse
./activator clean
./activator compile
./activator eclipse
Re-import into eclipse
The problem is basically that the managed source directory wasn't being created, these lines fix the problem.
EclipseKeys.projectFlavor := EclipseProjectFlavor.Java // Java project. Don't expect Scala IDE
EclipseKeys.createSrc := EclipseCreateSrc.ValueSet(EclipseCreateSrc.ManagedClasses, EclipseCreateSrc.ManagedResources) // Use .class files instead of generated .scala files for views and routes
EclipseKeys.preTasks := Seq(compile in Compile) // Compile the project before generating Eclipse files, so that .class files for views and routes are present
run play clean-all from your project directory
run play eclipse from your project directory
refresh your eclipse project
Upgrade sbteclipse to version 5.1.0 (which was released on January 12th 2017) - it fixes this bug.
Probably some kind of classpath issue in your Eclipse setup. Anyway, you should not rely on Eclipse to compile your Play application, simply compile it from the console and use Eclipse for source code editing only. (BTW : there are way lighter IDEs then Eclipse if you don't use it for compilation)

Can I avoid compiling sources twice when running play2 and eclipse?

Currently I am running eclipse and play (with ~run) at the same time. When I change a file it will be compiled by play and by eclipse.
Is it possible to avoid one of those two compilation steps?
As far as I know, the eclipse plugin also uses sbt to build the project so maybe there is a way to execute the play "run" command inside eclipse?
(I am asking because my laptop is not very fast and compilation takes some time, and I would like to have the "Fast turnaround" as advertised on the play webpage ;)
You can turn off Build Automatically from the Project menu without losing any of the IDE functionality. Binaries will be built only by Sbt (on the command line).
A detailed guide for setting-up Play 2 with Scala IDE can be found on the Scala IDE website: http://scala-ide.org/docs/tutorials/play20scalaide20/index.html
I have not yet tried to run the play run sbt task in eclipse.
BUT you can run the server directly from eclipse.
Add "target/scala-2.9.1/classes" to your class path, use filters to include only your assets. (Project Properties, Java Build Path)
Choose "Run Configurations..." from the Run-Button-Menu.
Create a new "Java Application" configuration with your favourite name.
Main Tab: Use "DebugStart" as your main class
Arguments Tab: Configure any "-Dconfig.file=..." "-Dlogger.file" options you might need in VM arguments
Classpath Tab: Add the conf directory to the classpath (Advanced/Add Folders)
Create DebugStart.scala with:
import play.core.server.NettyServer
import java.io.File
import play.core.SBTLink
import play.core.TestApplication
import play.api.test.FakeApplication
import play.api.test.TestServer
object DebugStart {
def main(args: Array[String]) {
val app = FakeApplication()
val server = TestServer(9000, app)
server.start()
}
}
You can now start the app with run or debug. If you use debug, you can perform some code changes without any restart.
My version of DebugStart.scala actually contains some platform dependent hackish code to kill any running process, so that I can just hit F11 or CTRL+F11 to restart the application.
To ensure that your assets/sources are up to date run:
> sbt
...
[your project] $ ~ ;play-copy-assets;sources
IntelliJ Idea 12 (Leda) is coming soon. I'm using 11 for a while and there's no such problems but new version will offer much better Play 2.0 integration.