我有我们的项目所必需的第三方jar。它在中央maven仓库中不可用,所以我使用maven-install-plugin在构建期间在本地安装jar。我将“安装文件”目标与“验证”阶段绑定在一起,而这主要起作用。 pom.xml文件摘录低于:mvn清洁没有依赖关系
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>install-myartifact</id>
<phase>validate</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<file>${basedir}/lib/myartifact-1.2.3.jar</file>
<groupId>com.example</groupId>
<artifactId>myartifact</artifactId>
<version>1.2.3</version>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>myartifact</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
但是,这里有一个问题。我们的大多数开发人员和我们的Jenkins安装都运行“mvn clean install”。 “验证”阶段不是“干净”生命周期的一部分,干净地莫名其妙地需要所有依赖关系存在才能运行。所以有人第一次运行这个版本,它不起作用。
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building MyModule
[INFO] task-segment: [clean, install]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean]
[INFO] Deleting directory C:\svn\trunk\mymodule\target
Downloading: http://nexusserver.local:8080/nexus/content/groups/public/com/example/myartifact-1.2.3.pom
[INFO] Unable to find resource 'com.example:myartifact:pom:1.2.3' in repository central (http://central)
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.
Missing:
----------
1) com.example:myartifact:jar:1.2.3
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=com.example -DartifactId=myartifact -Dversion=1.2.3 -Dpackaging=jar -Dfile=/path/to/file
Alternatively, if you host your own repository you can deploy the file there:
mvn deploy:deploy-file -DgroupId=com.example -DartifactId=myartifact -Dversion=1.2.3 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
Path to dependency:
1) com.example:mymodule:war:0.0.1-SNAPSHOT
2) com.example:myartifact:jar:1.2.3
----------
1 required artifact is missing.
for artifact:
com.example:mymodule:war:0.0.1-SNAPSHOT
from the specified remote repositories:
nexus (http://nexusserver.local:8080/nexus/content/groups/public)
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 second
[INFO] Finished at: Thu Jun 09 11:01:24 EDT 2011
[INFO] Final Memory: 17M/247M
[INFO] ------------------------------------------------------------------------
如果我是运行简单的“MVN安装”,罐子是在安装了“验证”,并且我可以运行“MVN净安装”,在随后的版本。但是,我们的构建服务器没有这种灵活性。我已考虑以下内容:
- 将阶段转到“预清理”,但假设每个人都始终使用清洁。如果有人只是简单地运行“mvn install”,这将无济于事。
- 复制执行过程,其中一个在“预清理”期间发生,另一个在“验证”期间发生。这涵盖了所有的基础,但复制的代码留下了不好的口味。
理想情况下,我想要其他选项。有没有依赖关系可以运行干净?或者运行插件两次而不必完全复制执行?谢谢!
这是一个很好的想法,但我们正处于一个分散的开发团队的国际公司。在主连线上获得它是一个漫长的过程。 =( – 2011-06-09 15:58:53
如何使用本地文件库?您可以将文件打包到您的模块的peer/child目录中,然后将该目录作为文件:repo添加到您的pom.xml文件中。您可以配置settings.xml以使用你的nexus回购作为镜像,但仍然允许本地文件回收 – massfords 2011-06-10 14:10:46
Massfords:更改settings.xml是一个非启动器,它会影响每个使用该构建的人,我最好是在主连接上获得工件。我会接受这个答案,因为即使它不能解决我的特殊情况,它应该适用于大多数人。 – 2011-06-13 19:27:41