在Jenkins上进行Maven构建失败 [英] Maven build fails on Jenkins

查看:199
本文介绍了在Jenkins上进行Maven构建失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要使用Jenkins在Payara服务器上部署的Maven项目.有两个项目:域项目和Spring Web MVC项目.将Spring项目配置为在域项目之后进行构建,因为它依赖于域项目.

I have a Maven project I want to deploy on a Payara server using Jenkins. There are two projects: a domain project and a Spring Web MVC project. The Spring project is configured to build after the domain project, as it is dependant on the domain project.

每次提交项目时,都会触发构建.但是,我总是收到以下错误:无法解析POM.请参阅下面的完整控制台输出.

Each time I commit my project, the build is triggered. However, I always get the following error: Failed to parse POMs. See full console ouput below.

这是我第一次使用Payara和Jenkins,我无法真正将自己的头埋在我做错的事情上……任何帮助或朝着正确方向的方向将不胜感激:)

This is my first time using Payara and Jenkins, and I can't really wrap my head around what I'm doing wrong... Any help or steering in the right direction would be greatly appreciated :)

控制台输出

Started by GitHub push by WouterCypers
Building in workspace /root/.jenkins/workspace/bookstore domain
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://github.com/ucll-ip/project-ip-WouterCypers.git # timeout=10
Fetching upstream changes from https://github.com/ucll-ip/project-ip-WouterCypers.git
 > git --version # timeout=10
using GIT_ASKPASS to set credentials 
 > git fetch --tags --progress https://github.com/ucll-ip/project-ip-WouterCypers.git +refs/heads/*:refs/remotes/origin/*
 > git rev-parse refs/remotes/origin/master^{commit} # timeout=10
 > git rev-parse refs/remotes/origin/origin/master^{commit} # timeout=10
Checking out Revision 5dec7ef129e3aa4f142e0ffd41579c741aab86be (refs/remotes/origin/master)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 5dec7ef129e3aa4f142e0ffd41579c741aab86be
 > git rev-list a3f63a2901948bc6f55e3f2bcdeca5daebc1ea08 # timeout=10
Parsing POMs
Established TCP socket on 54633
[bookstore-domain] $ /usr/lib/jvm/jdk1.8.0_131/bin/java -cp /root/.jenkins/plugins/maven-plugin/WEB-INF/lib/maven33-agent-1.8.1.jar:/root/.jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven/boot/plexus-classworlds-2.5.2.jar:/root/.jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven/conf/logging jenkins.maven3.agent.Maven33Main /root/.jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven /opt/payara41/glassfish/domains/domain1/applications/jenkins/WEB-INF/lib/remoting-3.4.1.jar /root/.jenkins/plugins/maven-plugin/WEB-INF/lib/maven33-interceptor-1.8.1.jar /root/.jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-commons-1.8.1.jar 54633
<===[JENKINS REMOTING CAPACITY]===>���channel started
Executing Maven:  -B -f /root/.jenkins/workspace/bookstore domain/bookstore-domain/pom.xml clean install -DskipTests
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchStandard(Launcher.java:330)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:238)
    at jenkins.maven3.agent.Maven33Main.launch(Maven33Main.java:176)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at hudson.maven.Maven3Builder.call(Maven3Builder.java:139)
    at hudson.maven.Maven3Builder.call(Maven3Builder.java:70)
    at hudson.remoting.UserRequest.perform(UserRequest.java:153)
    at hudson.remoting.UserRequest.perform(UserRequest.java:50)
    at hudson.remoting.Request$2.run(Request.java:336)
    at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoSuchFieldError: DEFAULT_USER_SETTINGS_FILE
    at org.apache.maven.cli.DefaultMavenExecutionRequestBuilder.settings(DefaultMavenExecutionRequestBuilder.java:658)
    at org.apache.maven.cli.DefaultMavenExecutionRequestBuilder.getMavenExecutionRequest(DefaultMavenExecutionRequestBuilder.java:149)
    at org.jvnet.hudson.maven3.launcher.Maven33Launcher.getMavenExecutionRequest(Maven33Launcher.java:150)
    at org.jvnet.hudson.maven3.launcher.Maven33Launcher.main(Maven33Launcher.java:127)
    ... 21 more
channel stopped
ERROR: Failed to parse POMs
java.io.IOException: java.lang.reflect.InvocationTargetException
    at hudson.maven.Maven3Builder.call(Maven3Builder.java:179)
    at hudson.maven.Maven3Builder.call(Maven3Builder.java:70)
    at hudson.remoting.UserRequest.perform(UserRequest.java:153)
    at hudson.remoting.UserRequest.perform(UserRequest.java:50)
    at hudson.remoting.Request$2.run(Request.java:336)
    at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:748)
    at ......remote call to Channel to Maven [/usr/lib/jvm/jdk1.8.0_131/bin/java, -cp, /root/.jenkins/plugins/maven-plugin/WEB-INF/lib/maven33-agent-1.8.1.jar:/root/.jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven/boot/plexus-classworlds-2.5.2.jar:/root/.jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven/conf/logging, jenkins.maven3.agent.Maven33Main, /root/.jenkins/tools/hudson.tasks.Maven_MavenInstallation/Maven, /opt/payara41/glassfish/domains/domain1/applications/jenkins/WEB-INF/lib/remoting-3.4.1.jar, /root/.jenkins/plugins/maven-plugin/WEB-INF/lib/maven33-interceptor-1.8.1.jar, /root/.jenkins/plugins/maven-plugin/WEB-INF/lib/maven3-interceptor-commons-1.8.1.jar, 54633](Native Method)
    at hudson.remoting.Channel.attachCallSiteStackTrace(Channel.java:1537)
    at hudson.remoting.UserResponse.retrieve(UserRequest.java:253)
    at hudson.remoting.Channel.call(Channel.java:822)
    at hudson.maven.ProcessCache$MavenProcess.call(ProcessCache.java:161)
    at hudson.maven.MavenModuleSetBuild$MavenModuleSetBuildExecution.doRun(MavenModuleSetBuild.java:873)
    at hudson.model.AbstractBuild$AbstractBuildExecution.run(AbstractBuild.java:534)
    at hudson.model.Run.execute(Run.java:1728)
    at hudson.maven.MavenModuleSetBuild.run(MavenModuleSetBuild.java:544)
    at hudson.model.ResourceController.execute(ResourceController.java:98)
    at hudson.model.Executor.run(Executor.java:404)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at hudson.maven.Maven3Builder.call(Maven3Builder.java:139)
    at hudson.maven.Maven3Builder.call(Maven3Builder.java:70)
    at hudson.remoting.UserRequest.perform(UserRequest.java:153)
    at hudson.remoting.UserRequest.perform(UserRequest.java:50)
    at hudson.remoting.Request$2.run(Request.java:336)
    at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:68)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.Exception: java.lang.reflect.InvocationTargetException
    at jenkins.maven3.agent.Maven33Main.launch(Maven33Main.java:179)
    ... 14 more
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launchStandard(Launcher.java:330)
    at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:238)
    at jenkins.maven3.agent.Maven33Main.launch(Maven33Main.java:176)
    ... 14 more
Caused by: java.lang.NoSuchFieldError: DEFAULT_USER_SETTINGS_FILE
    at org.apache.maven.cli.DefaultMavenExecutionRequestBuilder.settings(DefaultMavenExecutionRequestBuilder.java:658)
    at org.apache.maven.cli.DefaultMavenExecutionRequestBuilder.getMavenExecutionRequest(DefaultMavenExecutionRequestBuilder.java:149)
    at org.jvnet.hudson.maven3.launcher.Maven33Launcher.getMavenExecutionRequest(Maven33Launcher.java:150)
    at org.jvnet.hudson.maven3.launcher.Maven33Launcher.main(Maven33Launcher.java:127)
    ... 21 more
Warning: you have no plugins providing access control for builds, so falling back to legacy behavior of permitting any downstream builds to be triggered
Finished: FAILURE

Spring项目的POM.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>org.ucll</groupId>
    <artifactId>bookstore-springmvc</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>bookstore-springmvc</name>

    <properties>
        <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

        <jstl.version>1.2</jstl.version>
        <java.version>1.8</java.version>
        <javaee.version>7.0</javaee.version>
        <maven.war.version>2.3</maven.war.version>
        <spring.version>4.3.6.RELEASE</spring.version>
        <spring.security.version>4.2.2.RELEASE</spring.security.version>
        <payara.home>/c/Program Files/payara41</payara.home>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.ucll</groupId>
            <artifactId>bookstore-domain</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
        <!-- FRAMEWORK ETC -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>${jstl.version}</version>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-web-api</artifactId>
            <version>${javaee.version}</version>
            <!-- provided indicates that we do need this dependency for compilation and test, but not at runtime -->
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${spring.version}</version>
        </dependency>

        <!-- SPRING SECURITY -->
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>${spring.security.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>${spring.security.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-taglibs</artifactId>
            <version>${spring.security.version}</version>           
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>${maven.war.version}</version>
                <configuration>
                    <failOnMissingWebXml>false</failOnMissingWebXml>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.glassfish.maven.plugin</groupId>
                <artifactId>maven-glassfish-plugin</artifactId>
                <version>2.1</version>
                <configuration>
                    <glassfishDirectory>${payara.home}/glassfish</glassfishDirectory>
                    <user>admin</user>
                    <passwordFile>${payara.home}/glassfish/config/password.txt</passwordFile>
                    <debug>true</debug>
                    <terse>false</terse>
                    <echo>true</echo>
                    <domain>
                        <name>domain1</name>
                        <adminPort>4848</adminPort>
                        <httpPort>8080</httpPort>
                    </domain>
                    <components>
                        <component>
                            <name>${project.artifactId}</name>
                            <artifact>target/${project.build.finalName}.war</artifact>
                        </component>
                    </components>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

域项目的POM.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>org.ucll</groupId>
    <artifactId>bookstore-domain</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>

        <java.version>1.8</java.version>
        <junit.version>4.12</junit.version>
        <jgiven.version>0.12.1</jgiven.version>
        <maven.surefire.version>2.19</maven.surefire.version>
        <persistence.version>2.6.4</persistence.version>
        <derbyclient.version>10.13.1.1</derbyclient.version>
        <spring.security.version>4.2.2.RELEASE</spring.security.version>
        <hibernate.version>5.4.1.Final</hibernate.version>
        <glassfish.javax.el.version>3.0.1-b08</glassfish.javax.el.version>
        <spring.context.version>4.3.6.RELEASE</spring.context.version>
        <jgiven.version>0.12.1</jgiven.version>
        <maven.surefire.version>2.19</maven.surefire.version>        
    </properties>

    <dependencies>

        <!-- TESTING -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>${junit.version}</version>
        </dependency>
        <dependency>
            <groupId>com.tngtech.jgiven</groupId>
            <artifactId>jgiven-junit</artifactId>
            <version>${jgiven.version}</version>
        </dependency>

        <!-- JPA -->
        <dependency>
            <groupId>org.eclipse.persistence</groupId>
            <artifactId>org.eclipse.persistence.jpa</artifactId>
            <version>${persistence.version}</version>
        </dependency>

        <!-- DERBY DB -->
        <dependency>
            <groupId>org.apache.derby</groupId>
            <artifactId>derbyclient</artifactId>
            <version>${derbyclient.version}</version>
        </dependency>        

        <!-- BEAN VALIDATION -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator-cdi</artifactId>
            <version>${hibernate.version}</version>
        </dependency>
        <dependency>
            <groupId>org.glassfish</groupId>
            <artifactId>javax.el</artifactId>
            <version>${glassfish.javax.el.version}</version>
        </dependency>

        <!-- SPRING CONTEXT -->
        <!-- used in Author.java for validation of the Date format -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${spring.context.version}</version>
            <type>jar</type>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.1</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <testFailureIgnore>true</testFailureIgnore>
                </configuration>
                <version>${maven.surefire.version}</version>
            </plugin>
            <plugin>
                <groupId>com.tngtech.jgiven</groupId>
                <artifactId>jgiven-maven-plugin</artifactId>
                <version>${jgiven.version}</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>report</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <format>html</format>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

推荐答案

这似乎与詹金斯有关,已经在这里得到解答:

This seems to be an issue with Jenkins, already answered here: Getting exception while configuring the maven project in jenkins

我的解决方案是设置更改构建配置:

My solution was to set the change the build configuration:

配置>构建>高级中:

  • Settings file设置为Settings file in filesystem,然后输入设置文件的路径.就我而言:/root/.m2/settings.xml
  • Global Settings file设置为Global settings file on filesystem,然后输入全局设置文件的路径.我没有一个(我认为),所以我也将其设置为/root/.m2/settings.xml.
  • Set Settings file to Settings file in filesystem and enter the path to your settings file. In my case: /root/.m2/settings.xml
  • Set Global Settings file to Global settings file on filesystem and enter the path to your global settings file. I don't have one (I think) so I just set it to /root/.m2/settings.xml also.

这应该可以解决问题.现在,我只需要解决其他十几个构建错误:)

That should do the trick. Now I just have to solve a dozen other build errors :)

这篇关于在Jenkins上进行Maven构建失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆