Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intellij & Gradle module file name

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.

like image 265
Gus Avatar asked Jan 09 '14 18:01

Gus


People also ask

What IntelliJ used for?

Apart from providing smart navigation and coding assistance, IntelliJ IDEA integrates the essential developer tools and lets you debug, analyze, and version the code base of your applications from within the IDE.

Is IntelliJ only for Java?

Though designed primarily for Java development, IntelliJ IDEA understands many other programming languages, including Groovy, Kotlin, Scala, JavaScript, TypeScript, and SQL, and it provides smart coding assistance for each of them.

Is IntelliJ IDEA free?

IntelliJ IDEA Community Edition and IntelliJ IDEA Edu are free and can be used without any license.

Is IntelliJ the best IDE for Java?

With more than 33 percent of the market share, IntelliJ IDEA is the most used Java IDE in 2022. It also has a stellar user rating of 4.3 and a whopping 89 percent user satisfaction. IntelliJ IDEA has unique resources like a version control system, frameworks, and multi-language support.


2 Answers

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.

like image 196
Ethan Avatar answered Sep 28 '22 07:09

Ethan


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 http://i.stack.imgur.com/CH2Bv.png

like image 44
Vladislav Soroka Avatar answered Sep 28 '22 08:09

Vladislav Soroka