Maven looks for jar that isn't present in the repository - maven

I have a repository set up on Artifactory for my Maven projects. I have declared this repo in the <repositories> tag of my settings.xml for one of the projects, I have created a dependency on some other prooject (Say projectA) in my POM for a snapshot version. For this projectA, there is only POM artifact on the Artifactory and not a jar. Still when I compile my POM, Maven tries to download the jar for this project and fails saying it couldn't find it.
I shall paste the exact POM, error, settings.xml and repo view soon. Any idea what could be wrong?

If you would like to have a dependency of pom type, you need to explicitly declare it. For example:
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>my-artifact</artifactId>
<version>1.0</version>
<type>pom</type>
</dependency>
If type is not specified, Maven would use the default value which is jar.
Edit from OP: Just a caution, I use IntelliJ and even though I had the settings right in place, it was using some old (probably cached) settings.xml. I ran from commandline and it picked up the right one.

Related

How to cache specific maven artifact into local repository?

Suppose I have some Maven coordinates, like
org.ow2.asm:asm:5.0.3
How would I cache these artifact into (existing) local maven repository?
I believe this truly answers your question: it shows how to download and cache locally a specific Maven artifact from specific Maven repository with all dependencies without having to create pom.xml or any other sort of dependency declaration.
In your pom.xml add under <dependencies> the following :
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>5.0.3</version>
</dependency>
and use the command
mvn clean verify
at your project level to build the project and its dependencies to find the artifact in the corresponding .m2/repository folder.

How to add dependencies to pom.xml in IntelliJ 14

I have a few dependencies in Project Structure/Libraries in IntelliJ 14. How can I add them to my maven pom.xml? There is one single tutorial on IntelliJ's website that does not work for me. I don't want to manage them manually.
The proper way to do this would be to install the dependency artifacts (most likely jars) into your local maven repo, like this.
How to install artifacts to your local maven repo
And then add the dependencies into your pom.xml
<dependencies>
<dependency>
<groupId>com.something</groupId>
<artifactId>artifact</artifactId>
<version>1.2.3</version>
</dependency>
</dependencies>
Yes, this does require going through each artifact manually, one at a time, but it's a one time setup process.
That is the "proper" way. After that, you can do away with library dependencies in your project structure (they will be picked up correctly via maven).
There is the alternative possibility to "hack" in your project libraries path as a sort of "embedded" maven repo in your project, but that's a little bit hacky and I wouldn't advise that.

Does maven automatically download artifact dependencies?

I've been working with Maven for a little while now and I had a question about the information shown on the Maven Repository site. I was looking at the tags to paste into my pom for spring-web-mvc 3.2.8.RELEASE and noticed the table with the header "this artifact depends on" and saw the host of artifacts listed below.
My question is simple: Am I supposed to include the all of the dependencies listed in that table in my pom?
To answer your question, no you do not need to include all of the dependencies listed in the artifact dependencies section. It is my understanding that when you include a dependency in your pom file, maven will automatically download any needed jars. I am inferring this due to the fact that I personally don't add any of the artifact's dependencies other than what I need to my pom.
For example if I wanted spring-core I would do the following:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.2.8.RELEASE</version>
</dependency>
And maven will automatically take care of the dependencies for me.
A good way to test this out is to open a new maven project in eclipse and specify a dependency such as this, update the project, and then check in the Maven dependencies folder.
For fun, I experimented with this and it is indeed true, Maven will download any necessary dependencies when you update your project. After putting only the above dependency in my pom.xml file I got the following:
No need to download all those.
Maven will take care of all the artifact's dependencies for the specified dependency mentioned in pom file.

about generate maven dependency

I am pretty new to maven.
Now I have a maven project developed. My another project needs to depend on this one.
Does anyone know how can I generate my own dependency? So that my second project can add the first one as a dependency in pom.
thank you very much
Since your first project is already a maven-project, just install it in your local repository by running mvn install in the first project's root directory.
Then you can include a dependency in your second project by simply referencing the groupId, artifactId and version you defined in the first project.
So if your first project had the following in its pom:
<project>
<groupId>com.yourdomain</groupId>
<artifactId>yourcomponent</artifactId>
<version>1.0</version>
... <!-- more here -->
you can include this in your second project:
<dependencies>
<dependency>
<groupId>com.yourdomain</groupId>
<artifactId>yourcomponent</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
Unless you deploy your project 1 jar to a central maven repository, this will only work if your jar is in your local repository (via mvn install).
Maven projects are identified by the "Maven coordinates", that is, the ArtifactID, GroupID and version.
Say you create your first project and run maven install. Your local repository (in $HOME/.m2/) will now contain the compiled project plus whatever coordinates you put in there.
Your second project must now only depend on the said coordinates.
I would suggest googling a bit on maven. I made a tutorial a long time ago that might help you, even if the examples are a little simple. Here you go and good luck!

Maven - Unable to resolve dependencies

Im trying to compile a Maven project. The compile fails however due to a "Failure to find xx.xxx.jar" in the repository i have specified in my settings.xml. I have access to this repository and when i navigate to the Url of the repository maven is trying to use i can see a pom file with the name of the jar but no jar. When i open the pom it contains the correct groupid and artificatid and jar name however the jar is not in the same directory.
Maven gives another error saying that "resolution will not be reattempted until the update interval of my repo-server has elasped or updated are forced".
What is happening here?
When maven goes to the repo i specify in settings.xml and finds a pom for the jar does it then try and go out to some external site to resolve the dependency or should the jar exist in the same folder as the pom?
What module are you attempting to download?
I discovered something similar with the following Maven central module:
http://search.maven.org/#artifactdetails|net.sf.json-lib|json-lib|2.4|jar
The Maven POM packaging declaration was jar, but no jar in Maven called "json-lib-2.4.jar"
When I looked at the files actually stored, I discovered that the author is providing two versions of the jar, each compiled for different versions of the JVM:
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk13</classifier>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>

Resources