我有一个我们项目所需的第三方jar。 它在中央maven仓库中是不可用的,所以我使用maven-install-plugin在本地安装这个jar。 我把 "install-file "的目标与 "validate "阶段联系在一起,这样做大部分都能成功。 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/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"。 "validate "阶段并不是 "clean "生命周期的一部分,而且clean莫名其妙地要求所有的依赖关系都存在才能运行。 因此,当有人第一次运行这个构建时,它无法工作。
[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 install",那么在 "validate "期间就会安装jar,并且我可以在后续的构建中运行 "mvn clean install"。 然而,我们的构建服务器没有这种灵活性。 我考虑了以下几点。
理想情况下,我希望能有其他的选择。 是否可以在没有依赖关系的情况下运行clean? 或者在不完全复制执行的情况下运行一个插件两次? 谢谢
看起来你使用的是nexus。将工件部署到nexus repo可能会更容易,而不是用这个项目来维护它。
我遇到了一个相关的问题,我在谷歌搜索解决方案时发现了这个问题,所以我在这里把它记录下来。
在多模块项目中,如果在清理过程中调用了插件,那么当同一项目中缺少依赖关系时,mvn清理失败。
我们在清理阶段会在一些模块中调用antrun-plugin,正因为如此,所有的依赖关系都需要存在于maven仓库中,包括同一反应器中的其他模块,在某些情况下,这些模块还没有被构建(比如说你刚刚颠覆了项目版本,或者你正在启动一个新项目)。
这是一个maven-antrun的bug,在下面的文章中已经报告了。https:/issues.apache.orgjirabrowseMANTRUN-78。 - 这又回到了maven core的一个bug。https:/issues.apache.orgjirabrowseMNG-3283。.
我的变通办法是为开发者(和Jenkins)提供一种替代的清理方式(shellbat脚本、ant脚本或一些githg清理操作),让他们调用这种方式。
我建议你的团队采用类似的变通方法(或者直接在团队内部建立一个共享的maven仓库,必要时使用其中一台开发者机器)。
这个未经测试,但你能不能不要忽略干净插件的配置中的错误? 就像在。
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<failOnError>false</failOnError>
</configuration>
</plugin>
(这是来自... Maven清洁插件:忽略清洁错误)
这里还有一种可能。
配置maven跳过clean阶段,在初始化时运行clean。 不过还没试过。
这样做的缺点是,maven会一直清理输出文件夹。