How to manage maven depend project from Artifactory? - maven

Inside a Parent project i have multiple project and take this simple example Project common-3rdparty used as a depend project for Project B and in Project B pom.xml file i have added below lines
<dependencies>
<dependency>
<groupId>com.pre.cdd.common</groupId>
<artifactId>common-3rdparty</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
</dependency>
</dependencies>
Now i am using Artifactory for dependency management and added common-3rdparty project into Artifactory but now when i am running mvn eclipse:eclipse project build successful but common-3rdparty.jar not downloaded so Project B giving exception
common-3rdparty.jar missing
So it mean somehow common-3rdparty.jar not downloaded from Artifactory . What i am doing wrong here?
EDIT:-
Now my simple question is that if i have 10 project and 9 project needed to run 10th one so we added 9 dependencies in 10th project pom.xml now what changes i have to do in Artifactory side or pom file so it will easily get depended projects.

The remote-repos contain only the remote repositories (hence the name). If you deployed the jar into Artifactory yourself, it resides in one of the local repositories, that's why maven can't find it. You should use lib-releses instead of remote-repos in your maven configuration.

Related

Intellij Spring maven install error "package does not exist"

Intellij version : Community 2019.2.3
Maven : 3.6.2
Spring : 2.2.0
I am trying to create a very simple Spring maven project with two sub-modules (one independent and another one dependent on independent one).
Root module - testmultimodule
Independent module - independent
Dependent module - dependent
testmultimodule pom.xml has all Spring related declaration and module definition
<modules>
<module>independent</module>
<module>dependant</module>
</modules>
Independent poom.xml is simplest and . only has parent maven declaration
<parent>
<artifactId>testmultimodule</artifactId>
<groupId>in.org.app</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
dependent module pom.xml has the dependency declaration as below to independent module
<dependencies>
<dependency>
<groupId>in.org.app</groupId>
<artifactId>independent</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
I have created a Test class under dependent module and using a User object from independent module. Initially, without the above dependency declaration, asa usual there was compilcation error.
As soon as I add the dependency and builld the project within Intellij IDE with the option "Build Prooject" option from "Build" menu, it successfully builds.
However, if I try to use Maven install option within Intellij right side window option. It always fails stating Error:(3,33) java: package in.org.app.independent.bo does not exist .
I am providing the GitHub URL for the test project , if you want to take a look and test by yourself.
GIT URL:
https://github.com/DhruboB/testmultimodule
I have tried all sort of tweaking found in internet so far e.g.
clearing Intellij Cache & restarting, mvn -U clean install, mvn scope verification, proxy etc.
Any further idea to resolve this? I need to solve this in the Community version of Intellij.
Your parent project includes the definition for the spring-boot-maven-plugin. This leads to each project defining this as a parent to be repacked to an executable JAR by this plugin. This repackaged JAR isn't useable as a dependency in another project.
Either you need to change the configuration of the spring-boot-maven-plugin for the project you want to use as a dependency. This is explained here in the Spring Boot Reference Guide. You now basically have 2 jars from this project, one plain and one executable.
If you don't need that project to be an executable JAR file then just move the spring-boot-maven-plugin to the project that needs to be. All other projects will no be basic JAR files again.
See also How to add a dependency to a Spring Boot Jar in another project?

How to fix The POM for XXX:jar:1.0 is missing, no dependency information available

We tried to build our project(Spring Boot 2.0.3 with Maven 3.3.9 dependency management)Jenkins Tool(Linux environment).Its saying build failure showing the following message in console "The POM for org.actus:ACTUS-Core-1.0:jar:1.0 is missing, no dependency information available".ACTUS is our custom java library developed by us and its in the local repository also.
This is the first time we started using Jenkins Tool. There are some other modules which depends on this same ACTUS jar.Those are also failing.I have searched for solution on internet.Some people said,make changes to settings.xml file.But in our development machine ,we cant find any such type of settings.xml file(in .m2)
remaining all dependencies are normal spring boot dependencies only.This is the only one external or custom jar.Using mvn install, we kept in maven local repo.
<dependency>
<groupId>org.actus</groupId>
<artifactId>ACTUS-Core-1.0</artifactId>
<version>1.0</version>
</dependency>
I will try to explain as much I can to solve your problem. I hope you are looking for settings.xml to update your maven Nexus repository. If you don't know about nexus repository, it's kind of public repo where you will get all open source dependency.
In your case, from your organization, you should have a private nexus repository and upload ACTUS-Core jar to there.
Then update your settings.xml file to use your company nexus repository. (Please check comments, it will be available in M2_HOME location)
So while you execute mvn install automatically it will upload in your private repository.
Now, in your pom.xml mention the same nexus repository. (It's optional)
Then, in your Jenkins script, you have updated this nexus repo.
So, the key point is you should have your own repo to upload ACTUS-Core jar and need to access the same while you building in Jenkin tool.
OR ELSE
If you find all the above activities in pain / not possible then I can suggest a short cut solution.
Create a lib folder under your project name ( same hierarchy as src) then add your ACTUS-Core.jar and commit that file along with your source code.
Then, update your pom file like below. It will work.
<dependency>
<groupId>com.test</groupId>
<artifactId>test</artifactId>
<version>11.1</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/fileName.jar</systemPath>
</dependency>

Cannot resolve the SNAPSHOT dependency deployed via Maven deploy-file

I have a problem with Nexus dependency resolution. Nexus version is 3.13.
I have a project "A" which is used as a library across different projects.
I am trying to create
- SNAPSHOT versions to be used for DEV environment
- RELEASE versions will be used after code freeze and to deploy other environments.
I deploy the project "A" as a snapshot to a maven hosted repository(jar file, snapshot repository). I tried "deploy plugin" 3.0.0-M1 and 2.8.2 with uniqueVersion=false. But every time a timestamp is added to the artefacts in Nexus(jar and POM files). I have no issue with timestamp but I cannot resolve the project from other projects.
When I use "LATEST" as the version then the following is the response
"The POM for filename:jar:X.Y.Z-SNAPSHOT is missing, no dependency information available". The POM and JAR is in the repository, but the POM file contains the timestamp suffix as well.
I don't have any problems with release repository for the same project.
Any idea?
Edit :
I used uniqueVersion only for version 2.8.2, for the others there is already an error(or warning).
To deploy project "A", I use the following maven command
mvn deploy:deploy-file -Dfile=target/my-library-0.0.X-SNAPSHOT.jar -DpomFile=pom.xml -DrepositoryId=nexus -Durl=http://my-ip-address/repository/my-library-snapshots.
The POM contained almost nothing actually the usual IDs and a dependency to Lombok.
From the project B, I use only the following
<dependency>
<groupId>Some Group IDs</groupId>
<artifactId>my-library</artifactId>
<version>LATEST</version>
</dependency>
Instead of LATEST, I also tried expilicitly giving version number in nexus.
I found the issue. It was related to my settings.xml file. I added another element under "profile" element called "id"
<profiles>
<profile>
<id>nexus</id>

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.

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!

Resources