我爲我公司開發了一個插件,後來稱爲「myPlugin」。重構後的sonar-packaging-maven-plugin問題
背景: 我在讀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>
到目前爲止一切正常。現在我們來解決我的問題。重構後
現狀: 由於我公司擁有類和包一些命名conevtions我在樹中改變了包名稱爲「com.mycompany.sonar.plugins.myplugin」和每一類中的包decleration也到「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>
當我運行「編譯」命令一切正常。使用「包」不起作用,因爲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
我的問題:爲什麼我的新名字不工作? sonar-packaging-maven-plugin是否有任何內部通知(如包裝名稱必須以「org.sonar」開始)?
感謝您閱讀這篇長文,你的努力幫助我:)
你能提供新的POM片段嗎? – cowls
你想看到什麼?我把它添加到我的問題中(我已經確定沒有輸入錯誤) – Krummy