Create pom.xml file

Can anyone give me some tips on how to create a pom.xml file for a multi-module project that is created using ant? I need to create this pom.xml file to parse the project using Sonar.

+4
source share
4 answers

I suggest following the instructions from the Sonar documentation. See Java Project Analysis :

Project with multiple source directories

If your non-maven project contains more than one directory of sources, you can specify which directory sources to analyze by adding a new section about the Build Helper Maven plugin to the 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 options:

    ...

  • And execute the maven2 plugin as described in the installation guide:

     mvn sonar:sonar 
+7
source

Now there is a Sonar Ant Task that you can use, or there is a Sonar Runner

+1
source

What you put in pom.xml will depend on the dependencies you need to use and what plugins you need to run. Check out Intro to POM to find out what it consists of.

0
source

I think you can try using the builder-helper-maven plugin, currently the latest version is 1.5. as described by 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, do not forget to <sonar.phase> generate sources </sonar.phase>, without this it does not work.

as for the output directory, if you use eclipse, you can specify the output directory for each module and point them to the same folder. Use this folder as the output directory for pom.xml. do not forget to disable the scrub if using eclipse.

0
source

Source: https://habr.com/ru/post/1314711/


All Articles