Thoughts about java, ruby, agile and other every developer stuff.

Friday, February 09, 2007

Mavenization Idea

Finally, we did it. Our project was gained maven nature. The process of conversation is NOT so simple, as I thought when I started. I share my experiences during this migration.

Mavenize your project structure

It is possible to make maven work with your actual project structure, but as I know now, the first maven rule is "Don't fight with maven”.

When structure is mavenized your entire project looks the same way, and of course you find resources there where you suppose too.

Move your webapp part to src/main/webapp. In this directory you should have all the stuff going to web archive.

The hardest is how to separate java files which should be in src/main/java and java resources such properties, validations, and other stuff which should be in src/main/resources. In our company we have a tool which makes this for us. You can write yours, or use shell utils such as find, awk, and grep.

Next move all your ant stuff (properties, libraries) exclude build.xml to src/test/deprecated. Finally you should have clear maven Standard Directory Layout. For further information visit maven SDL site.

Useful tools

Without tools you are naked ;). When you want make maven SDL you must use tools. Of course when you don't want keep your versions control history you can do it just by deleting all files, moving them to SDL structure.

find - your first friend with -exec parameter.
sed & awk - sometimes we must rename path (for example sed 's/main/test/' in.file >out.file)
grep - it's always useful

When you work on windows, my suggestion is : if you don't have cygwin, install it. Build generate.sh file with UNIX tools, which generate for you bat files. Run it in windows command shell and go for coffee brake.

Keep your build.xml alive

The most important task is modifying build.xml file to work with new file structure. When you do this, you can switch to maven structure when all your team is on the lunch. Second maybe more important, if you want have time to make another step, prepare good how to switch work from previous structure to maven way. IT'S THE MOST IMPORTANT. And remember it must be easy and complete. Test it, and at least one another person should test it.

Write your pom

Its easy part, write task from beginning to end, and don’t forget to tell someone to test it, because you may have special setting, which won't work in another environment. Once you finish and check that pom.xml makes everything as build.xml. You should once again write proper documentation how to replace old task the new one. Makes profiles with filters.

Watch out, maven doesn't recognize that you filtering filter. In this case he hangs on resource:resource phase depends on configuration.
And it is not obvious to catch this. So be careful.

Finally kill deprecated

At least after all this steps, you can kill deprecated directory. First libs I think, next the rest. Ok one thing if you run in trouble I suggest use -X option. Than you should live long and peacefully.

Pedro

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home