6

I'm trying to move an existing project to gradle from ant. I'm using Intellij 13, and I've managed to get one module running under gradle by deleting the iml file. However, it insists on writing an iml file that has a name that matches the directory name not the module name.

I recognize that this is probably not a problem for folks who work alone or on a single team in a large company where the IDE and version is handed down from on high. However this project involves a variety of contractors from several companies who all supply their own IDE's. Intellij's licensing model makes it impractical to supply the IDE to outside contractors because most work is done off site and there is no way to take back or de-authorize the license key once you give it out.

Since upgrading Intellij is not free, it's nearly impossible to coordinate everyone to upgrade at once and so I use the file based project format, with a project file named ourproject.ij12.ipr1 and another named ourproject.ij13.ipr and the iml files for the module in the directory foo are foo.ij12.iml and foo.ij13.iml

This works great, and the policy is that everyone has until 14 comes out to get off of 12 so that we don't get an infinite number of versions going, but we don't have to synchronize our upgrades too the nanosecond either.

Unfortunately, as soon as I try to use build.gradle in the foo directory in intellij, it writes foo.iml which totally breaks the forgoing conventions. Furthermore, it adds another module (without asking) and that leads to two modules in the same directory and the ide won't let you change either one because two modules in the same directory are an error.

Can anyone tell me how to influence the file name that Intellij writes for the iml file when using gradle? obviously having separate directory names is not going to do it unless I get very elaborate with symlinks and ant.symlinks task, and that won't work if anyone trys to run it natively on windows.

EDIT: Since folks seem to be in the habit of deleting their unaccepted answers, let me clarify. I am aware of the gradle idea eclipse plugins. I am not asking for a guide to IDE agnosticism. I find there are things of value in IDE setups, and want to share them among others using the same IDE (where "same" includes the version, cross version sharing is not expected, but more than one version at a time is).

To be more specific, I am looking for one of these:

  • A configuration or trick that allows me to control the file names of iml files
  • Another way to maintain two versions of ide files, that is not too byzantine.
  • Confirmation from one of the JetBrains folks who participates in SO that there is no longer a way accomplish my goal with IDEA.

EDIT2: Solutions involving gradle generating the files are not going to work. Intellij 13 changes the file name to match the directory name not the module name, which is the soruce of the problem. I need a solution that convinces Intellij not to do that. I had no problems before the upgrade to 13.

Gus
  • 6,719
  • 6
  • 37
  • 58
  • The following websites have more information if it helps -> http://stackoverflow.com/questions/7060727/how-to-deal-with-intellij-idea-project-files-under-git-source-control-constantly , http://devnet.jetbrains.com/message/5245457, http://devnet.jetbrains.com/thread/279596?tstart=0 – First Zero Jan 14 '14 at 04:24
  • All good stuff, but none of it seems to address my actual problem (unless I missed something). – Gus Jan 14 '14 at 05:42

3 Answers3

3

Using the idea plugin I was able to get it to generate two iml files for me based on a commandline parameter. Here is the (minimal) build.gradle file I created

apply plugin: 'java'
apply plugin: 'idea'

def imlName = name + (hasProperty('generate12') ? '.ij12' : '.ij13')

idea {
    module {
    name = imlName
    }
}

This script will generate a '13' file for you by default. So to change that you will need to set the generate12 property.

Commands I ran:

> gradle idea
> gradle idea -Pgenerate12=true
> ls
  build.gradle  test.ij12.iml test.ij13.iml test.ipr test.iws

The idea module documentation might have some more useful things for you.

Side note: I think it would be best if you gave the project without iml files to everyone and told them to run gradle idea(without the custom iml name stuff) to let the files be created. This will allow you to not have to maintain files that will get modified and overwritten by IntelliJ. We check in iml files and it causes nothing but problems when someone checks something in and breaks it for everyone.

Ethan
  • 6,883
  • 3
  • 33
  • 41
  • Interesting, but the file name is not the point. The point is to have a file with features and settings for 12, and another with features and settings for 13. There will be no difference between the two generated files in your suggested solution. Note also that test.ij12.ipr and test.ij13.ipr are also necessary.... And my experience is that even if it reads a file named test.ij13 initially, intellij 13 will start writing a test.iml for a module in the test directory. I need a solution INSIDE intellij or that behavior will obviate any external solution. – Gus Jan 14 '14 at 14:28
  • So you want to know how to have multiple project files(iml, ipr, etc) inside one directory, using only intellij configurations so that when you open a project file (12 or 13) it opens the correct files with the names? – Ethan Jan 14 '14 at 15:04
  • I don't actually care where the files come from but the problem is with intellij re-naming the file. As for the gradle tag, though the solution may not contain gradle code this question **does** involve and relate to gradle. – Gus Jan 14 '14 at 15:38
  • I'm increasingly thinking that a solution doesn't really exist. I should just post this as an issue in YouTrack. – Gus Jan 14 '14 at 15:43
2

Use settings.gradle file to change module names. Intellij should use it. Next, you can use gradle.properties to set your prefix.

E.g. setting.gradle:

rootProject.name = adjustName("ourproject")

include "someProject"
// ... other includes

rootProject.children.each{ it.name=adjustName(it.name)}

String adjustName(String name) {
    String pref = System.properties['myIdeaVersionPrefix']
    return pref != null ? name + "." + pref : name
}

gradle.properties:

systemProp.myIdeaVersionPrefix=ij13

see screenshot for the configuration at https://i.stack.imgur.com/CH2Bv.png

0

There doesn't seem to be a good answer for this. I have filed this as a bug in YouTrack http://youtrack.jetbrains.com/issue/IDEA-119625.

Gus
  • 6,719
  • 6
  • 37
  • 58