IDEA 13 + Gradle - idea.module.iml.withXml is ignored?

I am trying to set up a multi-project gradle build in IDEA 13.  I am applying the idea plugin to all projects but letting IDEA manage the module files (I didn't run any gradle idea plugin tasks manually).  One of the projects is web/war and I want to customize the generated web facet.  In the gradle docs, I don't see any DSL documentation about the web facet, so I think I need to use withXml to change the generated .iml.

Unfortunately, withXml seems to have no impact on the generated .iml.  I make a change to build.gradle, "refresh" via the Gradle window, and nothing changes in the output.  Currently I have simplified to the example code from the gradle docs:

idea.module {
    iml {
        withXml {
            def node = it.asNode()
            node.appendNode('iLoveGradle', 'true')
            node.appendNode('butAlso', 'I find increasing pleasure tinkering with output *.iml contents. Yeah!!!')
        }
    }
}

Other changes via idea.module (scopes, excludeDirs, etc) are reflected in the .iml.  Any ideas?  Hopefully I am missing something simple/obvious.  

7 comments
Comment actions Permalink

Hi Jeremy,

idea Gradle plugin is developed by Gradle. May be it is better to ask this question on their forums. But multi module Gradle build setup should work out of the box with Gradle integration. For example in your settings.gradle define:

include "ChildModule"
rootProject.name = "GradleMultiModuleSample"


in build.gradle:

...
project(':ChildModule')


dependencies {
...
    compile project(':ChildModule')
}

// or manage child project in this build gradle: //project(':ChildModule'){ //    apply plugin: "java" //    dependencies { //        compile ... //    } //}
...


Does this work for you?

0
Comment actions Permalink

Yes, multi-module support works as expected.  I already have similar configs in settings.gradle and my build.gradles.

So the Gradle support that is built into IDEA 13 is developed by Gradle?  Or are you referring to the Gradle idea plugin?  I am using the DSL provided by the Gradle idea plugin to configure my modules, but IDEA actually generates the .iml files based on the config (or maybe it delegates to Gradle behind the scenes?).  For example, when I edit a build.gradle, IDEA automatically updates the .imls based on my changes.  From the IDEA 13 Gradle "features":

"IntelliJ IDEA 13 is even able to configure Web facet and WAR artifacts automatically based on Gradle files"

That is happening (the web facet and artifacts are generated), but I can't find a hook to customize/change them.  There is no documented DSL for the web stuff in the Gradle docs, and no info from Intellij.  withXml() was the solution in IDEA 12, but as far as I can tell, it isn't honored in 13.

0
Comment actions Permalink

So the Gradle support that is built into IDEA 13 is developed by Gradle?


Gradle idea plugin is developed by Gradle and was aimed to provide Gradle support for IDEA projects (which could be not necessarily of a Gradle type). Now Gradle integration is bundled with IDEA and you don't need to manually configure idea project configuration files (imls etc) for the synchronization. This includes automatic configuration of artifacts. So now it is assumed that Gradle idea plugin is not needed any more for all common use cases.

However it still can be used for may be some special cases which IDEA doesn't support. What exactly do you want to achieve?
May be the example from http://youtrack.jetbrains.com/issue/IDEA-76232 can be of help. Also check with 13.1 EAP http://confluence.jetbrains.com/display/IDEADEV/IDEA+13.1+EAP (it supports Gradle 1.11 version).

0
Comment actions Permalink

So now it is assumed that Gradle idea plugin is not needed any more for all common use cases.


I guess I agree, sort of.  Idea definitely generates all the config files (iml), artifacts, etc.  But what about customizations?  In my case, src/main/webapp is mostly the same between my local tomcat deployment and my war, but with some differences for each scenario - the IDEA artifact can't be totally generated from the gradle war config, since they aren't exactly the same. For instance, I need to:

1.  Exclude some directories from src/main/webapp from the exploded war (they are only needed at build time and take to long to copy to the artifact)
2.  Include the providedRuntime dependencies in the lib of the exploded war (so that they are on the tomcat test classpath, but not in the war)
3.  Include an additional directory (with dev properties files, logging config, etc) on the artifact classpath

Basically, all of the artifact customization I would have done in module settings before.  What I have found is that IDEA honors some of the 'idea' plugin configuration closures.  I was able to accomplish #1 via plugin config, even though IDEA is still generating the .imls.  

idea.module {
    excludeDirs += file("$webAppDirName/dir1")
}


#2 I am not really sure about...I have managed to use the idea.module config to change the module's libraries (for instance, switching the providedRuntime libraries from PROVIDED to RUNTIME in the module), but the artifact is still created without those libraries on the path.  Through testing and tweaking, I have noticed that IDEA only honors some of the 'idea' plugin configuration - thus the original question, withXml seems to not be honored.  But I guess what I am really after is, in IDEA 13, what is the recommended method for customizing the IDEA-generated files, and what config attributes are supported?  Am I just getting lucky using idea.module.excludeDirs or is IDEA intending to honor that configuration?  Is there a better way to make these changes?  For the generated artifacts (which don't have an associated DSL in the 'idea' plugin), is there any way to make changes?

BTW, I have generally been happy with the IDEA 13 Gradle integration, and I think it is close, for our needs anyways.  I am trying to dig into that last 5% to see what is possible for our custom needs.  Thanks!

0
Comment actions Permalink

1. This indeed is not yet supported out of the box and grdle idea plugin can be used here.
2. 'providedRuntime' dependency type shoud work - IDEA will create 2 library versions with 'provided' and 'test' scopes (see scopes descriptions here https://www.jetbrains.com/idea/webhelp/dependencies-tab.html )
3. Try adding new Web facet and add this directory to facet web content root

Am I just getting lucky using idea.module.excludeDirs or is IDEA intending to honor that configuration?


As noted IDEA uses Gradle tooling api for interaction with Gradle and building corresponding idea configuration files. Some groovy dsl construcst are supported by it, but the not the appendNode.

0
Comment actions Permalink

2. 'providedRuntime' dependency type shoud work - IDEA will create 2 library versions with 'provided' and 'test' scopes (see scopes descriptions here https://www.jetbrains.com/idea/webhelp/dependencies-tab.html )

You are correct, I think I misunderstood the purpose of providedRuntime.

3. Try adding new Web facet and add this directory to facet web content root

In the end I put my dev (idea runtime) config files in 'resources', and then exclude them at build time:

processResources {
    exclude '**/*'
}

So I worked around the problem another way.  I am not sure adding a web facet manually (I assume you mean through the IDEA UI) works for us, since at the moment, IDEA generates all of the .imls based on the Gradle builds, and we don't have to check the .imls into source control.  If we went with manual config we would need to check those in.  Not that we couldn't check them in, but the current solution seems very...clean.

As noted IDEA uses Gradle tooling api for interaction with Gradle and building corresponding idea configuration files. Some groovy dsl construcst are supported by it, but the not the appendNode.

Any documentation on what is supported?  

Thanks for the help.

0
Comment actions Permalink

Any documentation on what is supported?

All commonly used Gradle configuration and plugins. But it is not possible to make low level .iml modifications with Gradle 'idea' plugin and use Gradle IDEA integration for it at the same time.

You can see the "big" picture for Gradle here http://confluence.jetbrains.com/display/IDEADEV/Gradle+integration .

0

Please sign in to leave a comment.