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
Related
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.
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.
When I run
mvn compile
I get package com.ibm.icu.util does not exist. So I downloaded the ICU4J jar and installed it into the local repository. I confirmed it's in .m2/repository/com/ibm/icu/icu4j/3.4.4/icu4j-3.4.4.jar. Inside that jar file is the missing class file com/ibm/icu/util/Calendar.class. Then I added the following into the dependencies section of pom.xml:
<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
<version>3.4.4</version>
</dependency>
But when I run mvn compile again, I get the same error. What am I doing wrong?
You should avoid adding dependencies manually.
If you don't know a groupId and artifactId of the dependency you need, search for it at http://mvnrepository.com/. Usually, groupId matches the package names in the jar file.
For your case, the dependency is already there: http://mvnrepository.com/search?q=com.ibm.icu
So, go to http://mvnrepository.com/artifact/com.ibm.icu/icu4j and get the version of the dependency you need, e.g. 55.1: http://mvnrepository.com/artifact/com.ibm.icu/icu4j/55.1
Grab maven dependency xml and put it to your pom.xml file:
<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
<version>55.1</version>
</dependency>
If you didn't find your dependency try to find it in google. Sometimes the dependency may be found in some corporate public repositories, not in a central. In this case you need to add the third-party repository to repositories section of your pom.xml.
If you're unable to find your dependency in the public repository then you have three options:
A. Install jar to internal repository server (e.g. nexus)
B. Put the JAR file in your project sources and declare project maven repository :
<repositories>
<repository>
<id>my-local-repo</id>
<url>file://${basedir}/my-repo</url>
</repository>
</repositories>
Important: You should keep the maven repository layout in your local repository.
C. [Bad Practice] Use maven install plugin to install your custom jar to local repository on your machine. But it's a badIt's not recommended.
mvn org.apache.maven.plugins:maven-install-plugin:2.5.2:install-file -Dfile=path-to-your-artifact-jar -DpomFile=path-to-pom
D. [Bad Practice] Use system dependency with absolute path to the JAR file, although it's a bad practice and should be avoided.
<dependency>
<groupId>test</groupId>
<artifactId>test</artifactId>
<version>X.Y.Z</version>
<scope>system</scope>
<systemPath>${user.home}/jars/my.jar</systemPath>
</dependency>
You should not be manually installing things into the maven repository directory. That directory is maintained by maven itself.
The way dependencies work is that when you run mvn compile or some other goal, it will connect to the maven central repository and download the needed dependencies and their dependencies.
If you manually install a jar file, it may not have it's dependencies. That icu artifact will likely have other things it depends on. Maven will automatically resolve these dependencies.
I would recommend using mvn clean install this will clean the target directory and rebuild everything.
If it fails to download, then you likely need to change the maven configuration. For example, if you are behind a proxy server you need to configure maven with the proxy credentials.
Also, if you manually copied anything into the .m2/repository/ directory you should delete it and let maven put it in there correctly instead.
The beauty of maven is that you don't need to worry about things like downloading jars. It just handles that for you. Let it do it's job.
If you have an internal artifactory like JFrog maybe you should check that the jar is there. Do not download manually to .m2 because it's at least strange. At most you can upload the jar in that artifactory manually.
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.
My pom.xml use the following code to define the company 's internal Maven repository such that the dependencies will be downloaded from this repository if they cannot be found in my local repository.
<repositories>
<repository>
<id>XXXXXX</id>
<name>Internal Repository</name>
<url>http://private.ip/nexus-webapp/content/groups/public/</url>
</repository>
</repositories>
When I add some dependencies in pom.xml , I find that the dependencies I added will also be added to that internal repository . Besides deleting <repositories> section in pom.xml , can I configure its attributes such that the dependencies added in the pom.xml will not be added to this internal repository?
It sounds like what you're talking about is Nexus' proxying mechanism. You request artifacts from Nexus, and it looks at configured outside repos for the artifacts, caches them locally and returns them to you. That assumes the repositories in question are configured to be proxied through Nexus, of course. If someone set it up that way, then why do you want to circumvent it? You'd use Nexus in this way so the artifacts are closer to you and your builds work faster. The only way you'd get this not to happen is to change the settings in Nexus or else stop using it. You don't have to remove the repo entirely from the pom. Just put other repos ahead of it, and Maven will look in those first. But again, why would you not want to use Nexus as it was designed as a near cache for artifacts?
You need to configure it in your repository software (Artifactory, Nexus, ...).
I think you have set up a proxy repository here which downloads every artefact requested. You might want to try running a 'hosted repository' instead. More info here.
The equivalent concept in Artifactory is a 'local repository' (read here).
Download and install the dependencies you need manually using following command. It will add the package to your local repository such that you can use it. Read here
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
-DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>