I am trying to start my tests in an environment without an internet connection.
To do this, I need to save my dependencies in the project directory and specify Maven for this repository.
I copy repository folder from .m2 to project, write:
<repositories>
<repository>
<id>project-repository</id>
<url>file:${project.basedir}/repository</url>
<releases>
<checksumPolicy>ignore</checksumPolicy>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
and hoped that the maven would ignore the local m2 repository. But when I remove all the dependencies from m2, the maven still downloads them from the Internet. If i disconnected - the maven ignores the local repository and does not start.
Could not transfer artifact org.apache.maven.plugins:maven-clean-plugin:pom:2.5 from/to central (https://repo.maven.apache.org/maven2): repo.maven.apache.org: nodename nor servname provided, or not known
How can I tell the maven to work only from the internal repository? Without custom setting.xml, only on *.pom .
Maven is using the values from the settings.xml in {M2_HOME}\conf\settings.xml.
The issues here is that settings.xml allows you to override definitions in pom.xml, not the other way round. So you can override the tag <localRepository> in settings.xml, more on this here. Also This answer in another thread explains why.
The other option is to set the maven local repository on the command line:
mvn clean install -Dmaven.repo.local=repository
Related
I have Maven 3.0.5 with Java 8 setup (that's for particular project and stack versions won't be revised).
I'm aware of Apache's new decision to force all the Maven repositories to only use HTTPS, otherwise Maven clients won't be able to speak to the repository servers.
It seems like I have configured all necessary settings in ~/.m2/settings.xml but for some reason, when I any build phase (say mvn clean), Maven defaults to HTTP and doesn't care about settings.xml - it still attempts to download references/dependencies with HTTP protocol.
Example of my settings.xml
(For simplicity, I removed project specific things and left only problem-related stuff):
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<repositories>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2/</url>
</repository>
<repository>
<id>central</id>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
</repositories>
and here is what I'm getting when I do mvn archetype:generate, just to test the behaviour of Maven (the problem is persistent for any other command that tries to reach servers out):
[INFO] Scanning for projects...
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-clean-plugin:2.5: Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.5
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-install-plugin/2.3/maven-install-plugin-2.3.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-install-plugin:2.3: Plugin org.apache.maven.plugins:maven-install-plugin:2.3 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-install-plugin:jar:2.3
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-deploy-plugin/2.7/maven-deploy-plugin-2.7.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-deploy-plugin:2.7: Plugin org.apache.maven.plugins:maven-deploy-plugin:2.7 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-deploy-plugin:jar:2.7
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-site-plugin/3.0/maven-site-plugin-3.0.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-site-plugin:3.0: Plugin org.apache.maven.plugins:maven-site-plugin:3.0 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-site-plugin:jar:3.0
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-antrun-plugin/1.3/maven-antrun-plugin-1.3.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-antrun-plugin:1.3: Plugin org.apache.maven.plugins:maven-antrun-plugin:1.3 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-antrun-plugin:jar:1.3
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-assembly-plugin/2.2-beta-5/maven-assembly-plugin-2.2-beta-5.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5: Plugin org.apache.maven.plugins:maven-assembly-plugin:2.2-beta-5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-assembly-plugin:jar:2.2-beta-5
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-dependency-plugin/2.1/maven-dependency-plugin-2.1.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-dependency-plugin:2.1: Plugin org.apache.maven.plugins:maven-dependency-plugin:2.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-dependency-plugin:jar:2.1
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-release-plugin/2.0/maven-release-plugin-2.0.pom
[WARNING] Failed to retrieve plugin descriptor for org.apache.maven.plugins:maven-release-plugin:2.0: Plugin org.apache.maven.plugins:maven-release-plugin:2.0 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-release-plugin:jar:2.0
Downloading: http://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml
Downloading: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml
[WARNING] Could not transfer metadata org.apache.maven.plugins/maven-metadata.xml from/to central (http://repo.maven.apache.org/maven2): Failed to transfer file: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml. Return code is: 501 , ReasonPhrase:HTTPS Required.
[WARNING] Could not transfer metadata org.codehaus.mojo/maven-metadata.xml from/to central (http://repo.maven.apache.org/maven2): Failed to transfer file: http://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml. Return code is: 501 , ReasonPhrase:HTTPS Required.
[WARNING] Failure to transfer org.apache.maven.plugins/maven-metadata.xml from http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced.
Original error: Could not transfer metadata org.apache.maven.plugins/maven-metadata.xml from/to central (http://repo.maven.apache.org/maven2): Failed to transfer file: http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-metadata.xml. Return code is: 501 , ReasonPhrase:HTTPS Required.
[WARNING] Failure to transfer org.codehaus.mojo/maven-metadata.xml from http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced.
Original error: Could not transfer metadata org.codehaus.mojo/maven-metadata.xml from/to central (http://repo.maven.apache.org/maven2): Failed to transfer file: http://repo.maven.apache.org/maven2/org/codehaus/mojo/maven-metadata.xml. Return code is: 501 , ReasonPhrase:HTTPS Required.
What shall I do? as you see, it still uses HTTP, and I, correspondingly, get HTTP 501.
In your case, it seems to be working for dependencies, but not for plugins. You need to define a <profile> that is activeByDefault and contains a <pluginRepositories/> section for both snapshot and releases.
Maven has two types of repositories:
For dependencies
For plugins
The <mirrorOf> section only handles dependency repositories.
There were two problems:
Problem 1:
[WARNING] Failed to retrieve plugin descriptor for .. (whatever plugin name) warnings during almost any build phase, which says that (important>) the retrieval of plugin descriptors or its dependencies (which means plugins, and not the project dependencies!) is not going successful.
Here, Maven attempts to communicate with the end-point machine (repository) via HTTP, despite the fact(!), that I have customized my configuration .m2\settings.xml file and all the repository definition entries are with HTTPS, respectively, seems like Maven should be trying everything via HTTPS ..but no, it uses HTTP for plugins, and any HTTP communication with Maven repositories is forbidden since the 15th of January, 2020.
The way I resolved this is to define and configure <profiles/> and <pluginRepositories/> as #carlspring suggested, but I had to elaborate and expand that answer a bit.
So, here is my ready working settings.xml example: (note, that just to be safe, I provided alternative repositories in both - profiles and repositories)
<settings
xmlns="http://maven.apache.org/SETTINGS/1.0.0" $ xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<profiles>
<profile>
<id>ssl-profile</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>central-1</id>
<url>https://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central-2</id>
<url>https://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
<repositories>
<repository>
<id>central1</id>
<url>https://repo1.maven.org/maven2/</url>
</repository>
<repository>
<id>central2</id>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
</repositories>
</profiles>
</settings>
After this was resolved, and finally Maven attempted to connect to all the repositories via HTTPS, I then had another,
Problem 2:
peer not authenticated followed by Return code is: 501 , ReasonPhrase:HTTPS Required.
This was a bit tricky, but the way of solving this is to play with truststore cacerts file.
First, check whether you have truststore file cacerts and whether it's empty. it must NOT be empty and this is very important.
It seems like, in the OpenJDK 11 and in some other builds for Windows/Linux systems, cacerts file is either missing or present, but empty; however, according to my observation, it was present in Oracle JDK builds.
On Windows builds, it should be under %JAVA_HOME%\lib\security\;
On Linux builds, it may vary (depending on Linux distribution and your setup), but in my case, it was under /etc/ssl/certs (and I think that's Linux's certificates folder, not particularly Java's one).
If you see, that cacerts file is either absent or empty (simply check the file size, it should be larger than few bits), you can either:
Simply copy-paste existing cacerts file from some other JDK/JRE build;
Generate a cacerts truststore file and add certificate(s) to it. In this case, you will need to add as many certificates as you need, so, maybe it's easier to go with just a copy-paste variant.
I hope this helps.
I would suggest to go the following path:
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
<mirrors>
<mirror>
<id>central</id>
<name>central</name>
<url>https://repo1.maven.org/maven2/</url>
<mirrorOf>*</mirrorOf>
</mirror>
</mirrors>
</settings>
This will redirect all request via the above URL. If you have a repository manager inside of your corporate environment it's better to use this one and let the repo manager handle the https stuff.
Also an upgrade of Maven to most recent version 3.6.3 and I supose you are not using the most recent versions of plugins which I strongly recommend to upgrade there had been a lot of improvements.
I am trying to upload a Maven artifact I haven't built to my Organization's GitHub package registry. I am using the deploy:deploy-file Maven plugin in order to do so. Here is the command I have been using:
mvn deploy:deploy-file
-Dfile=[THE JAR FILE]
-Durl=https://maven.pkg.github.com/[ORG]
-Dregistry=https://maven.pkg.github.com/[ORG]
-DgroupId=[GID]
-DartifactId=[ARTIFACTID]
-Dversion=[VERSION]
-DgeneratePom=false
-Dtoken=[MY GITHUB TOKEN]
As a result I am receiving 401 errors from Github.
I have made sure that:
I have sufficient permissions inside of my Organization (currently Owner).
The token i am using is valid and has the appropriated scopes: I put all of them on to test.
Also, the github package page states:
<!-- Just a single step: Deploy using a GitHub token -->
$ mvn deploy -Dregistry=https://maven.pkg.github.com/[org] -Dtoken=GH_TOKEN
Why can't I find any information in Maven documentation about registry or token parameters?
Can I upload this file to the organization's registry without any kind of XML configuration file, using only the cli?
Thanks in advance.
I had success with this:
mvn deploy:deploy-file -Dfile=./[JAR].jar
-DpomFile=./pom.xml
-DrepositoryId=github
-Durl=https://maven.pkg.github.com/[OWNER]/[REPO]
-Dtoken=GH_TOKEN
And a settings.xml in my maven home directory:
<settings>
<servers>
<server>
<id>github</id>
<username>[GITHUB USERNAME]</username>
<password>[GENERATED ACCESS TOKEN]</password>
</server>
</servers>
</settings>
And inside my POM:
...
<distributionManagement>
<repository>
<id>github</id>
<name>GitHub Packages</name>
<url>https://maven.pkg.github.com/[OWNER]/[REPO]</url>
</repository>
</distributionManagement>
...
To workaround the repo issue - since I didn't want each package to be published to a different repo, I created a repo named packages and published the packages from all the other repos to it, using the same config as in the other two answers.
Url should have a repository name as well.
In one of my projects I have this in pom.xml
<distributionManagement>
<repository>
<id>github</id>
<url>https://maven.pkg.github.com/stirante/lol-client-java-api</url>
</repository>
</distributionManagement>
I am trying to deploy the Maven build JAR to Github Package Registry.
I am getting exception when I execute mvn deploy command.
I am using a simple Maven project which I want to create a component JAR and store in Github Package Registry.
The build is successful I now want to deploy this artifact to registry.
I have added the below in ~./m2/settings.xml.
Added a repository element under repositories in profile.
<repository>
<id>github</id>
<name>GitHub OWNER Apache Maven Packages</name>
<url>https://maven.pkg.github.com/swastikaa-in</url>
</repository>
<servers>
<server>
<id>github</id>
<username>swastikaa</username>
<password>my personal token from github</password>
</server>
</servers>
Also, I have added the below in Maven project's pom.xml:
<distributionManagement>
<repository>
<id>github</id>
<name>GitHub OWNER Apache Maven Packages</name>
<url>https://maven.pkg.github.com/swastikaa-in/math</url>
</repository>
</distributionManagement>
Expected:
Deployment to be successful , build artifact is deployed to Github package registry.
Actual:
Exception as below:
Caused by: org.eclipse.aether.transfer.MetadataTransferException:
Could not transfer metadata com.redjohn.tools:math:0.0.2-SNAPSHOT/maven-metadata.xml
from/to github (https://maven.pkg.github.com/swastikaa-in/math):
Failed to transfer file https://maven.pkg.github.com/swastikaa-in/math/com/redjohn/tools/math/0.0.2-SNAPSHOT/maven-metadata.xml
with status code 400
Caused by: org.apache.maven.wagon.TransferFailedException:
Failed to transfer file https://maven.pkg.github.com/swastikaa-in/math/com/redjohn/tools/math/0.0.2-SNAPSHOT/maven-metadata.xml
with status code 400
Can someone help me in resolving the issue.
I have followed the instructions provided in the below link:
https://help.github.com/en/articles/configuring-apache-maven-for-use-with-github-package-registry
I had the same problem and I found that snapshot versions don't work well. If you deploy a non snapshot version, it should work.
Inside your settings.xml file, <url>https://maven.pkg.github.com/OWNER/REPOSITORY</url> you need to make use that OWNER is replaced with your github username and REPOSITORY is replaced with the name of your project repository in github.
In Java I am adding below maven dependency,
<dependency>
<groupId>cloudant-labs</groupId>
<artifactId>spark-cloudant</artifactId>
<version>2.0.0-s_2.11</version>
</dependency>
but it is not loading package even in pom.xml file showing below error,
Missing artifact cloudant-labs:spark-cloudant:jar:2.0.0-s_2.11
Can anyone help me please why it is causing issue?
I am able to add another maven dependencies but particularly this is not working..
It's not in the official maven repository. (http://search.maven.org/#search%7Cga%7C1%7Cspark-cloudant)
But when you check: https://mvnrepository.com/artifact/cloudant-labs/spark-cloudant/2.0.0-s_2.11 there is note:
Note: this artifact it located at Spark Packages repository
(https://dl.bintray.com/spark-packages/maven/)
So you will need to add following to your pom.xml:
<repositories>
<repository>
<id>bintray</id>
<name>bintray.com</name>
<url>https://dl.bintray.com/spark-packages/maven/</url>
</repository>
</repositories>
EDIT:
According to https://spark.apache.org/news/new-repository-service.html
Bintray, the original repository service used for https://spark-packages.org/, is in its sunset process, and will no longer be available from May 1st. To consume artifacts from the new repository service, please replace “dl.bintray.com/spark-packages/maven” with “repos.spark-packages.org” in the Maven pom files or sbt build files in your repositories.
So this should work:
<repositories>
<repository>
<id>bintray</id>
<name>bintray.com</name>
<url>https://repos.spark-packages.org</url>
</repository>
</repositories>
Check your maven repo to verify that the file name and version matches what you've specified. Most Maven repo's give you an example of what to use, copy/paste.
ex: Sonatype Nexus is a repo that I use and they let you search and get snippets so you never have to worry about typing things wrong.
I'm having some issues to configure properly my eclipse to work with maven.
I create a new project, this one is correctly build with maven in command line (mvn install), but in Eclipse I got this error:
CoreException: Could not get the value for parameter compilerId for plugin execution default-compile: PluginResolutionException: Plugin org.apache.maven.plugins:maven-compiler-plugin:3.1 or one of its dependencies could not be resolved: Failed to collect dependencies for org.apache.maven.plugins:maven-compiler-plugin:jar:3.1 (): ArtifactDescriptorException: Failed to read artifact descriptor for org.apache.maven:maven-settings:jar:2.2.1: ArtifactResolutionException: Failure to transfer org.apache.maven:maven-settings:pom:2.2.1 from http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.apache.maven:maven-settings:pom:2.2.1 from/to central : NullPointerException pom.xml /test line 9 Maven Project Build Lifecycle Mapping Problem
Here is my settings.xml conf :
<proxy>
<active>true</active>
<protocol>http</protocol>
<username>myuser</username>
<password>$mymdp</password>
<host>myhost</host>
<port>8080</port>
<nonProxyHosts>some.host.com</nonProxyHosts>
</proxy>
....
<repository>
<id>central</id>
<name>central repo m2</name>
<url>http://central.maven.org/maven2</url>
</repository>
I choose the correct maven installation (in Preference -> Maven -> Install)
I also direct my user settings on the correct settings.xml (Preferences -> Maven -> User Settings)
But I still got this error in Eclipse and everything goes well with maven command line. Do you have and idea?
You only need to delete one folder it is throwing error for. Just go to your M2 repo and org/apache/maven/plugins/maven-compiler-plugins and delete the folder 2.3.2
Have you tried to remove the proxy username and password? A similar poster encountered that issue:
Could not calculate build plan: Plugin org.apache.maven.plugins:maven-jar-plugin:2.3.2 or one of its dependencies could not be resolved
Failing that I found the following worked:
Delete project in Eclipse (but do not delete the contents on disk)
Delete all files in your Maven repository
Re-download all Maven dependencies:
mvn dependency:resolve
Start up Eclipse
Ensure that Eclipse is configured to use your external Maven installation (Window->Preferences->Maven->Installations)
Re-import the existing project(s) into Eclipse
Ensure that there are no Maven Eclipse plugin errors on the final screen of the project import
I was getting this problem when using IBM RSA 9.6.1 when building a brand new development machine. The problem for me ended up being because of HTTPS on the Global Maven repository. My solution was to create a Maven settings.xml that forced it to use HTTP.
The key to me was that the central repository was empty when I exploded it under Maven Repositories -- > Global Repositories
Using the following settings file worked for me:
<settings>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>insecurecentral</activeProfile>
</activeProfiles>
<profiles>
<profile>
<id>insecurecentral</id>
<!--Override the repository (and pluginRepository) "central" from the Maven Super POM -->
<repositories>
<repository>
<id>central</id>
<url>http://repo.maven.apache.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://repo.maven.apache.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
</settings>
I got the idea from this stackoverflow question.
The issue has been resolved while installation of the maven settings is provided as External in Eclipse. The navigation settings are Window --> Preferences --> Installations. Select the External as installation Type, provide the Installation home and name and click on Finish. Finally select this as default installations.
I accidentally turned on offline mode.
To disable it: in the Maven tool window, click The Toggle Offline Mode button.
I also got the same issue and not able to create a jar, and I found that in Windows-->Prefernces-->Java-->installed JREs By default JRE was added to the build path of newly
created java project so just changed it to your prefered JDK.
Find your Maven local repository, navigate to maven-compiler-plugin, delete the 3.8.1 folder, so that the Maven will redownload it again.
For example:
C:\Users\mkyong.m2\repository\org\apache\maven\plugins\maven-compiler-plugin