java 使用 Jenkins 构建 Maven 项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15249474/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 18:59:34  来源:igfitidea点击:

Building Maven Projects with Jenkins

javamavenjenkinscontinuous-integration

提问by Michael Hillman

I'm new to both Maven and Jenkins so bear with me here...

我是 Maven 和 Jenkins 的新手,所以请耐心等待......

I've got a Maven project that builds correctly when I run mvn installfrom within the project folder, but when I attempt to build via Jenkins, no dependencies can be resolved at all. Am I missing something/screwed something up in my Maven or Jenkins settings?

我有一个 Maven 项目,当我从项目文件夹中运行mvn install时,它可以正确构建,但是当我尝试通过 Jenkins 构建时,根本无法解析任何依赖项。我是否在 Maven 或 Jenkins 设置中遗漏了什么/搞砸了什么?

Project POM and .m2/settings.xml are below...

项目 POM 和 .m2/settings.xml 如下...

pom.xml

pom.xml

<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>project</groupId>
<artifactId>ProjectGUI</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>ProjectGUI</name>
<url>http://maven.apache.org</url>

<repositories>
<repository>
  <id>central</id>
  <url>http://server:8081/nexus/content/groups/public</url>
  <releases><enabled>true</enabled></releases>
  <snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>                   
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
        <plugin>
    <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <executions>
                <execution>
                    <id>package-jar-with-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                           <appendAssemblyId>false</appendAssemblyId>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <archive>
                                                        <manifestEntries>
                                                            <Manifest-   Version>1.0</Manifest-Version>
                                                            <Main-Class>project.Main</Main-Class>
                                                            <SplashScreen-    Image>splash.png</SplashScreen-Image>
                                                        </manifestEntries>
                                                    </archive>
                    </configuration>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-jar-plugin</artifactId>
            <version>2.1</version>
            <configuration>
                <archive>
                    <manifestEntries>
                        <Manifest-Version>1.0</Manifest-Version>
                        <Main-Class>project.Main</Main-Class>
                        <SplashScreen-Image>splash.png</SplashScreen-Image>
                    </manifestEntries>
                </archive>
            </configuration>
        </plugin>    
    </plugins>
</build>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>3.8.1</version>
  <scope>test</scope>
</dependency>
<dependency>
  <groupId>com.googlecode.lambdaj</groupId>
  <artifactId>lambdaj</artifactId>
  <version>2.3.3</version>
</dependency>
<dependency>
  <groupId>org.hamcrest</groupId>
  <artifactId>hamcrest-all</artifactId>
  <version>1.3</version>
</dependency>
<dependency>
  <groupId>javax.media</groupId>
  <artifactId>jmf</artifactId>
  <version>2.1.1e</version>
</dependency>
<dependency>
  <groupId>ch.qos.logback</groupId>
  <artifactId>logback-classic</artifactId>
  <version>1.0.0</version>
</dependency>
<dependency>
  <groupId>jfree</groupId>
  <artifactId>jfreechart</artifactId>
  <version>1.0.13</version>
</dependency>
<dependency>
  <groupId>com.jidesoft</groupId>
  <artifactId>jide-charts</artifactId>
  <version>3.4.8</version>
</dependency>
<dependency>
  <groupId>com.jidesoft</groupId>
  <artifactId>jide-common</artifactId>
  <version>3.4.8</version>
</dependency>
<dependency>
  <groupId>org.jogamp.gluegen</groupId>
  <artifactId>gluegen-rt-main</artifactId>
  <version>2.0-rc11</version>
</dependency>
<dependency>
  <groupId>org.jogamp.jogl</groupId>
  <artifactId>jogl-all-main</artifactId>
  <version>2.0-rc11</version>
</dependency>
<dependency>
    <groupId>org.jzy3d</groupId>
    <artifactId>jzy3d</artifactId>
    <version>0.9</version>
</dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-api</artifactId>
  <version>1.7.2</version>
</dependency>
</dependencies>
</project>

.m2/settings.xml

.m2/settings.xml

<settings>
<mirrors>
<mirror>
  <!--This sends everything else to /public -->
  <id>nexus</id>
  <mirrorOf>central</mirrorOf>
  <url>http://server:8081/nexus/content/groups/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
  <id>nexus</id>
  <!--Enable snapshots for the built in central repo to direct -->
  <!--all requests to nexus via the mirror -->
  <repositories>
    <repository>
      <id>central</id>
      <url>http://central</url>
      <releases><enabled>true</enabled></releases>
      <snapshots><enabled>true</enabled></snapshots>
    </repository>
  </repositories>
 <pluginRepositories>
    <pluginRepository>
      <id>central</id>
      <url>http://central</url>
      <releases><enabled>true</enabled></releases>
      <snapshots><enabled>true</enabled></snapshots>
    </pluginRepository>
  </pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>

回答by Jin Kwon

That's, probably, because Jenkins (if she is running on the other computer) doesn't know the extra repository identified as centralwhich seems to be a private nexusinstance in your domain area.

这可能是因为 Jenkins(如果她在另一台计算机上运行)不知道被标识为central似乎是nexus您域区域中的私有实例的额外存储库。

Setting Jenkin's own settings.xmlvaries on the way of how she installed.

设置詹金自己settings.xml的方式因她的安装方式而异。

In my case (native ubuntu install), Jenkins' home is /usr/lib/jenkins. Maybe you can copy your local settings.xmlinto Jenkins' /usr/lib/jenkins/.m2/?

就我而言(本地 ubuntu 安装),Jenkins 的家是/usr/lib/jenkins. 也许你可以将你的本地复制settings.xml到詹金斯的/usr/lib/jenkins/.m2/