I read the python demo given by the official documentation
master/python-custom-rules
Shows how to bootstrap a project to write custom rules for Java, JS, PHP, Python, Cobol, RPG - sonar-custom-rules-examples/python-custom-rules at master · SonarSource/sonar-custom-rules-examples
It was found that it did not build successfully. . .
Someone asked this question in 2020. Is this project still being maintained?
opened 02:24PM - 15 Nov 20 UTC
I cloned the repo and build java and php examples easily.
But for python, using… `<sonar.python.version>2.0-SNAPSHOT</sonar.python.version>` throws the following error
```
[ERROR] Failed to execute goal on project python-custom-rules-plugin: Could not resolve dependencies for project org.sonarsource.samples:python-custom-rules-plugin:sonar-plugin:1.0-SNAPSHOT: Could not find artifact org.sonarsource.python:sonar-python-plugin:jar:2.0-SNAPSHOT -> [Help 1]
```
I changed
`<sonar.python.version>2.0-SNAPSHOT</sonar.python.version>` to
`<sonar.python.version>2.0.0.5043</sonar.python.version>` and it fixed the previous error.
But now I'm facing the following:
```
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.7.0:compile (default-compile) on project python-custom-rules-plugin: Compilation failure: Compilation failure:
[ERROR] /home/masoud/military/sonar-custom-rules/python-custom-rules/src/main/java/org/sonar/samples/python/checks/CustomPythonVisitorCheck.java:[24,36] cannot find symbol
[ERROR] symbol: class PythonCheckTree
[ERROR] location: package org.sonar.plugins.python.api
[ERROR] /home/masoud/military/sonar-custom-rules/python-custom-rules/src/main/java/org/sonar/samples/python/checks/CustomPythonVisitorCheck.java:[32,47] cannot find symbol
[ERROR] symbol: class PythonCheckTree
[ERROR] /home/masoud/military/sonar-custom-rules/python-custom-rules/src/main/java/org/sonar/samples/python/checks/CustomPythonVisitorCheck.java:[36,3] method does not override or implement a method from a supertype
[ERROR] /home/masoud/military/sonar-custom-rules/python-custom-rules/src/main/java/org/sonar/samples/python/checks/CustomPythonVisitorCheck.java:[38,5] cannot find symbol
[ERROR] symbol: method addIssue(org.sonar.plugins.python.api.tree.Name,java.lang.String)
[ERROR] location: class org.sonar.samples.python.checks.CustomPythonVisitorCheck
[ERROR] /home/masoud/military/sonar-custom-rules/python-custom-rules/src/main/java/org/sonar/samples/python/checks/CustomPythonVisitorCheck.java:[39,5] cannot find symbol
[ERROR] symbol: variable super
[ERROR] location: class org.sonar.samples.python.checks.CustomPythonVisitorCheck
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
```
This is my 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.sonarsource.samples</groupId>
<artifactId>python-custom-rules-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>sonar-plugin</packaging>
<name>Python Custom Rules Plugin</name>
<description>Python Custom Rules</description>
<properties>
<sonar.python.version>2.0.0.5043</sonar.python.version>
</properties>
<dependencies>
<dependency>
<groupId>org.sonarsource.sonarqube</groupId>
<artifactId>sonar-plugin-api</artifactId>
<version>7.9</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.sonarsource.python</groupId>
<artifactId>sonar-python-plugin</artifactId>
<type>sonar-plugin</type>
<version>${sonar.python.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.sonarsource.python</groupId>
<artifactId>python-checks-testkit</artifactId>
<version>${sonar.python.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.sonarsource.sonar-packaging-maven-plugin</groupId>
<artifactId>sonar-packaging-maven-plugin</artifactId>
<version>1.18.0.372</version>
<extensions>true</extensions>
<configuration>
<pluginClass>org.sonar.samples.python.CustomPythonRulesPlugin</pluginClass>
<requirePlugins>python:${sonar.python.version}</requirePlugins>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
```
If the demo of the python plugin has the latest changes or a more complete implementation, please reply to me, thank you!
Hello @dr.missname ,
Sorry for the late reply!
Indeed we didn’t maintain sonar-custom-rules-example
for a while but we recently fixed a few issues in it and now it should build successfully.
Hope that helps you!
system
(system)
Closed
July 12, 2022, 9:38am
7
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.