重构后的声纳包装maven插件有问题

时间:2014-04-02 10:24:45

标签: eclipse maven plugins sonarqube

我在为公司开发插件时遇到了一些麻烦,后来被称为“myPlugin”。

背景 我正在阅读Manning公司出版的“SonarQube in Action”一书。 有一个开发自己的插件的指南(他们使用redmine插件作为开发的例子)。它告诉我使用sonar-plugin-archetype来创建基本框架。

重构前的情况: 我写了插件,它工作正常。我在完成一些重构时遇到了问题。在重构之前,我树中src文件夹中的每个包(使用ecplise)都被称为“main.java.org.sonar.plugins.myplugin”,但每个类中的包解析是“org.sonar.plugins.myplugin”。这是使用sonar-plugin-archetype创建的默认设置。

sonar-packaging-maven-plugin的pom.xml中的设置是以下一次。

Pom-snippet before any changes were done:
<plugin>
   <groupId>org.codehaus.sonar</groupId>
   <artifactId>sonar-packaging-maven-plugin</artifactId>
   <version>1.9</version>
   <extensions>true</extensions>
   <configuration>
     <pluginClass>org.sonar.plugins.myplugin.myPlugin</pluginClass>
   </configuration>
</plugin>

到目前为止一切正常。现在我们来解决我的问题。

重构后的情况: 由于我的公司对类和包有一些命名标准,我将树中的包名称更改为“com.mycompany.sonar.plugins.myplugin”,并且每个类中的包解除也改为“com.mycompany.sonar.plugins.myplugin” ”。然后我将sonar-packaging-maven-plugin的classPath选项更改为“com.mycompany.sonar.plugins.myplugin.myPlugin”。我所说的就是改变“组织”。进入“com.mycompany。”。

Pom-snippet after changes were done:
<plugin>
   <groupId>org.codehaus.sonar</groupId>
   <artifactId>sonar-packaging-maven-plugin</artifactId>
   <version>1.9</version>
   <extensions>true</extensions>
   <configuration>
     <pluginClass>com.mycompany.sonar.plugins.myplugin.myPlugin</pluginClass>
   </configuration>
</plugin>

当我运行“编译”命令时,一切正常。使用“package”不起作用,因为sonar-packaging-maven-plugin无法找到给定的类(请参阅下面的控制台输出)。当我再次将所有内容重新开始时,它再次起作用。

[...] 
[INFO] --- sonar-packaging-maven-plugin:1.9:sonar-plugin (default-sonar-plugin) @ sonar-projectkeychecker-plugin ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 19.649 s
[INFO] Finished at: 2014-04-02T11:42:01+01:00
[INFO] Final Memory: 13M/67M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.sonar:sonar-packaging-maven-plugin:1.9:sonar-plugin (default-sonar-plugin) on project sonar-myplugin-plugin: Plugin class not found: 'com.mycompany.sonar.plugins.myplugin.myPlugin-> [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/MojoExecutionException

我的问题:为什么我的新名字不起作用?声纳包装maven插件是否有任何内部对流(就像包装名称必须以“org.sonar”开头一样)?

感谢您阅读这篇长篇文章,并尝试帮助我:)

2 个答案:

答案 0 :(得分:2)

pluginClass是插件的入口点。值必须是现有类。在你的例子中,我认为有一个拼写错误,它应该是com.mycompany.sonar.plugins.myplugin.MyPlugin(大写M)。

答案 1 :(得分:-1)

<plugin>下,我缺少<extensions>true</extensions>标签