2013-03-21 41 views
2

我有一個相當大的maven項目,有一堆子項目,我的竹實例使用「mvn clean deploy」運行連續構建。另外還有一個單獨的夜間「mvn clean sonar:sonar」,該錯誤與下面的錯誤不符。當聲納:sonar插件運行時,Maven編譯失敗無法訪問帶有@Nonnull註釋的Enum

MediaServiceType是正在編譯的子項目的主要java部分中的Enum,它實現了來自另一個項目的接口。 AbstractToolTest與MediaServiceType位於同一個包中,因此它不顯示完整的包名稱。有問題的線路只是從接口類型轉換爲MediaSerivceType。

我認爲我的pom出了問題,但用-X看着構建,java編譯器實際上註銷了類路徑,並且包含一個具有MediaServiceType.class的文件夾。我也不知道該怎麼做的錯誤是「無法訪問MediaServiceType」,而不是找不到類。

什麼會導致這種問題?

21-Mar-2013 10:45:46 [INFO] ------------------------------------------------------------------------ 
21-Mar-2013 10:45:46 [ERROR] BUILD ERROR 
21-Mar-2013 10:45:46 [INFO] ------------------------------------------------------------------------ 
21-Mar-2013 10:45:46 [INFO] Can not execute Sonar 
21-Mar-2013 10:45:46  
21-Mar-2013 10:45:46 Embedded error: Unable to execute maven plugin 
21-Mar-2013 10:45:46 Compilation failure 
21-Mar-2013 10:45:46 /data/bamboo/xml-data/build-dir/PRO-PROTRUNKSONAR-JOB1/processors/processor-tool/src/test/java/company/prod/processor/AbstractToolTest.java:[20,52] error: cannot access MediaServiceType 
21-Mar-2013 10:45:46  
21-Mar-2013 10:45:46  
21-Mar-2013 10:45:46 [INFO] ------------------------------------------------------------------------ 
21-Mar-2013 10:45:46 [DEBUG] Trace 
21-Mar-2013 10:45:46 org.apache.maven.lifecycle.LifecycleExecutionException: Can not execute Sonar 
21-Mar-2013 10:45:46  at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:719) 
21-Mar-2013 10:45:46  at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569) 
21-Mar-2013 10:45:46  at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539) 
21-Mar-2013 10:45:46  at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387) 
21-Mar-2013 10:45:46  at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:284) 
21-Mar-2013 10:45:46  at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180) 
21-Mar-2013 10:45:46  at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:328) 
21-Mar-2013 10:45:46  at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138) 
21-Mar-2013 10:45:46  at org.apache.maven.cli.MavenCli.main(MavenCli.java:362) 
21-Mar-2013 10:45:46  at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60) 
21-Mar-2013 10:45:46  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
21-Mar-2013 10:45:46  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
21-Mar-2013 10:45:46  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
21-Mar-2013 10:45:46  at java.lang.reflect.Method.invoke(Method.java:601) 
21-Mar-2013 10:45:46  at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315) 
21-Mar-2013 10:45:46  at org.codehaus.classworlds.Launcher.launch(Launcher.java:255) 
21-Mar-2013 10:45:46  at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430) 
21-Mar-2013 10:45:46  at org.codehaus.classworlds.Launcher.main(Launcher.java:375) 
21-Mar-2013 10:45:46 Caused by: org.apache.maven.plugin.MojoExecutionException: Can not execute Sonar 
21-Mar-2013 10:45:46  at org.codehaus.mojo.sonar.Bootstraper.executeMojo(Bootstraper.java:103) 
21-Mar-2013 10:45:46  at org.codehaus.mojo.sonar.Bootstraper.start(Bootstraper.java:79) 
21-Mar-2013 10:45:46  at org.codehaus.mojo.sonar.SonarMojo.execute(SonarMojo.java:88) 
21-Mar-2013 10:45:46  at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490) 
21-Mar-2013 10:45:46  at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694) 
21-Mar-2013 10:45:46  ... 17 more 
21-Mar-2013 10:45:46 Caused by: org.sonar.api.utils.SonarException: Unable to execute maven plugin 
21-Mar-2013 10:45:46  at org.sonar.batch.AbstractMavenPluginExecutor.execute(AbstractMavenPluginExecutor.java:51) 
21-Mar-2013 10:45:46  at org.sonar.batch.AbstractMavenPluginExecutor.execute(AbstractMavenPluginExecutor.java:38) 
21-Mar-2013 10:45:46  at org.sonar.batch.phases.InitializersExecutor.executeMavenPlugin(InitializersExecutor.java:73) 
21-Mar-2013 10:45:46  at org.sonar.batch.phases.InitializersExecutor.execute(InitializersExecutor.java:60) 
21-Mar-2013 10:45:46  at org.sonar.batch.phases.Phases.execute(Phases.java:90) 
21-Mar-2013 10:45:46  at org.sonar.batch.bootstrap.ProjectModule.doStart(ProjectModule.java:143) 
21-Mar-2013 10:45:46  at org.sonar.batch.bootstrap.Module.start(Module.java:83) 
21-Mar-2013 10:45:46  at org.sonar.batch.bootstrap.BatchModule.analyze(BatchModule.java:111) 
21-Mar-2013 10:45:46  at org.sonar.batch.bootstrap.BatchModule.analyze(BatchModule.java:106) 
21-Mar-2013 10:45:46  at org.sonar.batch.bootstrap.BatchModule.analyze(BatchModule.java:106) 
21-Mar-2013 10:45:46  at org.sonar.batch.bootstrap.BatchModule.doStart(BatchModule.java:101) 
21-Mar-2013 10:45:46  at org.sonar.batch.bootstrap.Module.start(Module.java:83) 
21-Mar-2013 10:45:46  at org.sonar.batch.bootstrap.BootstrapModule.doStart(BootstrapModule.java:102) 
21-Mar-2013 10:45:46  at org.sonar.batch.bootstrap.Module.start(Module.java:83) 
21-Mar-2013 10:45:46  at org.sonar.batch.Batch.execute(Batch.java:100) 
21-Mar-2013 10:45:46  at org.sonar.maven.SonarMojo.executeBatch(SonarMojo.java:152) 
21-Mar-2013 10:45:46  at org.sonar.maven.SonarMojo.execute(SonarMojo.java:142) 
21-Mar-2013 10:45:46  at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490) 
21-Mar-2013 10:45:46  at org.codehaus.mojo.sonar.Bootstraper.executeMojo(Bootstraper.java:98) 
21-Mar-2013 10:45:46  ... 21 more 
21-Mar-2013 10:45:46 Caused by: org.apache.maven.BuildFailureException: Compilation failure 
21-Mar-2013 10:45:46 /data/bamboo/xml-data/build-dir/PRO-PROTRUNKSONAR-JOB1/processors/processor-tool/src/test/java/company/prod/processor/AbstractToolTest.java:[20,52] error: cannot access MediaServiceType 
21-Mar-2013 10:45:46  
21-Mar-2013 10:45:46  
21-Mar-2013 10:45:46  at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:715) 
21-Mar-2013 10:45:46  at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:556) 
21-Mar-2013 10:45:46  at org.apache.maven.lifecycle.DefaultLifecycleExecutor.forkProjectLifecycle(DefaultLifecycleExecutor.java:1205) 
21-Mar-2013 10:45:46  at org.apache.maven.lifecycle.DefaultLifecycleExecutor.forkLifecycle(DefaultLifecycleExecutor.java:1038) 
21-Mar-2013 10:45:46  at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:643) 
21-Mar-2013 10:45:46  at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandaloneGoal(DefaultLifecycleExecutor.java:569) 
21-Mar-2013 10:45:46  at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:539) 
21-Mar-2013 10:45:46  at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:387) 
21-Mar-2013 10:45:46  at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:348) 
21-Mar-2013 10:45:46  at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:180) 
21-Mar-2013 10:45:46  at org.sonar.maven.Maven2PluginExecutor.concreteExecute(Maven2PluginExecutor.java:52) 
21-Mar-2013 10:45:46  at org.sonar.batch.AbstractMavenPluginExecutor.execute(AbstractMavenPluginExecutor.java:49) 
21-Mar-2013 10:45:46  ... 39 more 
21-Mar-2013 10:45:46 Caused by: org.apache.maven.plugin.CompilationFailureException: Compilation failure 
21-Mar-2013 10:45:46 /data/bamboo/xml-data/build-dir/PRO-PROTRUNKSONAR-JOB1/processors/processor-tool/src/test/java/company/prod/processor/AbstractToolTest.java:[20,52] error: cannot access MediaServiceType 
21-Mar-2013 10:45:46  
21-Mar-2013 10:45:46  
21-Mar-2013 10:45:46  at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:516) 
21-Mar-2013 10:45:46  at org.apache.maven.plugin.TestCompilerMojo.execute(TestCompilerMojo.java:102) 
21-Mar-2013 10:45:46  at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:490) 
21-Mar-2013 10:45:46  at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:694) 
21-Mar-2013 10:45:46  ... 50 more 

打開詳細日誌記錄後,我得到以下

21-Mar-2013 17:55:07 [loading RegularFileObject[/data/bamboo/xml-data/build-dir/PRO-PROTRUNKSONAR-JOB1/processors/processor-tool/target/generated-classes/cobertura/company/prod/processor/MediaServiceType.class]] 
21-Mar-2013 17:55:07 /data/bamboo/xml-data/build-dir/PRO-PROTRUNKSONAR-JOB1/processors/processor-tool/src/test/java/company/prod/processor/AbstractToolTest.java:20: error: cannot access MediaServiceType 
21-Mar-2013 17:55:07   return MediaServiceFactory.getMediaService((MediaServiceType) serviceType, ppt2TextPath, pdfwmkPath); 

和類文件存在意味着它不MediaServiceType是失蹤,但別的東西。

我現在發現,如果我刪除聲納生成運行,責備與javax.annotations.Nonnull在MediaServiceType中使用有關。也運行mvn測試工作正常,但如果我運行聲納測試編譯失敗,所以我很確定現在的責任與聲納,而不是我的POM文件。

上做了測試VS聲納構建了--debug日誌一個差異,我可以看到,聲納運行時,以下額外的罐子放在編譯類路徑:

  • 的Cobertura-1.9。 4.1.jar
  • 螞蟻1.7.0.jar
  • 螞蟻發射-1.7.0.jar

也代替使用目標/類,它使用生成的類/的Cobertura的主要類。

在我從配置的Cobertura忽略MediaServiceType解決此問題工作的時刻

  <configuration> 
       <instrumentation> 
        <excludes> 
         <exclude>**/MediaServiceType.class</exclude> 
         <exclude>**/*Parameter.class</exclude> 
        </excludes> 
       </instrumentation> 
      </configuration> 

參數枚舉似乎有同樣的問題,他們也使用@Nonnull枚舉。

+1

發佈你的'pom.xml'。 – carlspring 2013-03-21 13:08:01

回答

2

您是否檢查過包含MediaServiceType和AbstractToolTest的依賴項是否在測試範圍內。 <scope>test</scope>。測試找不到該類,因此它可能不在範圍內。

+1

不錯,但請記住,如果沒有指定範圍,它默認爲'compile',它將*使測試可用 – Miquel 2013-03-22 10:25:50

+0

需要真正看到pom! – 2013-03-22 11:30:24

0

確保您沒有舊版本的問題(您是否最近添加了Enum?)。

您可以嘗試暫時移開竹子主文件夾~/.m2/repository中的所有內容,看看它是否有幫助。我擔心的是,出於某種原因,您可能會在本地回購庫中使用捆綁包,而不是實際的模塊。如果這確實有效,你必須找出原因;)

相關問題