Question

I need to build a sonar plugin. I am using maven to create project but I am getting error.

Project build error: Unknown packaging: sonar-plugin

my pom.xml is as below:

<?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>       
    <groupId>com.phtpl</groupId>
    <artifactId>sonar-java-plugin</artifactId>
    <name>sonar-java-plugin</name>
    <packaging>sonar-plugin</packaging>
    <version>1.0.0-BUILD-SNAPSHOT</version>     

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>    
   <dependency>
    <groupId>org.codehaus.sonar</groupId>
    <artifactId>sonar-plugin-api</artifactId>
    <version>4.3</version>
</dependency>    
     <dependency>
      <groupId>org.codehaus.sonar.common-rules</groupId>
      <artifactId>sonar-common-rules</artifactId>
      <version>1.2</version>
    </dependency>        
<!-- Test -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>        

<dependency>
    <groupId>org.mockito</groupId>
    <artifactId>mockito-all</artifactId>
    <version>1.8.4</version>
    <scope>test</scope>
</dependency>

<dependency>
    <groupId>org.easytesting</groupId>
    <artifactId>fest-assert</artifactId>
    <version>1.4</version>
    <scope>test</scope>
</dependency>
  <dependency>
    <groupId>org.codehaus.sonar</groupId>
    <artifactId>sonar-deprecated</artifactId>
    <version>4.3</version>
    <scope>test</scope>
</dependency>

    <dependency>
    <groupId>com.mycila.maven-license-plugin</groupId>
    <artifactId>maven-license-plugin</artifactId>
    <version>1.9.0</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-jdk14</artifactId>
      <version>1.6.1</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-nop</artifactId>
      <version>1.6.0</version>
    </dependency>

  </dependencies>

  <build>
  <pluginManagement>
   <plugins>
    <plugin>
        <groupId>org.codehaus.sonar</groupId>
        <artifactId>sonar-packaging-maven-plugin</artifactId>
        <version>1.7</version>
        <extensions>true</extensions>
        <configuration>
            <pluginClass>org.sonar.plugins.java.JavaPlugin</pluginClass>
        </configuration>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
            <source>1.7</source>
            <target>1.7</target>
            <encoding>UTF-8</encoding>
        </configuration>
    </plugin>
</plugins>
    </pluginManagement>
  </build>
</project>

Please provide me a solution.

Thanks in advance!

Was it helpful?

Solution

First of all: sonar-packaging-maven-plugin version 1.9 is available (you are using 1.7)

Within the plugin I developed I am using the following header. You could also try to use the parents in your pom. Do not know if this will fix the problem. If it does not, I could give you 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>
  <parent>
    <groupId>org.codehaus.sonar-plugins</groupId>
    <artifactId>parent</artifactId>
    <version>18</version>
  </parent>

  <artifactId> ....

EDIT 1: My pom.xml: Please make sure you edit all the TODOs I wrote for you. Please notice: I have deleted the license part within my pom, because I did not need it and saw no reason to use it:

<?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>
  <parent>
    <groupId>org.codehaus.sonar-plugins</groupId>
    <artifactId>parent</artifactId>
    <version>18</version>
  </parent>

  <groupId>my.group.id</groupId>
  <artifactId>sonar-my-working-plugin</artifactId>
  <packaging>sonar-plugin</packaging>
  <version>1.0.0</version>

  <!-- TODO 1 -->
  <!-- These information will be displayed later within the update center -->
  <name>My Working Plugin</name>
  <description>Just a plugin I made work.</description>
  <inceptionYear>2014</inceptionYear>
  <url>http://www.mycompany.com</url>
  <organization>
    <name>My Company</name>
    <url>http://www.mycompany.com</url>
  </organization>

  <developers>
    <developer>
      <id>john.doe</id>
      <name>John Doe</name>
      <organization>My Company</organization>
      <organizationUrl>http://www.mycompany.com</organizationUrl>
      <email>john.doe@example.com</email>
    </developer>
  </developers>
  <!-- TODO 1 END -->

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <!-- TODO 2 -->
    <!-- sonar.buildVersio = minimum required Sonar Version to use your plugin-->
    <sonar.buildVersion>3.6</sonar.buildVersion>
    <sonar.pluginName>My My Working</sonar.pluginName>
    <jdk.min.version>1.5</jdk.min.version>
    <!-- TODO 2 END -->
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.codehaus.sonar</groupId>
      <artifactId>sonar-plugin-api</artifactId>
      <version>${sonar.buildVersion}</version>
      <scope>provided</scope>
    </dependency>

    <!-- unit tests -->
    <dependency>
      <groupId>org.codehaus.sonar</groupId>
      <artifactId>sonar-testing-harness</artifactId>
      <version>${sonar.buildVersion}</version>
      <scope>test</scope>
    </dependency>

    <!-- needed dependencies to check for project existens in the Sensor class -->
    <dependency>
      <groupId>org.codehaus.sonar</groupId>
      <artifactId>sonar-ws-client</artifactId>

      <!-- It is recommended to use the same version as the requested SonarQube
        server -->
      <version>2.11</version>
    </dependency>
    <dependency>
      <groupId>commons-httpclient</groupId>
      <artifactId>commons-httpclient</artifactId>
      <version>3.1</version>
    </dependency>

    <dependency>
      <groupId>commons-httpclient</groupId>
      <artifactId>commons-httpclient</artifactId>
      <version>3.1</version>
      <exclusions>
        <exclusion>
          <groupId>commons-logging</groupId>
          <artifactId>commons-logging</artifactId>
        </exclusion>
      </exclusions>
    </dependency>

    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>jcl-over-slf4j</artifactId>
      <version>1.7.6</version>
    </dependency>

    <dependency>
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpclient</artifactId>
      <version>4.1.3</version>
    </dependency>
  </dependencies>

  <build>
    <!-- TODO 3: Change SourceDirectory so it fits to your path containing all you sources
    use / (slash) instead of . (dot) if you are using packages. Maybe just "src" could also work fine -->
    <sourceDirectory>src/my/package</sourceDirectory>
    <!-- TODO 3 END -->
    <plugins>
      <plugin>
        <groupId>org.codehaus.sonar</groupId>
        <artifactId>sonar-packaging-maven-plugin</artifactId>
        <version>1.9</version>
        <extensions>true</extensions>
        <configuration>
          <!-- TODO 4: Change path to your PluginClass -->
          <pluginClass>my.package.MyWorkingPlugin</pluginClass>
          <!-- TODO 4 END -->
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>${jdk.min.version}</source>
          <target>${jdk.min.version}</target>
        </configuration>
      </plugin>
      <plugin>
        <!-- UTF-8 bundles are not supported by Java, so they must be converted
          during build -->
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>native2ascii-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>native2ascii</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
    <outputDirectory>target/classes</outputDirectory>
  </build>

  <!-- TODO 5: You can add here you  <distributionManagement> if you want to do so-->
</project>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top