Using IDEA to refactor a multi-project dependency?
Reusing code across projects is nice. To ensure proper dependencies, you package your reusable code in JARS than can be then reused as simple dependencies across projects.
I've started to do that extensively. And this is great, especially wih the help of Maven.
But some JARS aren't just one public interface and the rest of the implementation cleanly hidden. And when requirements evolve you have to modify those.
The big problem arise in my case when there is more than a single project using that dependency. How can you refactor your dependency without breaking code in the projects that depend on it??
I'm going to explore Maven poms dependency features and give one more look at IDEA's modules, but I don't think those will give me a solution.
How do you handle that kind of situation? Wouldn't it be possible to have a 'Workspace' of projects, or maybe stipulating which internal projects of your company are dependant and should be checked in case of refactoring?
Experience sharing in this field welcome!
-nodje
Please sign in to leave a comment.
if you want to refactor projects on which other projects depend, your best solution is to create a master pom including all of them as modules, and opening this master pom in IDEA.
THis way, all your depending projets will be opened and dependencies should be set between projects, not using the jars from maven repo.
Then you'll be able to refactor
There's no easy solution to this.
First of all you must of course apply strict versioning to your re-used code.
You just have to know what exact version of a shared library each project uses.
That's more of an organizational problem, though.
On the technical side a feature like Eclipse's refactoring scripts can probably help a lot (haven't used it myself):
http://www.eclipsezone.com/eclipse/forums/t72338.html
Unfortunately Idea does not currently have such a generic feature :(
However at least for simple class and package renames, there is a migration feature, see main menu "Refactor -> Migrate".
hi Thibaut,
this looks promising to me. I'm already relying on Maven for my project management, but only in a single pom configuration.
But before proceedings I'd like to make thnigs a little be clearer. Let's say you have this basic dependencies:
A B
\ /
C
From my previous readings, I understood the child - parent relation would only work for the main project and it's project dependencies.
That is, if project A depends on C, C is managed by a child pom and A managed by the master POM (C is a module of A). But if a second independant project B is also depending on C, then it's the same trouble. You cannot have an another master pom for B with the same C child pom used by A, can you?
Unless you mean having the project C, on which A and B depend, being managed by the master pom, and have A & B being managed by child poms, making them modules of C???
Thanks in advance for clarification!
-nodje
thanks for the bad news Stephen ;)
At least I finally understood what the migration feature in IDEA was for.
An I agree with you, it should stay in Diana. It's a pretty useful feature when you need it.
-nodje
what I mean, and am using for my own work, is that you're able to create ad-hoc, temporary master poms, aggregating any number of modules.
If I reuse your example, and let's imagine you've locally checked out your projets A, B, and C in a flat structure (would also work with a non flat one).
parent dir
- A
- B
- C
Nothing prevents you to create a new folder, let's say D, where you can create a pom containing
..\A ..\B ..\C ]]>
Basically I'm using a pom to materialize my workspace, and this is the one I'm opening in IDEA.
Note : as says Stephen this all works if you're able to modify ALL the projects depending on C, if you have some dependent loose, this is a completely different problem
Edited by: Thibaut on May 22, 2008 8:16 AM
this is a very clever one Thibaut!
many thanks for sharing.