2013-02-20 151 views
1

所以我對Maven仍然很陌生,所以我真的不明白整個過程如何運作得非常好。無論如何,我試圖讓maven編譯我的項目,當我運行命令「mvn compile」時,首先它會給我一個構建失敗,但是如果我運行命令「mvn package」,它將成功,而且隨後的「mvn compile」將在那之後工作。我的問題是我需要將它提交給git,它將它發送給jenkins進行審查,那時它正在失敗,我不知道如何解決它。這裏是日誌Maven未能獲得依賴關係

Building in workspace /var/lib/jenkins/workspace/my_dropbox 
Checkout:my_dropbox//var/lib/jenkins/workspace/my_dropbox - [email protected] 
Using strategy: Gerrit Trigger 
Last Built Revision: Revision 05182398b298d442d1c238673a40beb52b83386f (anything_but_blank) 
Fetching changes from 1 remote Git repository 
Fetching upstream changes from ssh://[email protected]:29418/my_dropbox.git 
Commencing build of Revision 0980748fbbd29ff9acd2134dd55cb84afb577dd7 (anything_but_blank) 
Checking out Revision 0980748fbbd29ff9acd2134dd55cb84afb577dd7 (anything_but_blank) 
Parsing POMs 
[my_dropbox] $ /usr/lib/jvm/jdk1.7.0/bin/java -cp /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-agent-1.2.jar:/var/lib/jenkins/tools/Maven/Maven_3/boot/plexus-classworlds-2.4.jar org.jvnet.hudson.maven3.agent.Maven3Main /var/lib/jenkins/tools/Maven/Maven_3 /var/cache/jenkins/war/WEB-INF/lib/remoting-2.19.jar /var/lib/jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-1.2.jar 40598 
<===[JENKINS REMOTING CAPACITY]===>channel started 
log4j:WARN No appenders could be found for logger (org.apache.commons.beanutils.converters.BooleanConverter). 
log4j:WARN Please initialize the log4j system properly. 
Executing Maven: -B -f /var/lib/jenkins/workspace/my_dropbox/pom.xml clean package 
[INFO] Scanning for projects... 
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for SimpleDropbox:SimpleDropbox:jar:0.0.1-SNAPSHOT 
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-jar-plugin is missing. @ line 35, column 9 
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build. 
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects. 
[WARNING] 
Projects to build: [MavenProject: SimpleDropbox:SimpleDropbox:0.0.1-SNAPSHOT @ /var/lib/jenkins/workspace/my_dropbox/pom.xml] 
projectStarted SimpleDropbox:SimpleDropbox:0.0.1-SNAPSHOT 
[INFO]                   
[INFO] ------------------------------------------------------------------------ 
[INFO] Building Fiachra 0.0.1-SNAPSHOT 
[INFO] ------------------------------------------------------------------------ 
mojoStarted org.apache.maven.plugins:maven-clean-plugin:2.4.1(default-clean) 
[INFO] 
[INFO] --- maven-clean-plugin:2.4.1:clean (default-clean) @ SimpleDropbox --- 
[INFO] Deleting /var/lib/jenkins/workspace/my_dropbox/target 
mojoSucceeded org.apache.maven.plugins:maven-clean-plugin:2.4.1(default-clean) 
mojoStarted org.apache.maven.plugins:maven-resources-plugin:2.5(default-resources) 
[INFO] 
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ SimpleDropbox --- 
[debug] execute contextualize 
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! 
[INFO] skip non existing resourceDirectory /var/lib/jenkins/workspace/my_dropbox/src/main/resources 
mojoSucceeded org.apache.maven.plugins:maven-resources-plugin:2.5(default-resources) 
mojoStarted org.apache.maven.plugins:maven-compiler-plugin:2.3.1(default-compile) 
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.1:compile (default-compile) @ SimpleDropbox --- 
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent! 
[INFO] Compiling 12 source files to /var/lib/jenkins/workspace/my_dropbox/target/classes 
[INFO] ------------------------------------------------------------- 
mojoFailed org.apache.maven.plugins:maven-compiler-plugin:2.3.1(default-compile)[ERROR] COMPILATION ERROR : 
[INFO] ------------------------------------------------------------- 
[ERROR] /var/lib/jenkins/workspace/my_dropbox/src/test/java/TestSomething.java:[3,23] error: package org.junit does not exist 

[ERROR] /var/lib/jenkins/workspace/my_dropbox/src/test/java/TestSomething.java:[7,16] error: package org.junit does not exist 

[ERROR] /var/lib/jenkins/workspace/my_dropbox/src/test/java/TestSomething.java:[11,2] error: cannot find symbol 

[INFO] 3 errors 
[INFO] ------------------------------------------------------------- 

projectFailed SimpleDropbox:SimpleDropbox:0.0.1-SNAPSHOT 
sessionEnded 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 7.054s 
[INFO] Finished at: Wed Feb 20 09:03:25 GMT 2013 
[INFO] Final Memory: 11M/240M 
[INFO] ------------------------------------------------------------------------ 
Projects to build: [MavenProject: SimpleDropbox:SimpleDropbox:0.0.1-SNAPSHOT @ /var/lib/jenkins/workspace/my_dropbox/pom.xml] 
[JENKINS] Archiving /var/lib/jenkins/workspace/my_dropbox/pom.xml to /var/lib/jenkins/jobs/my_dropbox/modules/SimpleDropbox$SimpleDropbox/builds/2013-02-20_09-03-14/archive/SimpleDropbox/SimpleDropbox/0.0.1-SNAPSHOT/SimpleDropbox-0.0.1-SNAPSHOT.pom 
Waiting for Jenkins to finish collecting data 
mavenExecutionResult exceptions not empty 
message : Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.1:compile (default-compile) on project SimpleDropbox: Compilation failure 
cause : Compilation failure 
Stack trace : 
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.1:compile (default-compile) on project SimpleDropbox: Compilation failure 
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:213) 
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) 
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145) 
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84) 
    at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59) 
    at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183) 
    at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161) 
    at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:320) 
    at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:156) 
    at org.jvnet.hudson.maven3.launcher.Maven3Launcher.main(Maven3Launcher.java:79) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:601) 
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchStandard(Launcher.java:329) 
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:239) 
    at org.jvnet.hudson.maven3.agent.Maven3Main.launch(Maven3Main.java:158) 
    at hudson.maven.Maven3Builder.call(Maven3Builder.java:98) 
    at hudson.maven.Maven3Builder.call(Maven3Builder.java:64) 
    at hudson.remoting.UserRequest.perform(UserRequest.java:118) 
    at hudson.remoting.UserRequest.perform(UserRequest.java:48) 
    at hudson.remoting.Request$2.run(Request.java:326) 
    at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72) 
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:166) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) 
    at java.lang.Thread.run(Thread.java:722) 
Caused by: org.apache.maven.plugin.CompilationFailureException: Compilation failure 
    at org.apache.maven.plugin.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:656) 
    at org.apache.maven.plugin.CompilerMojo.execute(CompilerMojo.java:128) 
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:101) 
    at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:209) 
    ... 27 more 
channel stopped 
Notifying upstream projects of job completion 
Finished: FAILURE 

,這裏是我的POM文件

<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>SimpleDropbox</groupId> 
    <artifactId>SimpleDropbox</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <name>Fiachra</name> 
    <description>It's a simple dropbox</description> 

    <dependencies> 
    <dependency> 
     <groupId>junit</groupId> 
     <artifactId>junit</artifactId> 
     <version>4.10</version> 
     <scope>test</scope> 
    </dependency> 
    <dependency> 
     <groupId>commons-codec</groupId> 
     <artifactId>commons-codec</artifactId> 
     <version>1.3</version> 
    </dependency> 
    </dependencies> 

    <build> 
    <sourceDirectory>src</sourceDirectory> 
    <plugins> 

     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>2.3.1</version> 
      <configuration> 
       <source>1.7</source> 
       <target>1.7</target> 
      </configuration> 
     </plugin> 

     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-jar-plugin</artifactId> 
     <configuration> 
     <archive> 
     <manifest> 
      <mainClass>main.java.Main</mainClass> 
      <packageName>main.java</packageName> 
     </manifest> 
     <manifestEntries> 
      <mode>development</mode> 
     </manifestEntries> 
     </archive> 
     </configuration> 
    </plugin> 

    </plugins> 
    </build> 
</project> 

這裏是當地的乾淨安裝。

[email protected] my_dropbox (develop *%=) $ mvn clean 
[INFO] Scanning for projects... 
[INFO] ------------------------------------------------------------------------ 
[INFO] Building Fiachra 
[INFO] task-segment: [clean] 
[INFO] ------------------------------------------------------------------------ 
[INFO] [clean:clean {execution: default-clean}] 
[INFO] Deleting file set: /home/fiachra/work/my_dropbox/target (included: [**], excluded: []) 
[INFO] ------------------------------------------------------------------------ 
[INFO] BUILD SUCCESSFUL 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: < 1 second 
[INFO] Finished at: Wed Feb 20 10:28:00 GMT 2013 
[INFO] Final Memory: 11M/361M 
[INFO] ------------------------------------------------------------------------ 
[email protected] my_dropbox (develop *%=) $ mvn install 
[INFO] Scanning for projects... 
[INFO] ------------------------------------------------------------------------ 
[INFO] Building Fiachra 
[INFO] task-segment: [install] 
[INFO] ------------------------------------------------------------------------ 
[INFO] [resources:resources {execution: default-resources}] 
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent! 
[INFO] skip non existing resourceDirectory /home/fiachra/work/my_dropbox/src/main/resources 
[INFO] [compiler:compile {execution: default-compile}] 
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent! 
[INFO] Compiling 12 source files to /home/fiachra/work/my_dropbox/target/classes 
[INFO] ------------------------------------------------------------- 
[ERROR] COMPILATION ERROR : 
[INFO] ------------------------------------------------------------- 
[ERROR] /home/fiachra/work/my_dropbox/src/test/java/TestSomething.java:[3,23] error: package org.junit does not exist 

[ERROR] /home/fiachra/work/my_dropbox/src/test/java/TestSomething.java:[9,2] error: cannot find symbol 

[INFO] 2 errors 
[INFO] ------------------------------------------------------------- 
[INFO] ------------------------------------------------------------------------ 
[ERROR] BUILD FAILURE 
[INFO] ------------------------------------------------------------------------ 
[INFO] Compilation failure 

/home/fiachra/work/my_dropbox/src/test/java/TestSomething.java:[3,23] error: package org.junit does not exist 

/home/fiachra/work/my_dropbox/src/test/java/TestSomething.java:[9,2] error: cannot find symbol 


[INFO] ------------------------------------------------------------------------ 
[INFO] For more information, run Maven with the -e switch 
[INFO] ------------------------------------------------------------------------ 
[INFO] Total time: 1 second 
[INFO] Finished at: Wed Feb 20 10:28:06 GMT 2013 
[INFO] Final Memory: 15M/361M 
[INFO] ------------------------------------------------------------------------ 

任何幫助將非常感激。

回答

1

編輯:明白了。

在你的POM,你modifiy默認sourceDirectory(你不應該取消少你有一個很好的理由)

<sourceDirectory>src</sourceDirectory> 

爲此,行家試圖在編譯階段編譯測試類。 JUNIT不可用(JUNIT依賴項的範圍是測試)。

刪除

<sourceDirectory>src</sourceDirectory> 

這應該工作

+0

我確信犯了POM,我甚至查了混帳只是爲了安全起見。我的IDE第一次包含了JUNIT,但是我刪除了在我的單元測試中出現錯誤的問題,這些錯誤在我將JUNIT依賴項添加到pom並更新了maven項目之後得到修復。該jar甚至包含在「Maven Dependencies」中。本地我第一次做「mvn編譯」它失敗了,一旦我做了「mvn package」它就成功了,之後的任何後續編譯或測試都會起作用,但是隻有在我做了mvn包之後。我不認爲這是一個超時,因爲它在一秒後失敗,我已經跑了幾次。 – Fiachra 2013-02-20 10:10:03

+0

我還應該指出,如果我做「mvn clean」「mvn compile」,我在本地得到相同的錯誤信息 – Fiachra 2013-02-20 10:10:58

+0

因此,最後的評論解釋了很多,因爲如果我沒有弄錯,Jenkins默認執行mvn clean install命令。所以至少你有一個可靠和一致的方法來測試它。你可以在你的本地機器上進行mvn clean install安裝後輸出嗎? – 2013-02-20 10:23:58