Jenkins : Add custom jar in maven project - java

I am trying to add custom jar which is not available in Maven repository. When I am executing in local I am pointing to the Jar path, So no issues. But when I execute with Jenkins I am facing issue as Could not resolve dependencies for project. Also it list down the two Jar file missing which I added custom.
So help me how to add the custom Jar wile executing using Jenkins. Also I am using Nexus for binary storage. After Jenkins executes successfully the image file will be posted to the nexus directory with versioning.

You have 2 options
1) If your have access to the local Nexus/Artifactory repo that your Jenkins uses you can add the jar to that repository and it will be downloaded as normal.
2) You can have a local repository where you check the jar into SCM under your project. You would then access it like this in your pom. See http://doduck.com/adding-local-jar-in-maven-local-repository/
<repositories>
<repository>
<id>localrepository</id>
<url>file://${basedir}/repo</url>
</repository>
</repositories>

Related

Maven: How to check if jar is not uploaded in central repo

How can I be sure that my jar files ARE NOT loaded to central repo maven? I am asking this question as I saw several times exception like - error while uploading to central repo. I was shocked (as I didn't make any configurations in pom and not applied to central repo administration). That's why I decided to ask this question.
So, how can I check that the absence or presence of some code guarantee that my jar is not uploading to central repo?
You can specify which repository your project should be deployed to via the Distribution Management section of pom.xml. I think there is no default. However, it's possible that you have a parent pom.xml specified and it contains some setting. If that is the case, you can modify parent. Failing that, you can override it by putting your own private repository details in this section to avoid deploying your artifacts anywhere else. It can even be invalid URL, in which case deployment will simply always fail.
Example:
<distributionManagement>
<snapshotRepository>
<id>fake-snapshots</id>
<url>https://fake/snapshots</url>
</snapshotRepository>
<repository>
<id>fake-releases</id>
<url>https://fake/releases</url>
</repository>
</distributionManagement>
Check whether are you using deploy:deploy-file goal under maven-deploy-plugin in your POM.xml.
This feature is used to deploy jar files to the remote repo.

Maven/IntelliJ import error: io.vertx.core does not exist

I am trying to get the vertx library to compile in IntelliJ (w/ maven)
I had a lot of trouble getting maven to recognize/download the vertx dependency but I was able to resolve the dependency issues by downloading and installing the vertx libraries via the command line. Now I no longer have issues with the vertx dependencies and when I check the project dependencies in IntelliJ it has the correct path and shows no errors.
The maven libraries in 'project structure' show up correctly and I've checked the directories for the .jar and .java files, they're all there.
I've also set my maven home directory to a fresh maven install:
C:/Program Files/apache-maven-3.3.3
and the settings file to the correct file:
C:\Users[User].m2\settings.xml
and the local repository (where maven has installed the requisite libraries)
C:\Users[User].m2\repository
These directories line up with libraries I've installed and the maven directories that seem to be working correctly (little red line that was there before I reinstalled the libraries and reset the caches is gone)
However, I am still not able to use the vertx libraries.
Also, this code is working on a friends mac, but I'm running windows and can't seem to get it to compile (java package does not exist error).
I was able to install the module with Maven by going to File - Project Structure - Add Libraries - Maven - and after googling the name of the module (it's io.vertx:vertx-core - io.vertx.core won't bring it up) I was able to install it fully using Maven and add it as a dependency from within IntelliJ. HTH.
So it took me forever, but I figured this out.
This was a caching issue and a problem with intelliJ not recognizing that I was importing a snapshot library with maven.
1: for some reason the settings.xml file that the vertx download website has does not have snapshots enabled, but (from what I understand) the most recent build of their system is a snapshot that maven updates from time to time. If snapshots are not enabled, maven intelliJ wont update/recognize the libraries. This was happening even though I had installed the libraries with mvn install.
settings.xml should look like:
<profiles>
<profile>
<id>allow-snapshots</id>
<activation><activeByDefault>true</activeByDefault></activation>
<repositories>
<repository>
<id>snapshots-repo</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<releases><enabled>false</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
</profile>
</profiles>
2: After I fixed the above issue, I still had the same issue until I deleted the local cached libraries I had previously installed with maven (/user/.m2/repositories). For some reason intelliJ wouldn't recognize them. Once deleted, maven/intelliJ redownloaded them and then recognized them from that point on.

Maven Local Repository, Two machines and Git: missing artifact

I am building a Java project using Maven. Since I need to add one jar file that has not been deployed on the central Maven repository (OpenCV), I created on the first machine, named M1, a local repository and deployed (mvn deploy:deploy-file) the external jar lib.jar file into that repository.
In the project pom.xml file I added the following lines:
<repositories>
<repository>
<id>in-project</id>
<name>In Project Repo</name>
<url>file://${project.basedir}/libs</url>
</repository>
</repositories>
On machine M1 everything is fine.
I use git both for versioning and for syncing two development environments on two different machines, M1 and M2 (I do not think it's relevant, but M1 has OS X and M2 has linux).
However, after a git pull on M2, if I run maven on M2 I get an error message caused by the missing artifact lib.jar from the local repo.
M1 has maven 3.2.2, M2 has maven 3.0.4.
Is there any way to move local repositories using git or another software?
Thanks.
Solution is to create a remote repo, not local repo:
setup a Sonatype Nexus or Jfrog Artifactory instance
upload your jar into it
edit your settings.xml file to mirror it
That will allow any maven build you run to retrieve the jar regardless of machine.

How to load/add third party jar files to bitbucket?

I want to load some jar file that are not present in maven repository or any other such repository.
For that I have created a repository named as "maven-repo" on bitbucket and cloned it to my local machine.
Now I am using command
mvn install:install-file -DgroupId=groupid -DartifactId=myid
-Dversion=5.1 -Dfile=/path to file/filename.jar -Dpackaging=jar -DgeneratePom=true -DlocalRepositoryPath=./repository -DcreateChecksum=true
After that I push that folder/repository to bitbucket server.
Now I want to add it to my maven project's pom.xml.
I added like:
<repository>
<id>Hyperv </id>
<url>https://myurl/repository/</url>
</repository>
But it gives me error failed to load a jar.
How to include a jar file and import classes in project???
Deploying with Maven
From official documentation (I cannot link, this is a popup)
Bintray adds a new layer to traditional Maven repositories in the form of a package.
A package acts as container for managing metadata about your project and its versions and may contain a collections of artifacts with different group ids.
When uploading files to a repository, you can associate them with specific package and version information in various ways:
Deploying to this repository
Please go into a specific package in this repository to see how to set up Maven to deploy artifacts to that package.
In Maven’s setting.xml file, add the following section to declare your Bintray credentials. Use your API key as your password (not your login password, please!):
<server>
<id>bintray-user-package-package</id>
<username>user</username>
<password>**********</password>
</server>
Add the the following Distribution Management section to your project’s pom.xml file to tell Maven to deploy into this package using the credentials you configured in the previous step:
<distributionManagement>
<repository>
<id>bintray-user-repo-package</id>
<name>user-repo-package</name>
<url>https://api.bintray.com/maven/user/repo/package</url>
</repository>
</distributionManagement>
Manual deploy
Prepare artifact folder as is described in How Do I Upload My Stuff to Bintray?
And deploy using commannd like this
mvn deploy:deploy-file -DpomFile=myfile-0.1.pom -Dfile=myfile-0.1.jar -DrepositoryId=bintray -Durl=https://api.bintray.com/maven/user/repo/package
In general deploying with maven is much easier

multiple repositories with the same artifact in maven

I have made some modifications to log4j and would like my project to use my local version rather than that from the remote maven repo, so I declared my project as a local repo in pom.xml in addition to my remote repo for other dependencies:
<repository>
<id>my-log4j</id>
<name>my log4j</name>
<url>file:///...</url>
</repository>
<repository>
<id>remote</id>
<name>remote repo</name>
<url>http://...</url>
</repository>
maven copied the files from my local repo as expected, but then it downloaded log4j again from the remote repo and overwrote the earlier files. Is there a way to exclude certain artifacts from being downloaded from the remote repo?
Also, how does maven detect changes to my-log4j? How can I make maven copy the my-log4j artifacts each time during compilation?
If you make a custom version of something, you give it a custom version number.
For example, if you modify log4j-1.2.17 for your own use, give it the version 1.2.17.JRR.1 and following numbers as you work on it.
You build them on your computer and when you run the install goal, it will put them in your local repo. If you have a shared repo for your group, it can be deployed there as well and never confused with the Apache releases.
This will never be found in the remote repo, just in yours.
If maven looks for artifacts, it always looks in your local repository first, you do not have to specify it (you can specify the location of your local repository in your settings.xml).
You answered your question already: If you had to change a third-party artifact, rename it (already in the pom.xml) like my-log4j or log4j-my-patch. Then it won't collide with the original artifacts.

Categories

Resources