Reputation: 5677
I'm trying to share the same pmd configuration across all my submodules. I'm looking for the best way to achieve that
I thought that I could place it in the parent project, like I did it for checkstyle plugin
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<configLocation>/src/main/config/checkstyle.xml</configLocation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>2.7.1</version>
<configuration>
<rulesets>
<ruleset>pmd.xml</ruleset>
</rulesets>
<linkXref>true</linkXref>
<sourceEncoding>${project.build.sourceEncoding}</sourceEncoding>
<targetJdk>${maven.compiler.target}</targetJdk>
</configuration>
</plugin>
</plugins>
</build>
Here my structure
parent
|-- src
| `-- main
| `-- resources
| |-- pmd.xml
| `-- checkstyle.xml
|-- pom.xml
|-- model
| `-- pom.xml
`-- webapp
`-- pom.xml
With this configuration, I only obtain the following error :
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-pmd-plugin:2.7.1:pmd (default-cli) on project model: An error has occurred in PMD Report report generation. Could not find resource 'pmd.xml'. -> [Help 1]
I tried this solution that works for me, because I only have one level on submodules : But in a close future, I may have more levels, so I'm not convinced that's THE method ${basedir}/../src/main/resources/pmd.xml
Without writing all the solution, I can use an assembly to zip my config and use it in all my submodule as an dependency. This would work for any levels, but this is overkilling !
Here a link that would explain it: How to include resources from war to another maven project
So I'm looking for a Maven trick, but I don't what or how ! Every advice / clue is welcome.
Upvotes: 4
Views: 4557
Reputation: 2979
I was reading the documentation for the ruleset tag and it says
The rule sets may reside in the classpath, filesystem or at a URL. For rule sets that are bundled with the PMD tool, you do not need to specificy the absolute path of the file. It will be resolved by the plugin. But if the rule set is a custom rule set, you need to specify its absolute path.
I solved the problem of sharing my PMD settings across my multi-maven build by specifying the URL to the ruleset file in my parent pom. (My repo was http accessible). Unfortunately this won't work though if you don't have your repo http accessible, but many people may.
Upvotes: 1
Reputation: 29912
Have a separate module that contains those generic config files like build-tools. Then you can add this module as a dependency to your plugin config and load it.
I have implemented an example of this with a checkstyle config file across a multiple modules in the ksoap2-android project.
https://github.com/mosabua/ksoap2-android/blob/master/pom.xml
Upvotes: 3