views:

3265

answers:

4

I'm defining a report configuration in my parent pom which will be run in each child and grandchild project.

Like so:

<reporting>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>findbugs-maven-plugin</artifactId>
            <version>1.2</version>
            <configuration>
                <xmlOutput>true</xmlOutput>
                <threshold>Low</threshold>
                <effort>Min</effort>
                <includeFilterFile>${basedir}/findbugsFilter.xml</includeFilterFile>
            </configuration>
        </plugin>
    </plugins>
</reporting>

The trouble is that each child inserts its basedir rather than the defining POM. I suppose I'm looking for the equivalent to ANT's <property name="name" location="${basedir}"/>. Any ideas?

+1  A: 

Hi,

I am not sure if this can solve your problem, but I have two ideas that you can try:

1st idea

Define a property in the parent pom, and use it in the report configuration:

<properties>
    <parent-basedir>${basedir}</parent-basedir>
</properties>
...
<reporting>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>findbugs-maven-plugin</artifactId>
            <version>1.2</version>
            <configuration>
                <xmlOutput>true</xmlOutput>
                <threshold>Low</threshold>
                <effort>Min</effort>
                <includeFilterFile>${parent-basedir}/findbugsFilter.xml</includeFilterFile>
            </configuration>
        </plugin>
    </plugins>
</reporting>

2nd idea

Another idea is to use ${project.parent.basedir}:

...
<includeFilterFile>${project.parent.basedir}/findbugsFilter.xml</includeFilterFile>
...
romaintaz
I've tried the first. It didn't work either. The second, doesn't work in the grandchild projects.
sblundy
A: 

This is related to your other question.

Have you given up the idea of deploying the filter file in a separate artifact? Why?

The problem with an absolute path is that you don't have any guarantee that the parent project's sources will be present on the machine when you build a child project. That's the whole point of having a repository mechanism.

Have you tried my suggestion to your other question?

Olivier
A: 

The short version: The solution to your problem is described in the documentation of the findbugs-maven-plugin. You simply have to create a separate (top-level) project for the build configuration that contains your findbugsFilter.xml and reference that project as a dependency.

The long version: Accessing recources from parent or sibling projects in Maven is a bit complicated unfortunately. The reason for this: When building a child project Maven can't assume that the parent module is one level up or a sibling project is on the same level in the file system. In fact, it can't assume any of these projects are even checked out somewhere! It's perfectly legal to only check out a single child project and build that as is. Thus, when building with Maven everything (with very few exceptions) is loaded from your local repository. And this is why you have to create separate projects for resources you want to use in multiple modules. The separate project can then be added as a dependency and be used by a bunch of different Maven plugins. Examples are: The checkstyle and findbugs plugins to read config files, the maven-dependency-plugin to copy external files into your artifacts or the properties-maven-plugin to load external properties files.

Thomas Marti
+1  A: 

I had a similar problem where I wanted the child POM's to have the same properties file as the parent, but I could not get the ${project.parent.basedir} variable to work.

However what I did was create a variable in the parent, and overwrote the same variable in each of the child Pom's (this should work for grand-poms too... although I didn't have any).

For example:

Parent POM:
    <properties>
        <my_basedir>${basedir}</my_basedir>
    </properties>


Child POMs:
    <properties>
        <my_basedir>${basedir}/../</my_basedir>
    </properties>

Now I just list the filter once in the parent, and everyone else gets it. If you move the child, you just change the relative path.

   <filters>
       <filter>${my_basedir}/myfile.properties</filter>
   </filters>