使用Jenkins构建Maven项目

时间:2013-03-06 14:08:10

标签: java maven jenkins continuous-integration

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

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

Project 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 / 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>

1 个答案:

答案 0 :(得分:3)

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

设置Jenkin自己的settings.xml因其安装方式而异。

在我的情况下(本机ubuntu安装),Jenkins的主页是/usr/lib/jenkins。也许您可以将本地settings.xml复制到Jenkins'/usr/lib/jenkins/.m2/