Could anayone give me some sugestions on how to create a pom.xml file for a multimodules project, that is build with ant? I need to create this pom.xm开发者_开发技巧l file in order to analyze the project with Sonar.
I suggest to follow the instructions from the Sonar documentation. See Analyzing Java Projects:
Project with multiple sources directories
If your non-maven project contains more than one sources directory, you can specify which sources directories to analyse by adding a new section about the Build Helper Maven Plugin into your pom.xml file :
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>[YOUR.ORGANIZATION]</groupId> <artifactId>[YOUR.PROJECT]</artifactId> <name>[YOUR PROJECT NAME]</name> <version>[YOUR PROJECT VERSION]</version> <build> <sourceDirectory>[YOUR SOURCE DIRECTORY]</sourceDirectory> <outputDirectory>[YOUR CLASSES/BIN DIRECTORY</outputDirectory> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.5</source> <target>1.5</target> <excludes> <exclude>**/*.*</exclude> </excludes> </configuration> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <version>1.1</version> <executions> <execution> <id>add-source</id> <phase>generate-sources</phase> <goals> <goal>add-source</goal> </goals> <configuration> <sources> <source>[YOUR SOURCE DIRECTORY 2]</source> <source>[YOUR SOURCE DIRECTORY 3]</source> </sources> </configuration> </execution> </executions> </plugin> </plugins> </build> <properties> <sonar.dynamicAnalysis>false</sonar.dynamicAnalysis> <sonar.phase>generate-sources</sonar.phase> </properties> </project>
Replace the parameters :
...
And execute the maven2 plugin as explained in the installation guide :
mvn sonar:sonar
There is now a Sonar Ant Task that you can use, or there is also the Sonar Runner
What you put in the pom.xml is going to depend what dependencies you need to use and what plugins you need to run. Check out the Intro to POM to see what it is made up of.
I think you can try to use the builder-helper-maven-plugin, currently, latest version is 1.5. as documented http://docs.codehaus.org/display/SONAR/Analyzing+Java+Projects. However, just change the plugin version to 1.5 and use mvn sonar3:sonar. Most importantly, dont forget <sonar.phase>generate-sources</sonar.phase>, without this, it doesn't work.
as for the output directory, if using eclipse, you can specify the output directory for each module, and make them point to the same folder. Use this folder as the outputdirectory for pom.xml. remember to disable scrub, if using eclipse.
精彩评论