Maven未能获得依赖关系

时间:2013-02-20 09:31:30

标签: java git maven jenkins

所以我对Maven还很新,所以我真的不明白整个过程是如何运作的。无论如何我试图让maven编译我的项目,当我运行命令“mvn compile”时,它首先给我一个构建失败,但是如果我运行命令“mvn package”它将成功并且无论如何后续“mvn compile”s之后会工作的。我的问题是我需要将它提交给git,然后将其发送给jenkins进行审核,当时它是失败的,我不知道如何修复它。这是日志

Building in workspace /var/lib/jenkins/workspace/my_dropbox
Checkout:my_dropbox / /var/lib/jenkins/workspace/my_dropbox - hudson.remoting.LocalChannel@427e3f2
Using strategy: Gerrit Trigger
Last Built Revision: Revision 05182398b298d442d1c238673a40beb52b83386f (anything_but_blank)
Fetching changes from 1 remote Git repository
Fetching upstream changes from ssh://jenkins@gerrit: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>

这是本地干净安装。

fiachra@fiachra-Precision-WorkStation-T5500 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] ------------------------------------------------------------------------
fiachra@fiachra-Precision-WorkStation-T5500 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 个答案:

答案 0 :(得分:1)

编辑:知道了。

在你的POM中,你修改了默认的sourceDirectory(你不应该少用你有充分的理由)

<sourceDirectory>src</sourceDirectory>

因此,maven尝试在编译阶段编译Test类。 JUNIT不可用(JUNIT依赖的范围是测试)。

删除

<sourceDirectory>src</sourceDirectory>

这应该有效