Could not transfer artifact - not authorized - maven

I want to use an artifact "eu.excitementproject:lap:jar:1.1.0:" from the following repository:
http://hlt-services4.fbk.eu:8080/artifactory/repo/eu/excitementproject
I can download the jar directly from the above link without any authorization.
However, when I mvn install on my computer, I get the following error:
Could not transfer artifact eu.excitementproject:lap:pom:1.1.0 from/to excitement
(http://hlt-services4.fbk.eu:8080/artifactory/repo/eu/excitementproject):
Not authorized
Here is the relevant part of my pom.xml:
<repositories>
<repository>
<id>excitement</id>
<name>excitement</name>
<url>http://hlt-services4.fbk.eu:8080/artifactory/repo/eu/excitementproject</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>eu.excitementproject</groupId>
<artifactId>lap</artifactId>
<version>1.1.0</version>
</dependency>
</dependencies>
What should I do?

Your Maven configuration is:
repository URL - http://hlt-services4.fbk.eu:8080/artifactory/repo/eu/excitementproject
group-id - eu.excitementproject
artifact-id - lap
artifact-version - 1.1.1.
The full path to the artifact is therefore http://hlt-services4.fbk.eu:8080/artifactory/repo/eu/excitementproject/eu.excitementproject/lap/1.1.1/lap-1.1.1.pom.
If I hit this URL from any web browser, I am asked to authenticate using basic HTTP authentication. This is exactly what Maven also sees. Therefore, as #Will mentioned above, if you wish to continue using this repository URL, you will have to configure authentication settings for the repository in your local settings.xml.
Interestingly, I can hit http://hlt-services4.fbk.eu:8080/artifactory/repo/eu.excitementproject/lap/1.1.1/lap-1.1.1.pom without problems. So, if you shorten your repository URL to http://hlt-services4.fbk.eu:8080/artifactory/repo, your build will work (I have tested this).

you can provide credentials to your artifactory using basic url authentification(https://developer.mozilla.org/en-US/docs/Web/HTTP/Basic_access_authentication).
In your case repository url should be:
http://USERNAME:PASSWORD#hlt-services4.fbk.eu:8080/artifactory/repo/eu/excitementproject

Related

How to ensure that maven passes credentials when redirecting?

I have a Java repository whose url is, say a. Access to this repository requires authentication, which is provided by the credentials stored in maven's setting.xml file (~/.m2/settings.xml). When I specify this url in pom.xml for maven's repository, everything works as expected.
<repositories>
<repository>
<id>my-internal-site</id>
<url>a</url>
</repository>
</repositories>
I also have a url, b, which redirects to a. More specifically, b returns a 302 HTTP response. Now, when I specify b in pom.xml as the repository url, it returns a 400 Authentication Error, which most likely means that the Authentication parameters are missing. So my hypothesis is that maven does not send the authentication details from settings.xml to a on redirection. Is there a way I can enable that? Or is there a fix for this?

Specifying the maven repository URL for getting the dependencies resolved?

I am trying to understand how maven downloads the binaries from the repositories.
For example, I have the following dependency for my project:
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-hdfs</artifactId>
<version>2.7.1</version>
</dependency>
Now, these binaries are present in http://mvnrepository.com/.
In pom.xml, we have <repositories> tag where we specify the repository URL from where maven can download the files, template:
<repositories>
<repository>
<id>mvnrepository_id</id>
<name>mvnrepository.com</name>
<url></url>
</repository>
Now, my doubt is, what should be the value of the <url>; does it need to be the base url , like http://mvnrepository.com/ or the complete URL --> http://mvnrepository.com/artifact/org.apache.hadoop/hadoop-hdfs
To me it appears that is should be the base url else for each dependency we have to put the complete URL.
Can anyone help me understand this?
Unless you want to fetch artifacts from a repository different from the default Central Maven repository, you need not add the <repositories> section to your pom.xml. Read about Maven Repositories here and here.
And the url for default Central Maven repository is http://repo.maven.apache.org/maven2/.
PS: The URLs you have posted are the ones for the Website.

How can I add maven artifact into an existing maven project

How can I add maven artifact into an existing maven project.I understand that I can build a jar locally and use file: protocol but this is possible using maven also.
For example I have a basic maven project
https://maven.apache.org/guides/getting-started/index.html#How_do_I_make_my_first_Maven_project and the artifact:
<repositories>
<repository>
<id>myrepo.org</id>
<name>MyRepository</name>
<url>http://mywork.com/repository</url>
</repository>
</repositories>
<dependency>
<groupId>org.ethereum</groupId>
<artifactId>ethereumj-core</artifactId>
<version>1.1.0-RELEASE</version>
I tried adding the code above to the project pom.xml fails because dependency is not in central maven repo.
mvn clean install
I then tried editing my settings.xml by adding the tag, that also failed because dependency was not found.
Im overlooking something pretty basic here.
Maven works on the concept of local and remote repositories.
The local repository refers to a copy on your own installation that is a cache of the remote downloads, and also contains the temporary build artifacts that you have not yet released.
Remote repository is repository you access the artifacts via file or http / ftp protocols , it can be an internal repo or a remote public hosted.
When you add dependency maven search that artifact in local if not found then remote repo will be searched. Still not found then error is reported.
https://maven.apache.org/guides/introduction/introduction-to-repositories.html
In your case, 'ethereumj-core' can not be located neither of location, you need find this jar and do a manual install to local repo.
mvn install:install-file -Dfile=< folder >\ethereumj-core.1.1.0-RELEASE.jar -DgroupId=org.ethereum
-DartifactId=ethereumj-core -Dversion=1.1.0-RELEASE -Dpackaging=jar
once properly installed maven should be able find this artifact when you add this as dependency to any of the projects (in pom.xml).
<dependency>
<groupId>org.ethereum</groupId>
<artifactId>ethereumj-core</artifactId>
<version>1.1.0-RELEASE</version>
</dependency>

Maven dependencies in local REPO have .lastUpdated extension

When I try to to install maven project in local repository, I notice that pom and jar files have .lastUpdated extension. Because of this issue I cannot build my project which depends on it.
Could you please explain why it happens?
I've found the answer here :
When an artifact is unable to be downloaded, Maven 3 caches this result for future reference in the "~/.m2/repo/.../.lastUpdated" file. For "not found" situations, it seems that the HTTP code could be used to more granularly re-attempt retrieval rather than just cache the failure.
For example, for any 404, I agree, the result should cache the failure and require a -U to attempt to retrieve it again. However, for 400, 500, 501, 502, 503, 301, 302 (what's the Maven behavior for 3xx today?) I think the resolution engine should try to re-retrieve the artifact each time. With those error codes, it seems more likely a config issue or brief network hiccup, not one of the file being absent from that repo. However, that brief network hiccup has longstanding cache implications in that the file is never attempted to be retrieved again.
It also can happen when you refer to the artifact which is listed under Maven Repository but is not there physically. E.g., the following Exasol artifact is listed under Maven Repository, but there's a small side note which tells that:
Note: this artifact i[s] located at Exasol repository
(https://maven.exasol.com/artifactory/exasol-releases/)
This means that you need to separately add another repository (in this case Exasol) as a source in your pom.xml file:
<!-- add the dependency as mentioned in maven website -->
<dependencies>
<dependency>
<groupId>com.exasol</groupId>
<artifactId>exasol-jdbc</artifactId>
<version>6.2.1</version>
</dependency>
</dependencies>
<!-- add the actual repository which unfortunately isn't mentioned in maven website -->
<repositories>
<repository>
<id>maven.exasol.com</id>
<url>https://maven.exasol.com/artifactory/exasol-releases</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>

How can i use SVN as Maven Repository

I am working on project which has multiple dependencies. Most of the dependencies are available at our centralized maven repository. My project includes some JARs which only specific to my application and unavailable at our Maven repo. Due to some policy/restriction i cant deploy that jars to our maven repository.
When i install these jars in my local repository(i.e.UserHome/.m2/repository) and compile the code its working fine.
Now i want these dependencies in SVN so that we can build the application package using Continuum.(We cant refer local dependency from Continuum server.)
Just to achieve these i copied the locally installed dependency from .m2/repository and committed it in SVN. Then i declared repository in pom.xml like..
<repositories>
<repository>
<id>repo.pu</id>
<name>repo.pu</name>
<url>https://URL/migration2/APP1/src/main/lib/</url>
<layout>default</layout>
</repository>
</repositories>
Now to use dependency from above repo i added code like...
<dependencies>
<dependency>
<groupId>repo.pu</groupId>
<artifactId>Ptestval</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
When i type mvn verify i am getting the below error..
[ERROR] Failed to execute goal on project APP1: Could not resolve dependencies f
or project fileservices.migration2:APP1:jar:1.0: Failed to collect dependencies
for [repo.pu:Ptestval:jar:1.0 (compile)]: Failed to read artifact descriptor for
repo.pu:Ptestval:jar:1.0: Could not transfer artifact repo.pu:Ptestval:pom:1.0
from/to repo.pu (https://URL/migration2/APP1/src/main/lib/): Access denied to:
https://URL/migration2/APP1/src/main/lib/repo/pu/Ptestv
al/1.0/Ptestval-1.0.pom -> [Help 1]
Could you please someone help me to resolve these issue?
EDIT: I created a repository like ..
<repositories>
<repository>
<id>repo.pu</id>
<name>repo.pu</name>
<url>https://SVNUserName:SVNPassword#SVN_URL/BaseProj/ProjA/src/main/lib</url>
<layout>default</layout>
</repository>
</repositories>
This technique works perfectly at my Personal laptop. Maven downloads the listed dependency from repo.
But when tries to use the same in my project on company network it is not working .. It gives the same error which i was getting before using this approach.
Can anyone help me please? What would be problem? Is it a network issue?
Set up a repository manager like Nexus and don't abuse Subversion for something it was not designed for. This is unfortunately done in Google Code.
You must configure your project to use wagon-scm.
See http://maven.apache.org/wagon/wagon-providers/wagon-scm/usage.html

Resources