I created a sample project A and pushed it to my jfrog artifactory. Now, I want to use this in another maven project B.
To achieve this, I added this dependency declaration (copied from jfrog) in B's pom.xml:
<dependencies>
<dependency>
<groupId>com.testartifactory.example</groupId>
<artifactId>testartifactory</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>testartifactory</id>
<name>com.testartifactory.example</name>
<url>https://myjfrogurl/artifactory/libs-release-local/com/testartifactory/example/testartifactory/</url>
</repository>
</repositories>
But when I import this import com.testartifactory.example;, I get error that package com.testartifactory does not exist.
Even though I can see the project downloaded in repositories under .m2 folder:
Here is how my project A is structured:
I am new to this so I may be doing something wrong and would appreciate any help.
The repository URL should correspond to the repository in JFrog Artifactory. In your case: https://myjfrogurl/artifactory/libs-release-local
In the pom.xml:
<repositories>
<repository>
<id>testartifactory</id>
<name>com.testartifactory.example</name>
<url>https://myjfrogurl/artifactory/libs-release-local</url>
</repository>
</repositories>
Other options to use Artifactory for Maven builds are to use the Artifactory Maven plugin or the JFrog CLI. With these integrations, you'll get some more benefits such as build-info, Xray scanning, better performance and more.
Read more about Maven and Artifactory:
Maven Repositories in JFrog Artifactory
QuickStart Guide: Maven and Gradle
Running Maven Builds using the JFrog CLI
Related
I want to use a package named sourcemap in my project. It's not available in maven central, but in Atlassian's public maven repository. I therefore set up my pom.xml like this:
<repositories>
<repository>
<id>atlassian</id>
<name>Atlassian</name>
<url>https://packages.atlassian.com/content/repositories/atlassian-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.atlassian.sourcemap</groupId>
<artifactId>sourcemap</artifactId>
<version>1.7.7</version>
</dependency>
</dependencies>
Now, the POM file for sourcemap references another POM file from a package named public-pom:
<!-- POM for sourcemap (NOT my pom.xml!) -->
<parent>
<groupId>com.atlassian.pom</groupId>
<artifactId>public-pom</artifactId>
<version>3.0.84</version>
</parent>
The problem: the POM file references version 3.0.84 of public-pom, but Atlassian's repo no longer provides 3.0.84. Currently, the oldest available version of public-pom is 5.0.0, as you can see here. Because of this, maven complains when I attempt to build the project:
Could not find artifact com.atlassian.pom:public-pom:pom:3.0.84 in atlassian (https://packages.atlassian.com/content/repositories/atlassian-public/)
How can I fix the POM and use this package in my project?
Mvnrepository lists com.atlassian.pom:public-pom:pom:3.0.84 but when selecting the link to it:
status: 404
message: "Could not find resource"
I have a maven project in bitbucket account. I need to add that the project in my local maven repository so that I can refer that project as a maven dependency in my main project's pom.xml.
That is, perform below steps
1) Clone the project
2) run maven build install This will add to local maven repository
Please let me know if there is a way to achieve the same (in similar ways to connecting to maven public repository) ?
You can achieve this by defining repositories in pom file of the project where you want to use project 1 as a dependency.
For eg.
Git clone path of Project 1: https://github.com/yogi21jan/project1
Add below code in child project:
<repositories>
<repository>
<id>YOUR-PROJECT-NAME-mvn-repo</id>
<url>https://raw.github.com/YOUR-USERNAME/YOUR-PROJECT-NAME/mvn-repo/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>always</updatePolicy>
</snapshots>
</repository>
</repositories>
And finally Add this project as a dependency:
<dependency>
<groupId>group id of project 1</groupId>
<artifactId>artifcat id of project 1</artifactId>
<version>required version</version>
</dependency>
Look into jitpack.io. It can create a Maven repository for a GitHub project and also other hosters like BitBucket, GitLab, Azure, Gitee.
I have choosen a random Maven based project,
here fastconverter. It not GitHub is used, the full URL has to be provided. The created jar is published then here.
I am using maven to add dependency. I added
<!-- https://mvnrepository.com/artifact/org.jboss.seam/jboss-seam -->
<dependency>
<groupId>org.jboss.seam</groupId>
<artifactId>jboss-seam</artifactId>
<version>2.3.5.Final-redhat-1</version>
</dependency>
jboss-seam jar by using above lines in pom.xml. When I run mvn clean install it gives an error
What is the issue and how to solve this error?
Try adding the below repository in your pom file,
<repositories>
<repository>
<id>redhat</id>
<url>https://maven.repository.redhat.com/ga/</url>
</repository>
</repositories>
The artifact is not available in maven central repository. Its available only in redhat-ga repository.
I am trying add this dependency in my pom.xml, but maven is not able to resolve the dependency for the same.
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>4.3.4.RELEASE</version>
</dependency>
I was working on my other computer some weeks ago. I switched my laptop, and trying to setup this project, but it's not working anymore.
Error:
Missing artifact org.springframework:spring-test:jar:4.3.4.RELEASE
I see this this is available in the maven central.
http://search.maven.org/#artifactdetails%7Corg.springframework%7Cspring-test%7C4.3.4.RELEASE%7Cjar
Does anybody have any idea why is it happening?
Thank you #Reek for the comment.
I added spring repository url in my pom.xml and it started working.
<repository>
<id>repository.spring.release</id>
<name>Spring GA Repository</name>
<url>http://repo.spring.io/release</url>
</repository>
You do not need to add spring specific repository to use those artifacts.
Maven works as follows:
Firstly Maven tries to find artifact in the local repository.
Otherwise Maven tries to download artifacts from http://repo1.maven.org/maven2/ by default.
If you wanna build your project on another computer for the first time than there is no local repository at the moment. There are two possible reasons for Error on the second stage:
Maven central repository is unavailable from another computer: check this URL.
Mirror of Maven central is misconfigured in settings.xml like this:
<mirrors>
<mirror>
<id>central-proxy</id>
<name>Proxy of Maven Central</name>
<url>http://some/invalid/url/here</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
Detailed logs are required.
When work in STS (springsource tool suite), open pom.xml file and check dependencies in "dependencies tab", add/select maven dependency will give 0 result found. We need edit pom.xml to add dependency by hand. Is there a way to let M2E know where to check repository to search dependency?
M2e by default searches maven central repository for artifacts. It downloads an index file which has artifact details. You can configure additional repositories to be searched by specifying the same in repository section of your settings.xml file. Do note that some repositories do not have this index file.
By default , all pom.xml will automatically extend the Super POM , which is located in the maven_installation_folder/lib/maven-x.x.x-uber.jar ==> package org.apache.maven.project ==> pom-4.0.0.xml . All the configuration specified in the Super POM is inherited by the POMs you created for your projects.
If you open pom-4.0.0.xml , you will find that the maven central repository http://repo1.maven.org/maven2/ is defined here . That means if you specify a <dependency> in your pom.xml , maven will try to download this dependency in the following orders:
Maven local repository (i.e your local hard disk)
Maven central repository specifed in the Super POM (i.e http://repo1.maven.org/maven2/)
Maven remote repository (Defined in the <repository> section of your pom.xml )
Normally , I will use some maven repository search engines , such as this , to find out the <dependency> of the libraries /frameworks /tools that I want to use and then paste them in the pom.xml
If the dependency exists in the Maven central repository , everything will be fine and it will be download to your local repository . However , if some of the <dependency> (eg Hibernate) cannot be found and downloaded from the Maven central repository , you can try to visit its official site to find out its repository link and paste them in the <repository> section of your pom.xml .For example , Hibernate require to define the jboss repository in the pom.xml like this:
<repositories>
<repository>
<id>repository.jboss.org</id>
<name>JBoss Repository</name>
<url>http://repository.jboss.org/nexus/content/groups/public-jboss</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
You can refer to this for the use of <repository>