【问题标题】:Jenkens Plugin (build with Maven) and external jarsJenkens 插件(使用 Maven 构建)和外部 jars
【发布时间】: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 插件中的正确方法是什么?

【问题讨论】:

    标签: java maven jar jenkins


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      pom.xml 下的&lt;repositories&gt; 下添加此工件可用的存储库

      【讨论】:

      • 我以为我是用 my_repofile://${project.basedir}/my_repo。最后第二个下载日志说,它正在使用它,最后一个下载日志说,maven 也在其他地方搜索它,但是为什么呢?
      • 您可以手动将该 jar 安装到您的本地缓存中,并且让 maven 不用担心它的远程分辨率吗? (或设置一个适当的 nexus 存储库并在那里管理您的工件)
      • 老实说,我是 maven 的初学者 .... 本地缓存是什么意思?有没有办法直接将jar添加到java类路径中?
      • myAwesomePackage:myAwesomePackage:1 的真正价值是什么?
      • 这是一个专有的jar文件
      猜你喜欢
      • 2014-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-12
      • 1970-01-01
      • 2010-12-29
      • 1970-01-01
      相关资源
      最近更新 更多