Thursday, 27 March 2008

[LazyWeb] a maven plugin to find resources on your maven dependency path

Every now and again I get the dreaded log4j.properties / log4j.xml maven transitive dependency hell. Some resource is included in multiple jars so the one you think you're meant to be using isn't found first. 

e.g. you try changing the log4j levels and nothing happens. Much scratching of head occurs. Normally through frustration you shove a load of System.out.println() calls in your app :)

So the idea is how about being able to do something like
mvn classpath:find -Dresource=log4j.properties
and the plugin would search all the test scoped jars on the classpath, including transitive dependencies letting you know all the jars (and the dependency path to them) which included the resource you specified.

It'd be handy right? Any volunteers... :)

6 comments:

Brett said...

I'd suggest filing a request under the MDEP (maven-dependency-plugin) project - this is pretty closely related to code already in there and could probably be added pretty easily

steve_l said...

You mean you want a reimplementation of Ant's <whichesource> task?
http://ant.apache.org/manual/CoreTasks/whichresource.html

James Strachan said...

Brett - will do thanks

Steve - not so much re-implementation, just a way to invoke it easily from any mvn build without having to mess with the pom.xml. i.e. having a standard mvn plugin we can use on any maven project to invoke the <whichsource> task

James Strachan said...

Brett : Done!

http://jira.codehaus.org/browse/MDEP-158

I was a tad surprised to see maven using codehaus for its JIRA :)

Emmanuel said...

whichresource task and the James's proposal are a bit different. whichresource search in the classpath but James want to search in jars filtered by a scope so it isn't a reimplementation but a new implementation of the search

Lee said...

I have used a line like this to find multiple log4j.properties files. One "gotcha" here is that there can be code supplying the log4j configuration or loading it from either properties or xml files of any name.

Enumeration logConfigEnum = this.getClass().getClassLoader().getResources("log4j.properties");

(I know this code has to run in the application and the request was for Maven to look around in the dependency jars. I'm just ignoring that.)