2

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

我有 2 个本地依赖项,并且没有托管在任何存储库上。他们是:

  • 第一个.jar
  • 第二个.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 配置:

  • “建造”
    • “调用顶级 Maven 目标”
      • 安装:安装文件 -Dfile=first.jar -DgroupId=first -DartifactId=first -Dversion=1.0.0 -Dpackaging=jar
        • 最初没有包含这些,但我想也许如果我在构建中安装它们可能会工作......但它没有。
    • “调用顶级 Maven 目标”
      • 安装:安装文件 -Dfile=second.jar -DgroupId=second -DartifactId=second -Dversion=1.0.0 -Dpackaging=jar
    • “调用顶级 Maven 目标”
      • 编译
        • 我也试过 compile -gs /usr/share/maven2/conf/settings.xml -s /usr/share/maven2/conf/settings.xml )
        • 我也尝试过选择“使用私有 Maven 存储库”并设置“全局设置文件”和“设置文件”
    • “调用顶级 Maven 目标”
      • 包裹
        • (也尝试过 package -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

有任何想法吗?

4

1 回答 1

2
  • 你收到的警告

    [信息] 无法在存储库中心 ( http://repo1.maven.org/maven2 )中找到资源“first:first:pom:1.0.0”

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

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

    /var/lib/jenkins/workspace/MyProject/src/Actions/EditorActions.java:[119,15] 编写 Actions.EditorActions.ListCheckBox 时出错:/var/lib/jenkins/workspace/MyProject/target/classes/Actions/ EditorActions$ListCheckBox.class(权限被拒绝)

It looks like a permission issue in that workspace. Maybe you have run the build twice under different users. Or something else strange is happening.

于 2013-08-19T20:08:23.990 回答