IntelliJ + Play 2 integration

The Gradle IDEA plugin doesn’t seem to know how to handle Play Framework apps yet (as of Gradle 2.8).

In order to prevent IDEA from going fireball red everywhere when developing on Play I had to add this to my build.gradle file:

apply plugin: "idea"

idea {
  module {
    sourceDirs += file("app")
    testSourceDirs += file("test")
    scopes.COMPILE = [plus: [configurations.play], minus: []]
    scopes.RUNTIME = [plus: [configurations.playRun], minus: [configurations.play]]
    scopes.TEST = [plus: [configurations.playTest], minus: [configurations.playRun]]
  }
}

It’d be cool if the Gradle Play plugin could handle this automatically, or at least put this in the Play Documentation

Cheers.

1 Like

Thats all? I have added that to my code but it still “can’t resolve symbol …” :frowning:

You’ll have to have the standard Play directory structure.

gradle cleanIdea idea

is assumed as well.

This is Gradle 2.8, Play 2.3.x and Java 8

I have tried with Play 2.4.3 and 2.3.10, Gradle 2.8-RC2 and java 1.8-20 and IntelliJ 14 Ultimate. IntelliJ still can’t resolve symbols and everything is red. This is my build.gradle. http://pastebin.com/LkpTiT41

Maybe you done something more?

Ok. I tried again and now this working!

gradlew cleanIdea
gradelw idea
gradlew ideaModule

Thanks for that! :smile:

1 Like

Glad it worked out :+1:

I’ve found it helpful to mark the compile/test resources and generated sources as well.

idea.module {
    // Source directories
    sourceDirs += file('app')
    testSourceDirs += file('test')

    // Generated sources
    def generated = [
        file("$buildDir/playBinary/src/compilePlayBinaryRoutes"),
        file("$buildDir/playBinary/src/compilePlayBinaryTwirlTemplates")
    ]
    generated.each { src ->
        sourceDirs += src
        generatedSourceDirs += src
    }

    // Output directories
    outputDir = file("$buildDir/playBinary/classes")
    testOutputDir = file("$buildDir/playBinary/testClasses")

    // Excluded dirs
    excludeDirs -= buildDir
    excludeDirs += [
        outputDir,
        testOutputDir,
        file("$buildDir/playBinary/lib"),
        file("$buildDir/playBinary/reports"),
        file("$buildDir/playBinary/results"),
        file("$buildDir/tmp"),
        file("$buildDir/assets")
    ]

    // Dependencies
    scopes.COMPILE = [ 'plus' : [ configurations.play ] ]
    scopes.TEST = [ 'plus' : [ configurations.playTest ] ]

    iml.withXml { provider ->
        def content = provider.node.component.content.first()

        // Resources
        def confUrl = 'file://$MODULE_DIR$/conf'
        def confAttrs = content.find { it.@url == confUrl }?.attributes()
        if (confAttrs) {
            confAttrs.remove('isTestSource')
            confAttrs.type = 'java-resource'
        } else {
            content.appendNode('sourceFolder', [url: confUrl, type: 'java-resource'])
        }

        // Test resources
        def testResourcesUrl = 'file://$MODULE_DIR$/test/resources'
        def testResourcesAttrs = content.find { it.@url == testResourcesUrl }?.attributes()
        if (testResourcesAttrs) {
            testResourcesAttrs.remove('isTestSource')
            testResourcesAttrs.type = 'java-test-resource'
        } else {
            content.appendNode('sourceFolder', [url: testResourcesUrl, type: 'java-resource'])
        }
    }
}

Admittedly, the code for marking resources is ugly. I’m all ears for improvements.

I cant find anything about evolutions working with play plugin :frowning: Does it works for you? What dependencies I need to add? I think have tried everything(play 2.4.3 and 2.3.10 with playEbean, play java ebean and avaje ebeanorm) and it still doesnt work.

There’s an outstanding pull request for the Gradle Play plugin to package resources (including evolution scripts) correctly. https://github.com/gradle/gradle/pull/528

Thanks!! Can’t wait it will be released! Btw. What ebean plugin in dependency you are using? I found this … But

play ‘com.typesafe.play:play-ebean_2.11:2.0.0’

  • model class nit fiund exception
    play ‘com.typesafe.play:play-java-ebean_2.11:2.4.0-M2’
  • when running model enhancement exception
    play ‘org.avaje.ebeanorm:avaje-ebeanorm:6.9.1’
  • compiling but not evolution

@edit
I have build your pull request. But now I see there is no evolution file generating at all… Does it work for you?

Sorry, I’m not using ebean.

You need to write your own evolution files and place them in the right directory.

Ok, thanks a lot! :smile:

This works like charm for me. Thanks, Eric
Just curious how/where did you figure it out - I am unable to find any other reference/documents on this
-Chris L

1 Like

Chris, IIRC I figured it out by looking at the XML under the .idea/ directory and cross-referenced that with a bit of the Gradle source code. Wasn’t as easy as we’d like.

Hey guys,

Has anyone else had success with this approach and IntelliJ 16? I’ve followed everything here and my IntelliJ 16 isn’t even recognizing the external libraries besides Java 1.8. Things seem totally broken with the IDE.

2 Likes

I can confirm that the above works in IntelliJ 15 but not in the current 2016.1 or any versions above 15, any help would be appreciated.

It looks like IDEA 16 splits projects into several modules that are not affected by idea.module, I think? I fixed the highlighting issue by going into Build, Execution & Deployment > Build Tools > Gradle from Idea’s Settings dialog and unchecking “Create separate module per source set”. Would there be a way to target a particular module with the idea plugin?

1 Like

Greetings guys! Any everyone who have have success experience of generate idea project using gradle?
Just I’m spend a little bit time trying fix it. After generated idea project and opened it, intellijIdea don’t see gradle’s dependencies. Could someone help me please?

So, In my module .iml file there are orderEntry nodes with correct absolute path:

<orderEntry type="module-library">
  <library>
    <CLASSES>
      <root url="jar:///home/user/.gradle/caches/modules-2/files-2.1/com.typesafe.play/play-slick-evolutions_2.11/2.0.2/c39998e138dfc55d8217ef0cabee8db412108e10/play-slick-evolutions_2.11-2.0.2.jar!/"/>
    </CLASSES>
    <JAVADOC/>
    <SOURCES>
      <root url="jar:///home/user/.gradle/caches/modules-2/files-2.1/com.typesafe.play/play-slick-evolutions_2.11/2.0.2/3b4dfa42d55333f24eba317e8b45a7c2f6efd45c/play-slick-evolutions_2.11-2.0.2-sources.jar!/"/>
    </SOURCES>
  </library>
</orderEntry>
<orderEntry type="module-library">
  <library>
    <CLASSES>
      <root url="jar:///home/user/.gradle/caches/modules-2/files-2.1/org.postgresql/postgresql/9.4-1204-jdbc42/aae989d89b2f9b10900044d85881e3a65137b1a7/postgresql-9.4-1204-jdbc42.jar!/"/>
    </CLASSES>
    <JAVADOC/>
    <SOURCES>
      <root url="jar:///home/user/.gradle/caches/modules-2/files-2.1/org.postgresql/postgresql/9.4-1204-jdbc42/9519b3d8569209b31a27a99f9faecaff2c97efbd/postgresql-9.4-1204-jdbc42-sources.jar!/"/>
    </SOURCES>
  </library>
</orderEntry>

Why Intellij Idea don’t see these dependencies? I cannot work, because of error. Could some one help me please?

Thanks! It’s working well for me after I wasted of time (5 days)