maven cannot find dependencies even in local repository - maven

I have just moved to a new machine and installed a new maven (version 3) but it keeps complaining about project dependencies even though I can see them in the repository myself and all the repository declarations in pom.xml are correct. i can paste their url in the browser and they resolve fine. Some are even in the .m2 folder.
most of the ones it complain about are those from jboss
<repository>
<id>jboss-repository</id>
<name>Jboss Repository</name>
<url>https://repository.jboss.org/nexus/content/groups/public/</url>
</repository>
any ideas?
Tx

Looks like the URL is not correct. It should be
http://repository.jboss.org/nexus/content/groups/public/

Related

Changing nexus servers: Maven deploy still deploys to old server

I have copied all contents from an old Nexus server to a new server. I am able to login to the new server, see all the uploaded artifacts, etc.
On the Jenkins build master, the maven builds are running obviously as the jenkins user. The home directory for that user is /var/lib/jenkins. Under there, I have copied the .m2 folder and changed all the old URL's in the settings.xml to point to the new URL.
However, when I run a maven deploy, while the build downloads some dependencies from the new nexus server, at the end of the build comes the mvn-deploy plugin and that tries to upload to the old server.
Do the artifacts, war, jar files have a record of the nexus server? Is there some setting in Jenkins that I'm missing? I did a grep for the old nexus address in /var/lib/jenkins folder and none of the config xml's have any mention of the old nexus.
Is the URL hardcoded in your pom? Maybe the pom is not using the params you set in the settings.xml?
The repositories configured in the settings.xml are the source of Maven artifacts. The destination for new artifacts is in the distributionManagement block. This is usually somewhere in your POM, or in a parent POM. The block will look something like the below. Chances are, the old URL is there.
<distributionManagement>
<repository>
<id>releases</id>
<name>Release Repository</name>
<url>${repository.url}/nexus/content/repositories/releases</url>
<layout>default</layout>
<uniqueVersion>true</uniqueVersion>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Snapshot Repository</name>
<url>${repository.url}/nexus/content/repositories/snapshots</url>
<layout>default</layout>
<uniqueVersion>true</uniqueVersion>
</snapshotRepository>
</distributionManagement>

Setup AEM Adobe CQ5 6.1 project to build/install offline

I'm new to CQ5 and looking for steps/settings I may need to do to setup an AEM adobe CQ5 6.1 project to build/install offline (not connected to internet).
I've to use our internal network Nexus (which has lot of general dependencies available except AEM related).
I've to use Maven & Java7.
Looking for possible issues/resolutions, steps & any helpful info.
Thanks all for your inputs.
After a detailed investigation, this is now resolved. Just want to share the findings so that it may help others.
The content-package-maven-plugin which was uploaded to our local nexus got corrupted.
Interestingly maven was not throwing any errors when i was trying mvn install command on my AEM project. Rather it was giving NoClassDefFound error for a further dependency of content-package-maven-plugin.
From the output of, mvn dependency:resolve-plugins, it was confirmed that the dependencies are not fully resolved for particular this plugin JAR, I tried to manually download the artifact from nexus & try to open/unjar it.
The artifact pom was corrupted and hence I uploaded the fresh artifact in nexus, and this time all went smooth.
My AEM project is now building fine with local nexus dependencies.
a typical AEM project does have lots of dependencies. There are some dependencies for the AEM platform(including granite, sling, osgi etc). These dependencies are downloaded from the adobe public repositories, unless you have a nexus repository in your company where all these dependencies are available.
If your Organization specific Nexus repository can connect to internet and download dependencies (AEM and non AEM related) atleast for the first time , then you do not need to connect to internet from your local sand box.
Theoretically, your organization specific nexus repo also might not be
connected to the internet and all the JARs can be uploaded to Nexus
manually. But, that would be the last thing I will do in my life !
Your project can download all the dependencies from the Nexus repo(only) in multiple ways.
Configure the repository configuration in your pom.xml file to point
to your internal Nexus repo.
<repositories>
<repository>
<id>internal</id>
<name>Internal Public Repository</name>
<url>URL to the public repository of your internal nexus</url>
<layout>default</layout>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>internal</id>
<name>Internal Public Repository</name>
<url>URL to the public repository of your internal nexus</url>
<layout>default</layout>
</pluginRepository>
</pluginRepositories>
Change your Maven settings (settings.xml) to use your internal Nexus
every time it downloads dependencies (Recommened).
settings.xml can be found in your <user>/.m2 directory or <maven-installation>/conf
<mirrors>
<mirror>
<id>public</id>
<mirrorOf>*</mirrorOf>
<url>URL to the public repository of your internal nexus</url>
</mirror>
</mirrors>

Maven: Manually install a Jar from local folder and then go online and grab & install all its dependencies

In my project's pom file I have a dependency that I can see in Maven central repository, javax.enterprise:cdi-api:jar:1.0-SP4 but for some reason I am getting on some of my computers the following error while building the project (hence the build fails):
[INFO] Unable to find resource 'javax.enterprise:cdi-api:jar:1.0-SP4' in repository central (http://repo1.maven.org/maven2)
Any idea why I get this error only on some of my computers (I can say all the computers are using the same network)?
Why do I get this error at all? As far as I can see the jar IS in the maven central repository.
Even though maven could not locate/download the jar on some of the computers, I was able to download it manually through the browser on these computers. How could it be?
Okay, so I've downloaded the jar manually through the browser at one of the problematic computers. I want to install it manually to the local repository on this computer. So from the command line I do:
mvn install:install-file -DgroupId=javax.enterprise -DartifactId=cdi-api -Dversion=1.0-SP4 -Dpackaging=jar -Dfile=path/to/file
...but none of its dependencies has been downloaded as well. Is there some maven plugin to install the file to the local repository AND download & install all its dependencies to the local repository?
If so, please show me how to use it.
Please check in the computers where the jar are not downloaded if the settings.xml file present in .m2 folder is having the url of the jar needed. If not add them.
You are not able to download because maven searches in the urls defined in the settings.xml file only. So if the url is not present there, even if the jar is in the central repository it wont be downloaded.
In your browser you can navigate to that link and download. Maven wont be able to do it for the reason given in the second point
Ok, looks like you need to mention your repository path in your pom file, What is the url of the repository? is it local to your network or some open url? for example: http://repo2.mvn.org/???
Sample example would be like this::
<repositories>
<repository>
<id>codehausSnapshots</id>
<name>Codehaus Snapshots</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://snapshots.maven.codehaus.org/maven2</url>
<layout>default</layout>
</repository>
</repositories>
If you could paste the pom file, it would be easier to help you.
To answer your 3 point: Check the settings.xml file in .m2\settings.xml, make sure that same content is present. Sometimes settings.xml are modified directly in maven installation directory. so you better check in that location also.
To Answer your 4th point: mvn install:install installs (in simple terms copies) an artifact (jar/ear/zip/any artifact that meant for distribution) into maven local repository or into remote repository. So in your command, you just tried to install only cdi-api jar.
Whenever you run mvn compile, mvn package, mvn install, maven will scan your pom file and downloads all dependency mentioned into your local repository. I would suggest you to look your local repository and see how is it creating directory structure.

Should I write repositories in my pom.xml?

I am new to Maven. If I start new project with Maven, should I know any repository URLs for it to work?
For example, this Hibernate tutorial http://docs.jboss.org/hibernate/core/3.3/reference/en/html/tutorial.html says about how to create a sample project with pom.xml text. But this pom.xml does not contain any repositories.
So, my m2eclipse plugin says, for example Project build error: 'dependencies.dependency.version' for org.hibernate:hibernate-core:jar is missing., for all dependency tag in pom.xml
Is this because of repositories absence?
Where to know repositories URLs? Is there one big repository? Why doesn't it included by default?
UPDATE 1
It is said here, that Maven should use "central" repository by default: http://maven.apache.org/guides/introduction/introduction-to-repositories.html
I have searched there for hibernate-code artifact and found it. So, this artifact IS in central repository. By my maven says dependency not found. Hence it doesn't use it's central repository. Why?
Apparently your Hibernate dependency is missing <version> tag:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.6.9.Final</version> <!-- this line is missing -->
</dependency>
Note that you don't have to specify version of dependencies previously declared in <dependencyManagement>.
Old answer:
Every build script (not only with Maven) should be reproducible and independent from environment. Standard pom.xml (called super pom), which every pom.xml inherits from, already defines main Maven central repository:
<repositories>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>https://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
You don't have to define this repository, and you don't have to define any others if all your dependencies are there. On the other hand if you are using some external repositories, you must add them to pom.xml, so that every developer is always able to build.
The bottom line is: if you can build the project having a completely empty repository, your pom.xml is fine.
It's not advisable to define repositories in POM files as that causes a lot of issues (Maven will search those repositories for ANY artifact even the ones available at Central, poor portability, ...)
Best approach: Setup a repository manager (Artifactory, Nexus) and edit your settings.xml file to use the repo manager as a mirror.
Second best approach: Define the required repositories in your settings.xml file, not in your pom.xml files.
Repositories in poms is a bad idea.

getting maven to use repository for one library only

i have a repository setup like this
<repository>
<id>jboss</id>
<name>JBoss Repository for Maven</name>
<url>https://repository.jboss.org/nexus/content/groups/public/</url>
</repository>
<repository>
<id>itextpdf.com</id>
<name>Maven Repository for iText</name>
<url>http://maven.itextpdf.com/</url>
</repository>
how do i set up the dependency to use the itext repository only for itext and jboss for everything else. for some reason the dependencies are being downloaded by both and one of them that is in the itext repository is different than the jboss and is crashing my system.
You shouldn't need to do this if the artifact only exists in one of the repositories (maven will try each repository in order and will stop once it finds it). The itext repo doesn't have any of the jboss jars so listing it first should result in it being checked first (and when it fails to resolve the jboss jars, it'll try the jboss repo).
Alternatively, if you have your own Maven repository server (Nexus, for instance), acting as a proxy for the public maven repositories, you can set up a "Repository Routing" in which you tell it which repositories to search for specific artifacts (based on group ID).

Resources