Wednesday, June 27, 2007

Maven and NetBeans (Platform)

As most of you know, the build system in the NetBeans IDE is entirely ANT-centric. That is, every project has a generated build.xml behind the scenes and every action (compile, run) is an ant target actually.

But, of course, you can't please everyone. Using ANT as a backend means that, of course, you need some custom ant targets to make the IDE-integration better. Thus, you're not 100% independent of NetBeans, you still need those custom tasks (some JARs basically) and the core ant scripts.

Using ANT also means some overhead for each action.

But the most nasty stuff in my projects are the 3rd party JARs. Most projects use some outside blobs. Normally, you can have the JARs in SVN and NetBeans will take care of this quite nicely (using relative paths).

But what happens if you decide not to include those JARs in the SVN ? Well, you enter a world of tweaking of .properties files and custom ant tasks to re-populate those properties files. It's not pretty and error-prone in a distributed project.

Maven on the other side has this repository concept. That is, a place where some 3rd party JARs sit. Your POM file (project metadata basically) just declares the dependencies and the repository list.

Imagine that: you have a local intranet repository and everyone in the team is using it. No more relative paths, no more custom ant tasks !

I've been migrating my SVN for about 3 weeks over to maven. I have normal Java projects, Enterprise projects (EJB/WAR) and NetBeans Platform modules (NBM). It's a bumpy road (I haven't used maven until now) but it does seem to simplify thigs.

But what you win on the dependency side you lose on the integration part. With MevenIDE you have normal NetBeans IDE projects, but not that kind of IDE-integration you have to module-projects for example. No more easy configuration for public-packages -- back to editing manifest files like in the old NetBeans 3.x times ;-)

Overall, Maven2 seems a better choice for the build backend then Ant. You can't customize it that much but once you have all the plugins properly configured, it works better. Plus that you are totally decoupled from the IDE and IDE tasks, but you depend now on the extra plugins.

Most of the continuous integration servers offer support for Maven2 projects so you can drop the new projects immediately.


Markus said...

I would like to move over to Maven to build our RCP application. I have started to look at nbm-maven-plugin.

In the ideal world, that plugin should generate nbms for my modules and Library Wrappers for the dependencies. However Maven has transative dependencies and Netbeans hasn't so it's not that easy.

Emilian Bold said...

I just use scope:provided for things I just need at compile-time.

Also the new maven-nbm-plugin (2.5) generated the netbeans dependencies quite nicely. The 2.4 depends more on the "descriptor" file where you specifically define which artifacts are netbeans dependencies and which artifacts are "libraries" (ie. wrapped).

What other problems did you encounter that are not so easy ?

I might also add that the mevenide mailing list is really helpful. Give it a try.

Markus said...

Do you know of any open source module project that uses maven-nbm-plugin? I think I would benefit from an example.

Emilian Bold said...

I just used the documentation and the mailing list. MevenIDE is using maven-nbm-plugin so you might want to chechout the sources to that and see how they did it.

අයිතිකාරයා said...

Hi Emilian,

I believe that you are the best person to ask this question.

I have an idea to develop a open source maven plugin to generate toString() method (and later some other important methods such as equals, hasCode). First I tried with Jalopy. But it was to complected and unable to save AST back. Also AST structure is very messy (May be for me)

Then I tried with netbeans api, Awesome, Its fantastic, but could only modify AST for "WorkingCopy" using your examples, (Not in a maven project, but in netbeans IDE). Since netbean is capable to open maven projects directly from POM without any maven plugins, I believe that therer is a high possibility to build netbeans AST for a maven project outside of Netbeans IDE.

Can you please give some hints to create netbeans AST outside of the IDE for a maven project, and how to work on other copies other than WorkingCopy.

Your support in this regards highly appreciate.


The Trouble with Harry time loop

I saw The Trouble with Harry (1955) a while back and it didn't have a big impression on me. But recently I rewatched it and was amazed a...