category.pom.errorprone.xml Maven / Gradle / Ivy
<?xml version="1.0" encoding="UTF-8"?> <ruleset name="Error Prone" xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd"> <description> Rules to detect constructs that are either broken, extremely confusing or prone to runtime errors. </description> <rule name="InvalidDependencyTypes" language="pom" since="5.4" message="By default, Maven only recognizes the following types: pom, jar, maven-plugin, ejb, war, ear, rar, par." class="net.sourceforge.pmd.lang.rule.xpath.XPathRule" externalInfoUrl="${pmd.website.baseurl}/pmd_rules_pom_errorprone.html#invaliddependencytypes"> <description> If you use an invalid dependency type in the dependency management section, Maven doesn't fail. Instead, the entry is just ignored, which might have the effect, that the wrong version of the dependency is used. The following types are considered valid: pom, jar, maven-plugin, ejb, war, ear, rar, par. </description> <priority>3</priority> <properties> <property name="xpath"> <value> <![CDATA[ //dependencyManagement/dependencies/dependency/type/text[not(@Text = $validTypes)] ]]> </value> </property> <property name="validTypes" value="pom,jar,maven-plugin,ejb,war,ear,rar,par" type="List[String]" description="Set of valid types."/> </properties> <example> <![CDATA[ <project...> ... <dependencyManagement> ... <dependency> <groupId>org.jboss.arquillian</groupId> <artifactId>arquillian-bom</artifactId> <version>${arquillian.version}</version> <type>bom</type> <!-- not a valid type ! 'pom' is ! --> <scope>import</scope> </dependency> ... </dependencyManagement> </project> ]]> </example> </rule> <rule name="ProjectVersionAsDependencyVersion" language="pom" since="5.4" message="Do not use project.version to express a dependency version." class="net.sourceforge.pmd.lang.rule.xpath.XPathRule" externalInfoUrl="${pmd.website.baseurl}/pmd_rules_pom_errorprone.html#projectversionasdependencyversion"> <description> Using that expression in dependency declarations seems like a shortcut, but it can go wrong. By far the most common problem is the use of \${project.version} in a BOM or parent POM. </description> <priority>3</priority> <properties> <property name="xpath"> <value> <![CDATA[ //dependencies/dependency [contains(version/text/@Text,'{project.version}')] [ (/document/project/parent/groupId and groupId/text/@Text != /document/project/parent/groupId/text/@Text) or (/document/project/groupId and groupId/text/@Text != /document/project/groupId/text/@Text) ]/version ]]> </value> </property> </properties> <example> <![CDATA[ <project...> ... <dependency> ... <version>\${project.version}</version> </dependency> </project> ]]> </example> </rule> </ruleset>