【发布时间】:2014-09-01 16:25:17
【问题描述】:
我正在尝试编写一个简单的 Jenkins 插件,它需要一个专有的外部库 myAwesomePackage.jar。在 stackoverflow 上经常讨论将外部 jars 包含到 maven 项目中,这里的解决方案 https://stackoverflow.com/a/7623805 似乎是解决这个问题的好方法。
所以我用
添加了我的罐子mvn install:install-file \
-Dfile=./lib/path_to_jar/lib/myAwesomePackage.jar \
-DlocalRepositoryPath=my_repo \
-DcreateChecksum=true \
-DgroupId=myAwesomePackage \
-DartifactId=myAwesomePackage \
-Dversion=1 \
-Dpackaging=jar \
-DgeneratePom=true
并修改了我的 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>
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.532.3</version>
</parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>myPlugin</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>hpi</packaging>
<licenses>
<license>
<name> ... license name ... /name>
<url> ... license url ... </url>
</license>
</licenses>
<repositories>
<repository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
</repository>
<repository>
<id>my_repo</id>
<url>file://${project.basedir}/my_repo</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/public/</url>
</pluginRepository>
</pluginRepositories>
<dependencies>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.xml.rpc</artifactId>
<version>3.0-Prelude-Embedded-m2</version>
</dependency>
<dependency>
<groupId>myAwesomePackage</groupId>
<artifactId>myAwesomePackage</artifactId>
<version>1</version>
</dependency>
</dependencies>
</project>
而且我没有 ~/m2/.settings 文件。
我得到的错误信息(在运行mvn package 之后)如下:
.....
Downloaded: http://repo.jenkins-ci.org/public/javax/servlet/servlet-api/2.4/servlet-api-2.4.jar (96 KB at 79.2 KB/sec)
Downloaded: http://repo.jenkins-ci.org/public/xalan/xalan/2.7.1/xalan-2.7.1.jar (3102 KB at 150.7 KB/sec)
Downloaded: http://repo.jenkins-ci.org/public/org/jenkins-ci/main/jenkins-war/1.532.3/jenkins-war-1.532.3-war-for-test.jar (62097 KB at 467.9 KB/sec)
Downloading: file:///home/path_to/my_repo/myAwesomePackage/myAwesomePackage/1/myAwesomePackage-1.jar
Downloading: http://repo.maven.apache.org/maven2/myAwesomePackage/myAwesomePackage/1/myAwesomePackage-1.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12:17.009s
[INFO] Finished at: Fri Jul 11 01:40:32 EDT 2014
[INFO] Final Memory: 12M/86M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project myPlugin: Could not resolve dependencies for project org.jenkins-ci.plugins:myPlugin:hpi:1.0-SNAPSHOT: Could not find artifact myAwesomePackage:myAwesomePackage:jar:1 in repo.jenkins-ci.org (http://repo.jenkins-ci.org/public/) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
所以我的问题是: 将专有 jar 包含到使用 maven 构建的 jenkins 插件中的正确方法是什么?
【问题讨论】: