我需要构建一个声纳插件。我正在使用maven创建项目但我收到错误。
项目构建错误:未知包装:sonar-plugin
我的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>
<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>
请给我一个解决方案。
提前致谢!
答案 0 :(得分:1)
首先:sonar-packaging-maven-plugin
版本1.9可用(您使用1.7)
在我开发的插件中,我使用以下标题。你也可以尝试在你的pom中使用父母。不知道这是否能解决问题。如果没有,我可以给你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> ....
编辑1:
我的pom.xml
:请确保编辑我为您编写的所有TODO。请注意:我已删除了我的pom中的许可证部分,因为我不需要它并且没有理由使用它:
<?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>