unable to download maven repositories due to custom settings.xml? - maven

Here is my situation:
I am able to run mvn install on my personal computer and the build successful.
But when I run the same at workstation, I get the following error. This is most likely because I have a settings.xml in ${user.home}/.m2/settings.xml which refers to my company's repo and DOES NOT allow to fetch from remote maven repo. How can I overcome this behavior?
Both my workstation and personal computer runs mac OS X.
Here is the settings.xml(I have replaced real names with dummy ones)
<profiles>
<profile>
<id>dummy</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<dummy-groupId>com.mycompany.mydummy</dummy-groupId>
<dummy-name>my-java-ee-app</dummy-name>
<dummy-Mode>FALSE</dummy-Mode>
</properties>
<repositories>
<repository>
<id>mycompany Release Repository</id>
<name>central maven release repository</name>
<url>
http://maven1.mycompany.com:8080/myartifactories/repo
</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>mycompany Snapshot Repository</id>
<name>central maven snapshot repository</name>
<url>
http://maven1.mycompany.com:8080/myartifactories/repo
</url>
<releases>
<enabled>false</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>mycompany Release Plugin Repository</id>
<name>central maven release repository</name>
<url>
http://maven1.mycompany.com:8080/myartifactories/repo
</url>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
</pluginRepository>
<pluginRepository>
<id>mycompany Snapshot Plugin Repository</id>
<name>maven snapshot repository</name>
<url>
http://maven1.mycompany.com:8080/myartifactories/repo
</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
Error:
Could not resolve dependencies for project org.glassfish.javaeetutorial:roster-ejb:ejb:7.0.5: Failure to find org.glassfish.javaeetutorial:roster-common:jar:7.0.5 in http://maven1.mycompany.com:8080/myartifactories/repo was cached in the local repository, resolution will not be reattempted until the update interval of mycompany Release Repository has elapsed or updates are forced -> [Help 1]
EDIT:
I DO see the central repo in my effective pom:
Here is the condensed version of it
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>http://repo.maven.apache.org/maven2</url>
</repository>

Simplest solution is to configure a repository manager on your mac and configure the different repositories in the repository manager. Or you can use git to switch your ${HOME}/.m2/settings.xml to different state.
Update:
Create a git repository in ${HOME}/.m2/ via git init there
add an appropriate .gitignore file which contains a single line
repository. Checkin your settings.xml file. Create a branch
for example git co -b company make the appropriate changes for
your company and check in that state. Afterwards you can simply
switch by changing into the appropriate branch in git.
Setup Repository manager like Nexus (on your machine)
and configure there necessary repositories you need. If you working
on company site you can activate/deactivate the appropriate repository
via the UI of Nexus which means you have no change in your
settings.xml.
My preference is the local git repository which make life easier for me as well.

It seems your repo is cached locally and needs to be updated forcefully.
Try following to force the updates:
mvn clean install -U

I see in your error you have pasted:
"...was cached in the local repository, resolution will not be
reattempted until the update interval of mycompany".
so you want to delete this cache, i.e. to delete it from the local repo. Go to your local repo (usually .m2/...) and delete the "placeholder": go to directory org/glassfish/javaeetutorial/7.0.5 and there you should see roster-common.XXX cached - delete it.
If this keep happening, after you deleted the 'cached' from the repo, it means that maven cannot find it in any repo. So you have to re-check your repositories definitions. For example, why don't you have the "central" repo defined in your settings.xml (like all other repos)?

Related

Sonatype Nexus server on localhost doesn't cache artifacts

I have installed nexus-2.11 on my 64-bit localhost Windows. I am running mvn within build.xml in Eclipse via ant-tasks. I have set the nexus server in .m2/settings.xml as the main mirror:
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/nexus/content/groups/public/</url>
</mirror>
When running mvn commands, dependencies are resolved and it is shown in the log that they are being downloaded from the Nexus server. The problem is with the Nexus cache: Nexus does not cache anything. I mean the sonatype-work folder is empty and all artifacts are inside .m2.
Logging in the admin panel, I can see the complete index for artifacts, but no jar files or metadata are inside sonatype-work. (After downloading all artifacts, I want to put contents of sonatype-work into the main server which is offline because of security reasons.)
What may have caused this?
Did you insert something like this in the profiles section of your settings.xml?
<profile>
<id>company-nexus</id>
<repositories>
<repository>
<id>central</id>
<url>http://central</url> <!-- use a not existing URL!! -->
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
This causes maven to look in the mirror definition.
According to sonatype-work/README.txt, I set the environment variable PLEXUS_NEXUS_WORK to the path of sonatype-work and then, Nexus started caching into the work folder.
The location of the individual work folders may be overridden using environment variables. For example, the Nexus work location can be defined with PLEXUS_NEXUS_WORK. If it is not defined, then this default is used.

Getting "Missing Artifacts" while they are exist in .m2

In my setting.xml from .m2 folder, the following configs are applied to get jar files from local nexus repository:
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>central</mirrorOf>
<url>http://192.168.0.172:9090/nexus/content/groups/public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
In my pom.xml, an external repository declared to get jar files not presented in central repository:
<repositories>
<repository>
<id>spring-snasphot</id>
<url>https://repo.spring.io/snapshot</url>
</repository>
</repositories>
Despite of the fact that these so called "missing artifacts" are existed in their corresponding folder in .m2, but I always get
Missing artifact ....
What is wrong with my configurations?
Thanks in advance.
Finally I just figured it out. Having deleted files excluding jar file from corresponding folder, and then updating maven project solved the problem.
The configuration looks ok. But something must be going on...
If you delete those snapshot artifacts from your local repository and retry (for ex: mvn dependency:go-offline) do you see an attempt is made to download the artifact from https://repo.spring.io/snapshot ?
The additional repository seems to contain snapshots but the are not enabled for that repository. But I'm not sure whats the default. The artifacts may be not found because of the update policy. They are locally available but too old so maven tries to update them but fails (have you tried mvn -X ? that may give an indication what fails when resolving those artifacts).
What may be an option is to add the spring snapshots repo to your nexus (snapshot repo enabled) and set the mirrorOf in settings xml to <mirrorOf>*</mirrorOf>.
The mirror of central only might was intended so: just an experiment :)
It is always a good thing to verify the settings maven actually sees are the ones you think they are:
mvn help:effective-settings
mvn help:effective-pom

Why is Maven downloading from the wrong repository?

I'm a newbie to Maven. I'm trying to setup a local Archiva 1.3.6 server to act as a repository server for a project's internal artifact, as well as mirror to external repos. Things work fine except for snapshots. I'm using Maven version 3.0.5.
Here are the mirror settings in my settings.xml file
<mirrors>
<mirror>
<id>internal</id>
<mirrorOf>external:*</mirrorOf>
<name>My Maven Repository</name>
<url>http://my.repo.server:9000/archiva/repository/internal/</url>
</mirror>
</mirrors>
During the build, Maven tries to download the snapshot artifact from the wrong repository. I have 2 repositories set in the parent's parent pom.xml: internal and snapshots.
<repositories>
<repository>
<id>internal</id>
<url>http://my.repo.server:9000/archiva/repository/internal/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>snapshots</id>
<url>http://my.repo.server:9000/archiva/repository/snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
In the project's pom.xml I have the following dependency:
<dependency>
<groupId>com.mygroup</groupId>
<artifactId>metadata-framework</artifactId>
<version>1.0.3.SNAPSHOT</version>
</dependency>
During the build Maven tries to do this:
Downloading:
.../archiva/repository/**snapshots**/com/mygroup/metadata-framework/1.0.3.SNAPSHOT/maven-metadata.xml
Downloaded:
.../archiva/repository/**snapshots**/com/mygroup/metadata-framework/1.0.3.SNAPSHOT/maven-metadata.xml (795 B at 16.9 KB/sec)
Downloading:
.../archiva/repository/**internal**/com/mygroup/metadata-framework/1.0.3.20130908.081541-1/cems-metadata-framework-1.0.3.20130908.081541-1.pom
[WARNING] The POM for com.myground:metadata-framework:jar:1.0.3.20130908.081541-1 is missing, no dependen
cy information available
I verified the files in snapshot repo is correct, that it has properly generated maven-metadata.xml and etc. it appears that Maven downloaded the metadata correctly from snapshot repo, determined the right timestamped version, but somehow it decided to download the actual file from internal repo instead of snapshots, which lead to 404 and failed build.
I have no idea how Maven works, please help.
#lee - Here's how I download custom artifacts from an internal snapshots repo within Archiva. I use this config every day.
settingsl.xml:
Let's say I have a virtual repo named "help".
help is comprised of outside-facing repos and 2 internal-facing repos. Those 2 internal-facing repos are:
help-internal
help-snapshots
Under the <mirrors> section, I declare:
<mirror>
<id>help</id>
<mirrorOf>*, !help-snapshots</mirrorOf>
<name>The Help Repository</name>
<url>http://blah:8080/archiva/repository/help/</url>
</mirror>
Under the <servers> section, I declare:
<server>
<id>help</id>
<username>my_user_name</username>
<password>{my_encrypted_pwd}</password>
</server>
<server>
<id>help-snapshots</id>
<username>my_user_name</username>
<password>{my_encrypted_pwd}</password>
</server>
And now the final bit. In my projects' pom's that use in-house snapshots, I include this:
<repositories>
<repository>
<id>help-snapshots</id>
<url>http://blah:8080/archiva/repository/help-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
More concisely, and without modifying any pom.xml, you could define an all repository group in archiva which contains both internal and snapshots, and then add the following in your .m2/settings.xml:
<mirrors>
<mirror><id>myGroup</id><mirrorOf>*</mirrorOf>
<url>http://my.repo.server:9000/archiva/repository/all/</url>
</mirror>
</mirrors>
<profiles>
<profile><id>alwaysactive</id>
<activation><activeByDefault>true</activeByDefault></activation>
<repositories>
<repository><id>unused</id><url>unused</url></repository>
</repositories>
</profile>
<profiles>
I know this post is old by in order for maven to search in a snapshot repository the version should end with "-SNAPSHOT" (rather than ".SNAPSHOT")

Get dependencies from multiple repo's

Is it possible to download dependencies in maven using multiple plugin-repos?
I have my settings.xml configured to get dependencies from a custom repo and because of this, i am unable to get dependencies from the main maven repo server.
Is this possible to setup more then one plugin Repo?
Here is what i have setup so far for my custom repo:
</profiles>
<profile>
<id>custom-config</id>
<repositories>
<repository>
<id>custom-snapshots</id>
<name>customSnapshots</name>
<releases>
<enabled>false</enabled>
<updatePolicy>always</updatePolicy>
<checksumPolicy>warn</checksumPolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
<checksumPolicy>fail</checksumPolicy>
</snapshots>
<url>http:/custom/repo</url>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>custom-plugins</id>
<urlhttp:/custom/repo/public-snapshots</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
I have not included the dependencies here, but I am unable to pull and resolve some library dependencies.
The maven repo that I use is http://mvnrepository.com/ but I dont have details on the exact repo settings to use as the one I defined for a custom one.
The default maven repository is called "central". Its url is: http://repo1.maven.org/maven2/ or nowadays: http://repo.maven.apache.org/maven2/
But it is usually configured as mirrorOf. If you create a repository in your settings.xml and give it the id *central" it will replace it.
So I wonder why you can't resolve dependencies from there. Usually adding a repository in settings.xml does not turn of central.
could you execute mvn help:effective-settings and mvn help:effective-pom and have a loook at all repositories, profiles and mirrorOf elements in the xml? central should be there.
I would also recommend using a Maven proxy like Nexus or Artifactory. It simplifies a lot of things within a company.

Maven repository lookup order

We have an internal Apache Archiva based repository and we have configured the repositories tag in pom.xml to be as follows. Can I assume that all dependency access will get resolved by internal repository if you have access to it and will get resolved by other repositories listed below, if internal repository is down for a certain reason.
<repositories>
<repository>
<id>internal</id>
<name>Internal Repository</name>
<url>http://192.168.1.2/archiva/repository/internal</url>
</repository>
<repository>
<id>jboss</id>
<url>https://repository.jboss.org/nexus/content/repositories/releases</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
....
</repositories>
EDIT:
I want to do away with the .m2/settings.xml file. I want to define this in my pom.xml file, so that if my repository manager is UP and running I would want the runtime to connect there, else would want to fallback into the other repositories. Would this be possible?
Maven 3.0 had it fixed as you can see in Maven developer's Jira below. The lookup will be done in the order they are declared.
https://issues.apache.org/jira/browse/MNG-4400

Resources