Jenkins插件(使用Maven构建)和外部罐子

时间:2014-07-11 06:05:51

标签: java maven jar jenkins

我试图编写一个简单的Jenkins插件,这需要一个专有的外部库myAwesomePackage.jar。将外部jar包含到maven项目中经常在stackoverflow上进行讨论,这里的解决方案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包含到jenkins插件中的正确方法,该插件是用maven构建的?

2 个答案:

答案 0 :(得分:1)

由于您已在repositories中手动指定pom.xml,因此会在这些存储库中查找无法解析的myAwesomePackage:myAwesomePackage:jar:1工件

pom.xml

下的<repositories>中添加此工件可用的存储库

答案 1 :(得分:1)

我的问题中描述的程序有效! 由于-Dfile=....选项中的输入错误而发生错误,但maven没有给出任何我认为操作成功的错误。 正如Jigar Joshi的评论所述,mvn clean install -X有助于调试此类问题。