Tuesday, 21 February 2012

IntelliJ Idea 11 and groovy/gradle projects fun and games

Part 1: That darned case when you lose all your gradle 'external libraries' stuff.

I tend to create groovy/gradle projects like this:

mkdir -p src/main/groovy/com/${COMPANY}/${GROUP}/${PROJECT_NAME}
mkdir -p src/main/runtime
cp /global/log4j.properties src/main/runtime
mkdir -p src/main/resources
mkdir -p src/test/groovy/com/${COMPANY}/${GROUP}/${PROJECT_NAME}
cp /global/build.gradle .
cd ..
svn add com.${COMPANY}.${GROUP}.${PROJECT_NAME}
svn -m Creation commit com.${COMPANY}.${GROUP}.${PROJECT_NAME}
svn propset svn:ignore -F /file/with/.gradle/and/build/in/it.txt .
svn -m Upload commit .

That's overblown, but you get the idea.
My dev style tends towards floating back and forth between IDEs and just plain vi/cmd line.
Sort of like companies floating between out/in sourcing.
I get pissed off with Eclipse, switch to Netbeans, get pissed off, switch to IntelliJ, get pissed off, switch to the cmd line, get pissed off, switch to Eclipse... Round and round we go.

Recently I decided to commit myself to IntelliJ Idea 11 (for a while).
And ran into problems with library dependencies.
First up I have two offices.
So If I committed the blah.blah.iml to SVN at the office and then tried updating at home, Idea11 had issues.
The reason is the:


Stuff in the blah.blah.iml file.
Your hash key won't be the same as the one in your ~/.gradle/caches/artifacts-7/artifacts/... folder.
The trick is to make sure your global build.gradle has 'apply plugin: idea' in it, and run 'gradle idea'.
This will create a new blah.blah.iml file.
(along with an .ipr and iws file which you can safely delete)
Your project will now open and correctly load all the dependencies.
Just remember not to commit your 'at-home' .iml file unless you feel inclined to do the same thing at your office...

Part 2: You've created a plain groovy/gradle project and you just can't get Idea11 to open it.

This is probably because you're using some external build.gradle with the 'apply from: /some/global/build.gradle'
You just get this annoying 'unable to resolve' popup and you're stuffed.
The reason is that Idea11's module IS the .idea folder, and you don't have one.

The trick is the similar to the above.
Do the 'gradle idea' trick at the cmd line, then create a NEW project BUT DON'T CREATE A MODULE.
Then once you have the project loaded, add the module by pointing at the .iml file.

No comments:

Post a Comment