Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala unused import statement with play framework in IntelliJ

I'm trying to learn scala and play framework. I choosed IntelliJ Idea as ide. The problem is editor gives warning on imports like ; "unused import statements"

import play.api._
import play.api.mvc._

Also give warnings on declerations like ; "Cannot resolve symbol Controller"

object Login extends Controller

How can i remove warnings?

Steps i followed;

Create template idea project with play command;

Add scala compiler and library into external libraries.

IntelliJ Idea Version : 12.1 Community Editon

like image 646
Fatih Donmez Avatar asked Apr 10 '13 08:04

Fatih Donmez


People also ask

What version of Scala is supported by IntelliJ IDEA?

Before you start generating your Play project, make sure that the Scala plugin is downloaded and enabled in IntelliJ IDEA. IntelliJ IDEA supports Play versions 2.4 and later.

How do I create a play 2 project in IntelliJ?

Open New Project wizard. From the options on the right, select Play 2.x. Follow the steps suggested in the wizard and click Finish. IntelliJ IDEA generates the Play 2 project with the appropriate structure, dependencies and an executable application. Open a new project wizard and from the options on the right, select Lightbend Project Starter.

Does IntelliJ IDEA manage migrations of projects while upgrading?

As I commented that I had a similar problem: I actually got mine resolved: It seems like Intellij IDEA did not manage migrations of projects while upgrading. Deleted directories: build, out, .idea

How do I create a Scala project in Visual Studio?

Select the highest version number (e.g. 2.13.7) and click Download. This might take a few minutes but subsequent projects can use the same SDK. Once the SDK is created and you’re back to the “New Project” window click Finish. On the Project pane on the left, right-click src and select New => Scala class.


1 Answers

This is how I did it (I'm using Play! 2.1.0):

C:\dev>play new community
       _            _
 _ __ | | __ _ _  _| |
| '_ \| |/ _' | || |_|
|  __/|_|\____|\__ (_)
|_|            |__/

play! 2.1.0 (using Java 1.7.0_15 and Scala 2.10.0), http://www.playframework.org

The new application will be created in C:\dev\community

What is the application name? [community]
>

Which template do you want to use for this new application?

1             - Create a simple Scala application
2             - Create a simple Java application

> 1
OK, application community is created.

Have fun!


C:\dev>cd community

C:\dev\community>play idea
[info] Loading project definition from C:\dev\community\project
[info] Set current project to community (in build file:/C:/dev/community/)
[info] Trying to create an Idea module community
[info] Updating {file:/C:/dev/community/}community...
[info] Done updating.
[info] Excluding folder target
[info] Created C:\dev\community/.idea/IdeaProject.iml
[info] Created C:\dev\community\.idea
[info] Excluding folder C:\dev\community\target\scala-2.10\cache
[info] Excluding folder C:\dev\community\target\resolution-cache
[info] Excluding folder C:\dev\community\target\streams
(commons-codec_commons-codec_1.6_test,List(commons-codec_commons-codec_1.3))
(org.apache.httpcomponents_httpcore_4.1.3_test,List(org.apache.httpcomponents_httpcore_4.0.1))
(org.apache.httpcomponents_httpclient_4.1.2_test,List(org.apache.httpcomponents_httpclient_4.0.1))
[info] Created C:\dev\community\.idea_modules/community.iml
[info] Created C:\dev\community\.idea_modules/community-build.iml

C:\dev\community>play compile
[info] Loading project definition from C:\dev\community\project
[info] Set current project to community (in build file:/C:/dev/community/)
[info] Compiling 5 Scala sources and 1 Java source to C:\dev\community\target\scala-2.10\classes...

enter image description here

The Unused import statement is because no classes are being used in that package. This line can safely be removed by optimizing import: Ctrl + Alt + o.

In this case I didn't add any scala libraries at all. I just compiled from the command line.

like image 140
maba Avatar answered Sep 21 '22 22:09

maba