当前位置: 首页 > 知识库问答 >
问题:

与Jenkins一起构建Maven项目

尉迟德惠
2023-03-14

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

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

项目POM和. m2/settings.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/设置.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>

共有1个答案

焦苏燕
2023-03-14

这可能是因为Jenkins(如果她在另一台计算机上运行)不知道被标识为<code>central

设置Jenkin自己的< code>settings.xml因她安装的方式而异。

在我的情况下(原生ubuntu安装),Jenkins的家是/usr/lib/jenkins。也许你可以将本地设置.xml复制到 Jenkins 的 /usr/lib/jenkins/.m2/ 中

 类似资料:
  • 我已经为一个项目配置了SVN-Jenkins-Maven-Tomcat。小项目的每件事都很好。但当我试图构建包含大量JAR和包的实际项目时…它显示错误..找不到xxx包。我已经手动将依赖项JAR添加到本地maven存储库中。

  • 问题内容: 我有一个多模块Maven项目,其中有多个微服务作为模块,因此我的父母中列出了一些模块,如下所示: 这里是依赖项,因此我在下面列出了依赖项 : 当我在本地运行时,按预期方式在被调用之前,但是在詹金斯中,它正在尝试构建然后使构建失败说: 我是否需要运行其他作业或重新排序模块,从本地到Jenkins有什么不同?感谢对此的任何帮助。 问题答案: 众所周知,问题在于子模块之间的依赖关系失败,因为

  • 主要内容:构建项目,测试项目在上一节中,我们介绍了如何使用 archetype 创建 Maven 项目,接下来我们介绍如何构建和测试这个项目。 构建项目 查看 helloMaven 项目的 pom.xml 文件,配置如下。 从以上配置可知,Maven 已经添加了 Junit 作为该项目的测试框架,且 Maven 也在项目中自动生成了一个源码文件 App.java 和一个测试文件 AppTest.java 。 打开命令行窗口,

  • 我配置了一个简单的maven freestyle项目。我能够成功构建该项目,但无法部署到Nexus。我得到这个错误: [错误]无法执行目标org.apache.maven.plugins:maven部署插件:2.8.1:部署(默认部署)项目eqs_utility:部署工件失败:找不到工件com.companyName.eqs:eqs_utility:jar:1.0.1-20190529.19124

  • ----maven-enforcer-plugin:1.0.1:enforce(default)@cli---添加ignore:org.eclipse.jetty.spdy.* ----maven-enforcer-plugin:1.0.1:enforce(enforce-bang-dependencies)@cli-- ---build-helper-maven-plugin:1.7:times

  • 本文向大家介绍jenkins+Maven从SVN上构建项目的方法,包括了jenkins+Maven从SVN上构建项目的方法的使用技巧和注意事项,需要的朋友参考一下 一、安装Maven 下载地址:https://maven.apache.org/download.cgi 把下载的安装包解压 配置环境变量 使配置文件生效 查看版本信息 二、jenkins配置 1、配置jdk 先在Jenkins服务器上