Problem with custom xml rule

Hi, i’m trying to make a rule in which the version of xpto.micronaut cannot be lower than 4.9.*, however, the rule is not being applied.

SonarQube version: 10.2.1

My custom rule:

My project pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<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>

    <parent>
        <groupId>xpto.micronaut</groupId>
        <artifactId>microservice-bom</artifactId>
        <version>4.8.0.RC</version>
    </parent>

    <groupId>br.com.xpto</groupId>
    <artifactId>teste-pipe</artifactId>
    <version>1.0.0-SNAPSHOT</version>

    <properties>
        <arch.codegen.modelPackage>core.autogen.models</arch.codegen.modelPackage>
        <arch.codegen.controllerPackage>core.autogen.controllers</arch.codegen.controllerPackage>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <arch.app>br.com.xpto.Application</arch.app>
    </properties>

    <build>
        <finalName>${pom.artifactId}-${pom.version}</finalName>  <!-- Code smell test -->
    <pluginManagement>
        <plugins>
                <plugin>
                    <groupId>org.sonarsource.scanner.maven</groupId>
                    <artifactId>sonar-maven-plugin</artifactId>
                    <version>3.9.0.2155</version>
                </plugin>
        </plugins>
    </pluginManagement>
    </build>
</project>

Please help me.

Hi,

The screenshot of your rule shows a forbidden version of 4.10.*. Since 4.9.0.RC != 4.10.*, I’m not surprised no issue is raised.

Based on the text in the screenshot, I suspect you need a version pattern something like 1.0.*-4.8.*

 
HTH,
Ann

Hi Ann, thank you for your help!

I switched to the 1.0.*-4.8.* pattern, but it didn’t work either. Is there a problem with this being in a <parent> tag and not in a <dependency> tag ?

Hi,

Well… the rule is built to look at… dependencies.

I would play around with it:

  • try setting the version specifically to the one in your pom
  • try moving the dependency to actually show up in the pom as a dependency

 
HTH,
Ann

Hi Ann! Thanks for helping me! The problem is that it doesn’t really work in the <parent> tag, it necessarily has to be in the <dependency> tag.

Now I’m going to have to find a solution for this, do you have any suggestions?

Thank you very much.

Hi,

Your other option is xml:XPathCheck, which is a pure XPath 1.0 query template rule. It’s doable, but a looot harder.

And when you’re looking up XPath syntax guides, make sure you stick to 1.0 syntax.

 
HTH,
Ann

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.