Category Archives: Maven

Enhanced find usages support in NetBeans >= 7.1

In my opinion, Netbeans is one of the most intuitive Java IDE today, especially when it comes to maven development. There was just one missing feature I was always upset about. The IDE was not indexing classes and their dependencies in the local maven repository. So it was not possible to find referenced classes contained in maven projects that weren’t opened  in the IDE. This is quiet annoying if you need to gain an overview of the code, or you have to track down one specific misbehavior especially if you work with hundreds of maven projects.

So, together with Netbeans contributors (mainly Jesse Glick), we’ve worked out a solution for the problem.

The class dependencies were found by bytecode parsing and then indexed with Lucene for very fast search results. All classes from the JDK are excluded to reduce the overhead.

Find Usages in action

In the following example, I selected the class “org.apache.maven.artifact.ArtifactUtils” and searched with “Find Usages” for all referring classes. The class is used as an import in one of the classes in the only loaded maven project  “Maven Release Plugin”.

This gave me the following output:

Under the node “Maven Repository: local” are all hits listed found in the local maven repository. This enables the developer to quickly scan all interesting artifacts without the need to open any maven project in Netbeans.

For now, only the class name is highlighted and linked to the corresponding class located in the maven artifact. I plan to implemented the same behavior as seen as in the search results for already opened projects, in this case “Maven Release Plugin” which features enhanced line highlighting and more precisely jumps to the source code.

Conclusion

It took my some time to get used to a small part of the massive code base of Netbeans and it’s API’s but it felt good to give something back to the community.

Last but not least, I was able to improve my knowledge in programming across the board which was a lot of fun!  😎

 

Eclipse 3.7 Indigo with M2E – lifecycle connectors

Recently Eclipse 3.7 Indigo with M2E Plugin 1.0.0 was released.  Since Eclipse 3.7, M2E is part of the Eclipse Foundation. I had expected better of it.

Since M2E 1.0.0, the plugin features a new life-cycle connector concept for maven-plugins. M2E users are now forced to provide a connector for every plugin used in their builds or if none connectors are available, to ignore the connectors. Unfortunately, to ignore the missing connectors the user is required to modify his pom files for M2E to work properly.

If a maven-plugin is missing a connector, M2E will show you errors like: Plugin execution not covered by lifecycle configruation: {plugin-GAV-goals} and prompts you to modify your project pom or parent pom as following:

 

 

This means that M2E is no longer an interpreter of Maven, it’s a modifier. It binds your independent Maven projects to a specific IDE, which is in my opinion the wrong path. I’d prefer a much more “lighter” Maven integration in Eclipse, for example like NetBeans 7.x does. This led to several discussions on the M2E mailing-list. As a result, I created an enhancement-request with collected and own suggestions from the list.

I hope an enhancement will soon be released, I could imagine that this will be a real deal breaker for several users to use M2E-1.0.0+.

Maven artifact sources / javadoc download

Artifact sources resolution

Um mit Maven alle sourcen der verwendeten direkten und transitiven dependencies aufzulösen, wird folgendender plugin Aufruf verwendet:

[cc lang=’text’ line_numbers=’false’]mvn dependency:sources[/cc]

Nun muss man wissen, dass nach dem Aufruf im target Verzeichnis des entsprechenden Projektes ein cache-Ordner “dependency-maven-plugin-markers” erstellt wird. Dies verhindert ein erneutes auflösen der sourcen beim selbigen Aufruf.

Mit einem vorangehenden clean kann das dependency Plugin zu einem erneuten lookup gezwungen werden.

[cc lang=’text’ line_numbers=’false’]mvn clean dependency:sources[/cc]

Unter welchen Bedingungen der cache des plugins geleert wird ist mir nicht bekannt und aus der Dokumentation leider nicht ersichtlich.

Die oben gezeigten Befehle funktionieren nur, wenn der default classifier “sources” für die source artifacts verwendet wurde wie zum Beispiel hier: “junit-4.8.1-sources.jar”.

Einen ähnlichen Effekt kann man erzielen mit:

[cc lang=’text’ line_numbers=’false’]mvn dependency:resolve -Dclassifier=sources[/cc]

Hier wird allerdings kein cache im target abgelegt, die sourcen werden direkt ins lokale Repository geladen, ansonsten ist das Resultat dasselbe.

Artifact javadoc resolution

Mit dem folgeden Befehl werden alle javadocs aufgelöst.

[cc lang=’text’ line_numbers=’false’]mvn dependency:resolve -Dclassifier=javadoc[/cc]

Wieder unter der Vorraussetzung, dass der standart classifier -javadoc nicht verändert wurde.

Weiterführende Links

http://maven.apache.org/plugins/maven-dependency-plugin/sources-mojo.html