mvn package ignoring repository in pom.xml - java

We cannot get a project to pull from a remote repository using mvn package. In maven installed folder, config/settings.xml we declare our internal central repo:
<mirrors>
<mirror>
<id>advnexus</id>
<mirrorOf>*</mirrorOf>
<url>http://internalserver/nexus/content/groups/public</url>
</mirror>
</mirrors>
This works for all of the jar files hosted at this repo. But we have some additional jar files we pushed to a server under our control and running Sonatype Nexus. So in the project's pom.xml, we setup our remote repo as:
<repositories>
<repository>
<id>companynamenexus</id>
<name>Company Name Project Repo</name>
<url>http://nexus.companyname.com:8081/repository/project-name</url>
<layout>default</layout>
<spanshots>
<enabled>false</enabled>
</spanshots>
</repository>
</repositories>
When I run the build, it pulls any needed jar files from the main repo, but simply times out trying to pull the jar files that don't exist on this repo vs. using the repository in the pom.xml.
Note that in the settings.xml mirror section, I tried changing the <mirrorOf> to be central vs. *, but this just caused additional errors.
I have also tried setting up this repo as a secondary mirror in the settings.xml, tried commenting out the mirror in the settings.xml and place it as an additional repository in the pom.xml, all without finding the right combination. Seems like a simple problem, but the answer is eluding us.

Best solution: Don't try to access two different internal Nexus, but set up a repository group in one of the Nexus that contains all other repositories (may they be hosted or proxy, internal or external). Then you can simply set a mirror entry on that repository group and you are fine.
Second best solution: Change your mirror entry to <mirrorOf>*,!companynamenexus</mirrorOf> and define the additional repository in the <repositories> section of your settings.xml.

Related

If a Maven artifact is not in central repository and local, how to automatically search which public repository to add in pom.xml?

I am new to maven and find that some artifacts are not on Maven central repository, so I need to manually add repository 's id and url in pom.xml. It's relatively easy if I were the original developer of the project, but hard as a maintainer.
For example, I get a Maven project from GitHub. The project has an dependency on org.openhab.addons.bundles:org.openhab.addons.reactor.bundles:3.2.0-SNAPSHOT, which is not on Maven central repository.
What I do is Google org.openhab.addons.bundles org.openhab.addons.reactor.bundles to try finding which public repository should I add in pom.xml.
Like
<repositories>
<repository>
<id>openhab</id>
<url>https://openhab.jfrog.io/openhab/libs-release/</url>
</repository>
</repositories>
My question is that given a Maven artifact's coordinate, how can I programmatically find which repository should I add in pom.xml?
Thank you.

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.

How to import a deployed jar "SNAPSHOT" from local Artifactory repository into another project?

I am a newbie in Artifactory, I have 2 projects one depends on another...
I set up Artifactory on a server and deploy the first jar into libs-snapshot....and change the C:\Users.m2\setting.xml and add this tag in the pom of the deployed project:
<distributionManagement>
<snapshotRepository>
<id>serverId</id>
<name>serverName</name>
<url>serverUrl/artifactory/libs-snapshot/</url>
</snapshotRepository>
</distributionManagement>
how can I access the first project from the second one via Artifactory repository
I am working on Netbean8.2, glassfish 4 and artifactory 4
By default, maven doesn't know to look anywhere except your local repo and maven central. You'll need to tell it the additional repos it can look in either via a pom setting or settings.xml.
You can see some example and additional details in the Maven docs.

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

"Missing artifact" errors with company repository

I setup a company maven repository using artifactory. I deployed a project of us into the repository. If I now specify a dependency to that artifact, it doesn't get retrieved. Which it should, because I declared this in my settings.xml:
<mirrors>
<mirror>
<id>company-internal</id>
<name>company repository</name>
<url>http://company.repository:8080/artifactory/repo/</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
This works for all 3rdparty dependencies. The artifact is definitely in the reposity, manually I can download the artifact just fine. Why is maven not able to download it? Is it more likely to be a problem with maven (or the configuration there), or is there a bug in artifactory? Is there something which is handled differently in case of SNAPSHOTs?
You'll have to add your company repository under the "repositories" element.
The "mirrors" element is for specifying local mirrors for repositories like "central".
it should work, can you give more informations ?
dependency snippet you use to get the artifact
pom.xml of the artifact in the repository

Categories

Resources