For example, let's say I have a Maven build file that has dependencies located in two different repositories:
<repository>
<id>id1</id>
<name>id1</name>
<url>http://localhost/mavenRepo/repository1</url>
</repository>
<repository>
<id>id2</id>
<name>id2</name>
<url>http://localhost/mavenRepo/repository2</url>
</repository>
With one dependencies from the first repository and the other from the second repository. How can I do this?
Just list all the dependencies in your <dependencies> section, and Maven will contact each repository in turn (including your local repository) to find them.
A POM file has no concept of "get these dependencies from this repository and get these dependencies from that repository".
How can you do what? What is the problem? Just add the dependencies and Maven will try to resolve them from central repository and then fallback on the next declared repository if not found and so on.
Related
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
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'm having an issue adding a maven dependency, it's for a Twitter API dependency but I'll try and keep the question as generic as possible.
The dependency is located onthe maven site here
It states that the repo is here:
Note: this artifact it located at Spring Plugins repository (http://repo.spring.io/plugins-release/)
So I have created a pom with the specified dependency and repo:
<repositories>
<repository>
<id>maven_twitter</id>
<name>twitter</name>
<url>http://repo.spring.io/plugins-release/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.twitter.sdk.android</groupId>
<artifactId>twitter</artifactId>
<version>3.1.1</version>
</dependency>
</dependencies>
The repository ID and Name weren't given so I've given them a suitable name - is this wrong?
The error received is:
[ERROR] Failed to execute goal on project java: Could not resolve dependencies for project com.project.java:java:jar:0.0.1-SNAPSHOT: The following artifacts could not be resolved: com.twitter.sdk.android:tweet-composer:jar:3.1.1, com.twitter.sdk.android:twitter-core:jar:3.1.1, com.twitter.sdk.android:twitter:jar:3.1.1, com.twitter.sdk.android:tweet-ui:jar:3.1.1, com.android.support:support-v4:jar:23.1.1, com.android.support:recyclerview-v7:jar:23.1.1: Could not find artifact com.twitter.sdk.android:tweet-composer:jar:3.1.1 in maven_twitter (http://repo.spring.io/plugins-release/) -> [Help 1]
So my question is: is simply adding the repo and dependency details of the Maven site enough? Am I missing something?
When trying to use
compile 'com.turn:ttorrent:1.4'
I get unresolved dependency net.sf.jargs.
POM of ttorent contains URL for external Maven repository:
<repositories>
<repository>
<id>jboss-thirdparty-releases</id>
<name>JBoss Thirdparty Releases</name>
<url>https://repository.jboss.org/nexus/content/repositories/thirdparty-releases/</url>
</repository>
</repositories>
So adding that URL as repository explicitly solves that problem, but it is not Jedi way?
Can I say something to Gradle to make it doing such things implicitly?
Having repository declarations in published Maven POMs is discouraged, and Gradle will not honor them when resolving.
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>