Jenkins无法找到本地maven依赖项

时间:2013-08-19 17:10:09

标签: maven maven-2 jenkins

我在使用jenkins构建我的maven项目时遇到了一些麻烦。该项目在我的本地机器上构建良好,但不是在Jenkins尝试构建它时

我有两个本地的依赖,并没有托管在任何仓库上。他们是:

  • first.jar
  • second.jar

这是我项目的结构:

 - -MyProject/
 - ---images/...
 - ---resources/...
 - ---src/...
 - ---first.jar
 - ---second.jar
 - ---pom.xml
 - ---...

Maven似乎找不到“first.jar”和“second.jar”并试图远程下载它们。

我已经用

安装了它们
install:install-file -Dfile=first.jar -DgroupId=first -DartifactId=first -Dversion=1.0.0 -Dpackaging=jar

install:install-file -Dfile=second.jar -DgroupId=second -DartifactId=second -Dversion=1.0.0 -Dpackaging=jar

========================

的pom.xml

这是我的pom.xml:

<!-- This pom is now operational.-->
<!--  ****Compile with****: mvn compile -->
<!--  ****Create Executable with****: mvn package -->
<!--  ****Run with****: java -jar MYPROJECT-0.0.1-beta-jar-with-dependencies.jar [args]-->
<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>
    <!-- MYPROJECT INFO -->
    <groupId>Main</groupId>
    <artifactId>MyProject</artifactId>
    <version>0.0.1-beta</version>
    <name>MyProject</name>
    <packaging>jar</packaging>
    <!-- DEPENDANCIES -->
    <dependencies>
        <dependency>
        <groupId>first</groupId>
        <artifactId>first</artifactId>
        <version>1.0.0</version>
    </dependency>    
        <dependency>
          <groupId>second</groupId>
          <artifactId>second</artifactId>
          <version>1.0.0</version>
    </dependency>   
    </dependencies>

    <build>
        <sourceDirectory>src</sourceDirectory>
    <!-- RESOURCES -->
        <resources>
          <resource>
            <directory>src</directory>
            <filtering>true</filtering>
          </resource>
          <resource>
            <directory>${basedir}/images</directory>
        <filtering>false</filtering>
        <targetPath>images</targetPath>
          </resource>
        <resource>
            <directory>${basedir}/resources</directory>
        <filtering>false</filtering>
        <targetPath>resources</targetPath>
          </resource>
        </resources>
        <testResources>
          <testResource>
            <directory>src</directory>
          </testResource>
        </testResources>
        <plugins>
    <!--  For Java 6, you need to configure the maven-compiler-plugin. Add this to your pom.xml: -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
              <source>1.6</source>
              <target>1.6</target>
            </configuration>
          </plugin>
    <!-- CREATE EXECUTABLE JAR WITH DEPENDANCIES in target/MYPROJECT -->
        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
          <version>2.4</version>
          <configuration>
            <archive>
              <manifest>
            <mainClass>Main.Main</mainClass>
              </manifest>
            </archive>
            <descriptorRefs>
              <descriptorRef>jar-with-dependencies</descriptorRef>
            </descriptorRefs>
            <outputDirectory>${project.build.directory}/MYPROJECT</outputDirectory> 
          </configuration>
          <executions>
            <execution>
              <id>make-assembly</id> <!-- this is used for inheritance merges -->
              <phase>package</phase> <!-- bind to the packaging phase -->
              <goals>
            <goal>single</goal>
              </goals>
            </execution>
          </executions>
        </plugin>
    <!-- COPY RESOURCES to target/MYPROJECT -->
        <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>2.6</version>
        <executions>
          <execution>
            <id>copy-resources</id>
            <!-- here the phase you need -->
            <phase>package</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${basedir}/target/MYPROJECT</outputDirectory>
              <resources>          
                  <resource>
                <directory>${basedir}/images</directory>
                <filtering>false</filtering>
                <targetPath>images</targetPath>
                  </resource>
                <resource>
                <directory>${basedir}/resources</directory>
                <filtering>false</filtering>
                <targetPath>resources</targetPath>
                  </resource>
              </resources>              
            </configuration>            
          </execution>
        </executions>
          </plugin>

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

========================

JENKINS

这是我的Jenkins配置:

  • “生成”
    • “调用顶级Maven目标”
      • 安装:install-file -Dfile = first.jar -DgroupId = first -DartifactId = first -Dversion = 1.0.0 -Dpackaging = jar
        • 最初没有包含这些内容,但我想也许如果我在构建中安装它们可能会起作用......但事实并非如此。
    • “调用顶级Maven目标”
      • 安装:install-file -Dfile = second.jar -DgroupId = second -DartifactId = second -Dversion = 1.0.0 -Dpackaging = jar
    • “调用顶级Maven目标”
      • 编译
        • 我也尝试过编译-gs /usr/share/maven2/conf/settings.xml -s /usr/share/maven2/conf/settings.xml)
        • 我还尝试选择“使用私有Maven存储库”并设置“全局设置文件”和“设置文件”
    • “调用顶级Maven目标”
        • (还试过包-gs /usr/share/maven2/conf/settings.xml -s /usr/share/maven2/conf/settings.xml)

========================

输出

Building in workspace /var/lib/jenkins/workspace/MyProject
Checkout:MyProject / /var/lib/jenkins/workspace/MyProject - hudson.remoting.LocalChannel@65565eae
Using strategy: Default
Last Built Revision: Revision 72e4cfcdd55427078cb0fb2c799c99e96ecb4ad8 (origin/master)
Fetching changes from 1 remote Git repository
Fetching upstream changes from origin
Commencing build of Revision 72e4cfcdd55427078cb0fb2c799c99e96ecb4ad8 (origin/master)
Checking out Revision 72e4cfcdd55427078cb0fb2c799c99e96ecb4ad8 (origin/master)
[MyProject] $ mvn install:install-file -Dfile=first.jar -DgroupId=first -DartifactId=first -Dversion=1.0.0 -Dpackaging=jar
/usr/lib/jvm/java
[INFO] Scanning for projects...
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-compiler-plugin:2.0.2 and goal prefix is compiler
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-compiler-plugin:2.0.2 and goal prefix is compiler
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-compiler-plugin:2.0.2
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-compiler-plugin:2.0.2
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-assembly-plugin:2.4 and goal prefix is assembly
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-assembly-plugin:2.4 and goal prefix is assembly
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-assembly-plugin:2.4
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-assembly-plugin:2.4
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-resources-plugin:2.6 and goal prefix is resources
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-resources-plugin:2.6 and goal prefix is resources
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-resources-plugin:2.6
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-resources-plugin:2.6
[INFO] Searching repository for plugin with prefix: 'install'.
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-install-plugin:2.2 and goal prefix is install
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-install-plugin:2.2 and goal prefix is install
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-install-plugin:2.2
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-install-plugin:2.2
[INFO] ------------------------------------------------------------------------
[INFO] Building MyProject
[INFO]    task-segment: [install:install-file] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] [install:install-file {execution: default-cli}]
[INFO] Installing /var/lib/jenkins/workspace/MyProject/first.jar to /home/jenkins/.m2/repository/first/first/1.0.0/first-1.0.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3 seconds
[INFO] Finished at: Mon Aug 19 10:05:11 PDT 2013
[INFO] Final Memory: 7M/30M
[INFO] ------------------------------------------------------------------------
[MyProject] $ mvn install:install-file -Dfile=second.jar -DgroupId=second -DartifactId=second -Dversion=1.0.0 -Dpackaging=jar
/usr/lib/jvm/java
[INFO] Scanning for projects...
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-compiler-plugin:2.0.2 and goal prefix is compiler
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-compiler-plugin:2.0.2 and goal prefix is compiler
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-compiler-plugin:2.0.2
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-compiler-plugin:2.0.2
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-assembly-plugin:2.4 and goal prefix is assembly
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-assembly-plugin:2.4 and goal prefix is assembly
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-assembly-plugin:2.4
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-assembly-plugin:2.4
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-resources-plugin:2.6 and goal prefix is resources
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-resources-plugin:2.6 and goal prefix is resources
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-resources-plugin:2.6
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-resources-plugin:2.6
[INFO] Searching repository for plugin with prefix: 'install'.
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-install-plugin:2.2 and goal prefix is install
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-install-plugin:2.2 and goal prefix is install
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-install-plugin:2.2
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-install-plugin:2.2
[INFO] ------------------------------------------------------------------------
[INFO] Building MyProject
[INFO]    task-segment: [install:install-file] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] [install:install-file {execution: default-cli}]
[INFO] Installing /var/lib/jenkins/workspace/MyProject/second.jar to /home/jenkins/.m2/repository/second/second/1.0.0/second-1.0.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4 seconds
[INFO] Finished at: Mon Aug 19 10:05:18 PDT 2013
[INFO] Final Memory: 7M/30M
[INFO] ------------------------------------------------------------------------
[MyProject] $ mvn compile
/usr/lib/jvm/java
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building MyProject
[INFO]    task-segment: [compile]
[INFO] ------------------------------------------------------------------------
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-resources-plugin:2.6 and goal prefix is resources
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-resources-plugin:2.6 and goal prefix is resources
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-resources-plugin:2.6
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-resources-plugin:2.6
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-compiler-plugin:2.0.2 and goal prefix is compiler
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-compiler-plugin:2.0.2 and goal prefix is compiler
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-compiler-plugin:2.0.2
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-compiler-plugin:2.0.2
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-compiler-plugin:2.0.2
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-assembly-plugin:2.4 and goal prefix is assembly
*DEBUG*: Putting in plugin descriptor list org.apache.maven.plugins:maven-assembly-plugin:2.4 and goal prefix is assembly
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-assembly-plugin:2.4
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-assembly-plugin:2.4
*DEBUG*: Constructed plugin version key is org.apache.maven.plugins:maven-resources-plugin:2.6
[INFO] [resources:resources {execution: default-resources}]
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 35 resources
[INFO] Copying 126 resources to images
[INFO] Copying 18 resources to resources
Downloading: http://repo1.maven.org/maven2/first/first/1.0.0/first-1.0.0.pom
[INFO] Unable to find resource 'first:first:pom:1.0.0' in repository central (http://repo1.maven.org/maven2)
[WARNING] Skipping jpp repository file:///usr/share/maven2/repository in vanilla mode
Downloading: http://repo1.maven.org/maven2/second/second/1.0.0/second-1.0.0.pom
[INFO] Unable to find resource 'second:second:pom:1.0.0' in repository central (http://repo1.maven.org/maven2)
[WARNING] Skipping jpp repository file:///usr/share/maven2/repository in vanilla mode
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Compiling 24 source files to /var/lib/jenkins/workspace/MyProject/target/classes
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure
/var/lib/jenkins/workspace/MyProject/src/Actions/EditorActions.java:[119,15] error while writing Actions.EditorActions.ListCheckBox: /var/lib/jenkins/workspace/MyProject/target/classes/Actions/EditorActions$ListCheckBox.class (Permission denied)


[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 15 seconds
[INFO] Finished at: Mon Aug 19 10:05:35 PDT 2013
[INFO] Final Memory: 14M/53M
[INFO] ------------------------------------------------------------------------
Build step 'Invoke top-level Maven targets' marked build as failure
Finished: FAILURE

有什么想法吗?

1 个答案:

答案 0 :(得分:2)

  • 您收到的警告

    [INFO]无法在资源库中心找到资源'first:first:pom:1.0.0'(http://repo1.maven.org/maven2

    是关于maven没有找到中央仓库中的依赖关系的POM文件,而不是jar。 Maven总是会寻找POM来检查jar是否有更多的依赖关系。如果您为依赖项安装POM,它将停止在中央存储库中查找它们。

  • 您遇到的构建问题有所不同:

    编写Actions.EditorActions.ListCheckBox时出现

    /var/lib/jenkins/workspace/MyProject/src/Actions/EditorActions.java:[119,15]错误:/ var / lib / jenkins / workspace / MyProject / target / classes /Actions/EditorActions$ListCheckBox.class(Permission denied)

它看起来像是工作区中的权限问题。也许你已经在不同用户下运行了两次构建。或者其他一些奇怪的事情正在发生。