The question is, I want to add the .jar library to the maven project so that jenkins is going to be fine.

Accordingly, 2 questions:

  1. I read the article https://habrahabr.ru/company/lanit/blog/323008/ maven compiled it, I wrote it in pom.xml dependecy, I didn’t quite understand the moment:

    Letting the project know that the repository exists, and show where it is located, you can already described method, however, adjusted for the fact that the repository is local.

    <repositories> <repository> <id>localrep</id> <name>local repository</name> <url>file:${project.basedir}/lib</url> </repository> </repositories> 

    Can you please tell by example what to write here - it seems to be working now, but the search, as I understand it, does on a computer with jenkins, i.e. in file:${project.basedir} we specify the path to the local computer used.
    How to make it download from another computer?

  2. And from here comes the second question - if you need a folder with a “repository” that is open for internal locking, can you share it and specify it in <url></url> ?

  • There is also a site doduck.com/adding-local-jar-in-maven-local-repository , and there, as I understand it, the bottom example is directed to get the library straight from the maven project, I understand correctly? Only I have in pom.xml the path specified by / (slashes), red. Am I pointing wrong or what is wrong? (Write a way through slashes, just like in the example only in your project) - sank

2 answers 2

Before answering, I want to say that the only solution contradicts the ideology of maven . The correct solution is to install your library into a remote maven repository (possibly corporate / closed), which is done using the deploy command.

And now about the wrong, but working decision. At the root of the project, i.e. at the same level as the src folder, you create a folder (in the example, it is lib ) into which local libraries will be stored. Put the jar you need there. Further you do dependecy with scope system . Like that

  <dependency> <groupId>ru.stackoverflow.com</groupId> <artifactId>megalib</artifactId> <version>${project.version}</version> <scope>system</scope> <systemPath>${basedir}/lib/megalib.jar</systemPath> </dependency> 

But there are two nuances.

  1. The specified scope has been officially declared obsolete .
  2. If pom'nik has at least one dependency with scope as system , then this project will not add transient dependencies to dependent projects.
  • Thank you very much, earned! Regarding your answer, you can clarify: 1. Do not use - because in the case of updates, it will be necessary to rewrite everything — and the main thing is to avoid a mistake anywhere, otherwise jenkins simply won't start? 2. I understand that for such purposes they use Nexus ( sonatype.com/download-oss-sonatype ). Tell me tutorial? + Is it better to install it on the same computer as jenkins? - sank
  • @sank 1. I do not understand the question. 2. The most popular is nexus, others are listed here . I will not say good manuals in Russian, because he himself once put only with the official . - Temka too
  • Yes, I just clarified why it is not correct to write everything manually. Thanks, I will look! - sank

The above proposed variant with scopes takes place, but nothing prevents any library from installing into a local repository with real groupId, artifactId, version or fictional .. for the above artifact (with the fictional version 1.0.0) the command in the console will look like

 mvn install:install-file -DgroupId=ru.stackoverflow.com -DartifactId=megalib -Dversion=1.0.0 -Dfile=megalib.jar -Dpackaging=jar -DgeneratePom=true 

Of course, in order for this to work properly, you need the path to the maven to be registered in the path and you need to start it from the directory where megalib.jar is located

then insert the dependency into the pom file

 <dependency> <groupId>ru.stackoverflow.com</groupId> <artifactId>megalib</artifactId> <version>1.0.0.</version> </dependency> 

and enjoy

  • Yes, I did the same as in the article, I did not understand just how to write the way correctly. But thanks for the reply. - sank