Maven程序集插件重新加载jenkins中的依赖项

时间:2012-05-28 06:52:27

标签: java maven jenkins lwjgl slick2d

出于某种原因,每当我尝试使用Jenkins构建它时,maven似乎都在尝试下载我的项目的依赖项。有一些问题。第一个是它根本不应该这样做,另一个问题是它甚至没有尝试从正确的仓库下载它们,这意味着它必须等待它们中的每一个超时。

我可以自己运行mvn clean包,并在~4秒内构建它,因为所有依赖项都在我的本地.m2 repo中。 Jenkins在本地安装并且正在共享这个maven repo,所以我不知道它为什么表现不同。似乎jenkins正在使用-B和-f标志发出maven命令并且正在使用install而不是package但是即使我自己这样做它也会在几秒内完成,而Jenkins需要大约8分钟,因为所有的超时它必须等待。

我标记了Slick2d和lwjgl库,因为我认为它与它们有关,因为它们不在公共maven仓库中,我必须手动将它们的repo添加到pom中。

也许值得注意的是,构建完成并且是成功的,唯一的区别是Jenkins在超时上花了8分钟,而自己在几秒钟内完成。

另外,当我试图解决这个问题时,当我尝试手动完成时也会发生这种情况。在我添加了Maven Natives Repository之后它停止了这一点,但我不知道为什么Jenkins仍在花时间,因为他们共享相同的本地仓库和

更新:在试图找出正在发生的事情后,我似乎已将其缩小为与maven程序集插件相关,因为如果我从我的pom中取出那部分它可以正常工作。

以下是我的pom文件的相关部分:

<repositories>
    <repository>
        <id>slick</id>
        <name>slick</name>
        <url>http://slick.cokeandcode.com/mavenrepo</url>
    </repository>
    <repository>
        <id>mavenNatives</id>
        <name>Maven Natives Repository</name>
        <url>http://mavennatives.googlecode.com/svn/repo</url>
    </repository>
    <repository>
        <id>nolat.org</id>
        <name>Nolat</name>
        <url>https://raw.github.com/Talon876/repo/master/releases</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.8.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.16</version>
    </dependency>
    <dependency>
        <groupId>org.nolat</groupId>
        <artifactId>toolkit</artifactId>
        <version>1.0</version>
    </dependency>
    <dependency>
        <groupId>org.lwjgl.lwjgl</groupId>
        <artifactId>lwjgl</artifactId>
        <version>2.8.3</version>
    </dependency>
    <dependency>
        <groupId>slick</groupId>
        <artifactId>slick</artifactId>
        <version>274</version>
    </dependency>
</dependencies>
<build>
    <plugins>
        [...]
        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.3</version>
            <executions>
                <execution>
                    <id>jar-with-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <archive>
                            <manifest>
                                <mainClass>${main}</mainClass>
                                <addClasspath>true</addClasspath>
                            </manifest>
                        </archive>
                        <appendAssemblyId>false</appendAssemblyId>
                    </configuration>
                </execution>
                <execution>
                    <id>dist</id>
                    <phase>package</phase>
                    <goals>
                        <goal>single</goal>
                    </goals>
                    <configuration>
                        <descriptors>
                            <descriptor>src/META-INF/dist.xml</descriptor>
                        </descriptors>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
 </build>

以下是Jenkins控制台的相关部分(每个下载行都是在放弃和继续之前放置一段时间):

[JENKINS] Recording test results
mojoStarted org.apache.maven.plugins:maven-jar-plugin:2.3.2(default-jar)
[INFO] 
[INFO] --- maven-jar-plugin:2.3.2:jar (default-jar) @ Falldown ---
mojoSucceeded org.apache.maven.plugins:maven-jar-plugin:2.3.2(default-jar)
mojoStarted org.apache.maven.plugins:maven-assembly-plugin:2.3(jar-with-dependencies)
[INFO] 
[INFO] --- maven-assembly-plugin:2.3:single (jar-with-dependencies) @ Falldown ---
Downloading: http://slick.cokeandcode.com/mavenrepo/phys2d/phys2d/060408/phys2d-    060408.pom
Downloading: http://mavennatives.googlecode.com/svn/repo/phys2d/phys2d/060408/phys2d-060408.pom
Downloading:     https://raw.github.com/Talon876/repo/master/releases/phys2d/phys2d/060408/phys2d-060408.pom
Downloading: http://repo.maven.apache.org/maven2/phys2d/phys2d/060408/phys2d-060408.pom
Downloading: http://slick.cokeandcode.com/mavenrepo/org/lwjgl/lwjgl/2.1.0/lwjgl-2.1.0.pom
Downloading: http://mavennatives.googlecode.com/svn/repo/org/lwjgl/lwjgl/2.1.0/lwjgl-  2.1.0.pom
Downloading:    https://raw.github.com/Talon876/repo/master/releases/org/lwjgl/lwjgl/2.1.0/lwjgl-2.1.0.pom
Downloading: http://repo.maven.apache.org/maven2/org/lwjgl/lwjgl/2.1.0/lwjgl-2.1.0.pom
Downloading: http://slick.cokeandcode.com/mavenrepo/org/lwjgl/lwjgl-jinput/2.1.0/lwjgl-jinput-2.1.0.pom
Downloading: http://mavennatives.googlecode.com/svn/repo/org/lwjgl/lwjgl-   jinput/2.1.0/lwjgl-jinput-2.1.0.pom
Downloading: https://raw.github.com/Talon876/repo/master/releases/org/lwjgl/lwjgl- jinput/2.1.0/lwjgl-jinput-2.1.0.pom
Downloading: http://repo.maven.apache.org/maven2/org/lwjgl/lwjgl-jinput/2.1.0/lwjgl-jinput-2.1.0.pom
Downloading: http://slick.cokeandcode.com/mavenrepo/org/lwjgl/lwjgl-native/2.1.0/lwjgl-native-2.1.0.pom
Downloading: http://mavennatives.googlecode.com/svn/repo/org/lwjgl/lwjgl-native/2.1.0/lwjgl-native-2.1.0.pom
Downloading: https://raw.github.com/Talon876/repo/master/releases/org/lwjgl/lwjgl-native/2.1.0/lwjgl-native-2.1.0.pom
Downloading: http://repo.maven.apache.org/maven2/org/lwjgl/lwjgl-native/2.1.0/lwjgl-native-2.1.0.pom
Downloading: http://slick.cokeandcode.com/mavenrepo/javax/jnlp/jnlp/1.2/jnlp-1.2.pom
Downloading: http://mavennatives.googlecode.com/svn/repo/javax/jnlp/jnlp/1.2/jnlp-1.2.pom
Downloading: https://raw.github.com/Talon876/repo/master/releases/javax/jnlp/jnlp/1.2/jnlp-1.2.pom
Downloading: http://repo.maven.apache.org/maven2/javax/jnlp/jnlp/1.2/jnlp-1.2.pom
Downloading: http://slick.cokeandcode.com/mavenrepo/ibxm/ibxm/unknown/ibxm-unknown.pom
Downloading: http://mavennatives.googlecode.com/svn/repo/ibxm/ibxm/unknown/ibxm-unknown.pom
Downloading: https://raw.github.com/Talon876/repo/master/releases/ibxm/ibxm/unknown/ibxm-unknown.pom
Downloading: http://repo.maven.apache.org/maven2/ibxm/ibxm/unknown/ibxm-unknown.pom
Downloading: http://slick.cokeandcode.com/mavenrepo/jcraft/jogg/0.0.7/jogg-0.0.7.pom
Downloading: http://mavennatives.googlecode.com/svn/repo/jcraft/jogg/0.0.7/jogg-0.0.7.pom
Downloading: https://raw.github.com/Talon876/repo/master/releases/jcraft/jogg/0.0.7/jogg-0.0.7.pom
Downloading: http://repo.maven.apache.org/maven2/jcraft/jogg/0.0.7/jogg-0.0.7.pom
Downloading: http://slick.cokeandcode.com/mavenrepo/jcraft/jorbis/0.0.15/jorbis-0.0.15.pom
Downloading: http://mavennatives.googlecode.com/svn/repo/jcraft/jorbis/0.0.15/jorbis-0.0.15.pom
Downloading: https://raw.github.com/Talon876/repo/master/releases/jcraft/jorbis/0.0.15/jorbis-0.0.15.pom
Downloading: http://repo.maven.apache.org/maven2/jcraft/jorbis/0.0.15/jorbis-0.0.15.pom
[WARNING] Artifact: org.nolat:Falldown:jar:1.0-SNAPSHOT references the same file as the assembly destination file. Moving it to a temporary location for inclusion.
[INFO] META-INF/ already added, skipping
[INFO] META-INF/MANIFEST.MF already added, skipping
[INFO] org/ already added, skipping
...and so on

2 个答案:

答案 0 :(得分:1)

获得稳定的Maven构建的第一步是使用Maven Repository Manager,例如Nexus

  • 安装Maven Repoitory Manager(和Jenkins一样,如果您是唯一的开发人员,可以在本地安装Nexus)
  • Configure Maven to use a single Nexus group。您必须为每个用户执行此操作,如果您有专门的系统用户运行Jenkins(推荐方法),也必须为Jenkins用户执行此操作。如果您使用的是与Nexus不同的Maven Repository Manager,请查看文档。
  • 仅在Maven Repository Manager中定义存储库。 POM中没有存储库部分!

完成此操作后,请检查行为并告诉我们您是否有任何问题。

答案 1 :(得分:0)

似乎maven程序集插件是尝试下载内容的原因所以我用maven shade插件替换它,这让我排除了一些我想要排除的文件。不确定这是否是最好的解决方案,但它适用于我的情况。结束了我的构建时间从8分钟减少到25秒。

这是我在取出程序集插件的jar-with-dependencies部分后添加到我的pom中的内容。

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>1.6</version>
            <configuration>
                <createDependencyReducedPom>false</createDependencyReducedPom>
            </configuration>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                        <transformers>
                            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                <mainClass>${main}</mainClass>
                            </transformer>
                        </transformers>
                        <filters>
                            <filter>
                                <artifact>*:*</artifact>
                                <excludes>
                                    <exclude>*.dll</exclude>
                                    <exclude>*.so</exclude>
                                    <exclude>*.jnilib</exclude>
                                </excludes>
                            </filter>
                        </filters>
                    </configuration>
                </execution>
            </executions>
        </plugin>