1

I'm trying to write a simple Jenkins plugin, which requires a proprietary external library myAwesomePackage.jar. Including external jars into a maven project was often discussed here on stackoverflow and the solution here https://stackoverflow.com/a/7623805 seems to be the tidy way solve this.

So I added my jar with

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 

and modified my pom.xml that it looks like

<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>

And I don't have a ~/m2/.settings file.

The error message, I get (after running mvn package) is the following:

.....
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

So my question is: Which is the right way to include a proprietary jar into a jenkins plugin, which is build with maven?

Community
  • 1
  • 1
feddischson
  • 136
  • 1
  • 8

2 Answers2

1

Since you have manually specified repositories in your pom.xml it will look in those repositories for your myAwesomePackage:myAwesomePackage:jar:1 artifact which isn't resolvable from it

add the repository where this artifact is available in your pom.xml under <repositories>

jmj
  • 237,923
  • 42
  • 401
  • 438
  • I thought I did this with ** my_repo file://${project.basedir}/my_repo **. The 2nd last Downloading log says, that it is using it and the last Downloading log says, that maven is also searching for it somewhere else, but why? – feddischson Jul 11 '14 at 06:17
  • can you just install that jar manually into your local cache and have maven not worry about its resolution remotely ? (or setup a proper nexus repository and manage your artifact there) – jmj Jul 11 '14 at 06:19
  • To be honest I'm a beginner with maven .... what do you mean with local cache? Is there a way to add a jar directly to the java classpath? – feddischson Jul 11 '14 at 06:24
  • what is the real value for `myAwesomePackage:myAwesomePackage:1` ? – jmj Jul 11 '14 at 06:26
  • It is a proprietary jar file – feddischson Jul 11 '14 at 06:33
  • refer [this](http://stackoverflow.com/questions/22706173/maven-ojbc-6-jar-not-found-in-central-repository) to install that jar to your local maven repository with groupId, artifactId, version as specified in your `` and retry – jmj Jul 11 '14 at 06:44
  • Thats what I did (see beginning of my question). – feddischson Jul 11 '14 at 07:11
  • oh missed that, remove `-Dfile=./lib/path_to_jar/lib/myAwesomePackage.jar`, and try exact command shown in that my another answer - http://stackoverflow.com/questions/22706173/maven-ojbc-6-jar-not-found-in-central-repository – jmj Jul 11 '14 at 07:12
  • Removing the -Dfile doesn't make sense, because it specifies the jar file, which we want to add: `[ERROR] Failed to execute goal org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file (default-cli) on project myPlugin: The parameters 'file' for goal org.apache.maven.plugins:maven-install-plugin:2.3.1:install-file are missing or invalid -> [Help 1]` – feddischson Jul 14 '14 at 06:33
  • The command, which you mentioned in your answer is the same than I did, just without the -DcreateChecksum and -DlocalRepositoryPath option. If I do the command without these two options, it successfully adds the jar to the repository: [INFO] Installing .../path/to/my/jar/myAwesomePackage to /home/user_name/.m2/repository/myAwesomePackage/myAwesomePackage/1/myAwesomePackage-1.jar [INFO] Installing /tmp/mvninstall5085297968308767822.pom to /home/christian/.m2/repository/myAwesomePackage/myAwesomePackage/1/myAwesomePackage-1.pom – feddischson Jul 14 '14 at 06:39
  • But `mvn package` fails with the error: `[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]` – feddischson Jul 14 '14 at 07:06
  • looks like it is trying to read it from other repository, try running `mvn clean package -X` and it will say from which local repository it is reading, you might have specified it somewhere in `settings.xml` – jmj Jul 14 '14 at 07:10
  • It says, that it tries to read the package from http://repo.jenkins-ci.org/public. There should be an option within `...` to specify, in which repository the dependency can be found (in this case in a local repository). Unfortunately, my maven knowledge is very limited. – feddischson Jul 14 '14 at 07:37
  • post first 10 line of logs with `mvn clean install -X` – jmj Jul 14 '14 at 07:39
1

The procedure as described in my question works! The error occurred due to a typing error within the -Dfile=.... option, but maven doesn't give any error I thought that operation was successful. As described in the comments of Jigar Joshi, a mvn clean install -X helps to debug such troubles.

feddischson
  • 136
  • 1
  • 8