Why can't I find my settings.xml under ~/.m2?
Note: I'm currently running Apache Maven 3.3.9 on my machine.
There are two locations where a settings.xml file may live:
The Maven install: ${maven.home}/conf/settings.xml
The user’s install: ${user.home}/.m2/settings.xml
The former settings.xml are also called global settings, the latter
settings.xml are referred to as user settings. If both files exists,
their contents gets merged, with the user-specific settings.xml being
dominant.
Tip: If you need to create user-specific settings from scratch, it’s
easiest to copy the global settings from your Maven installation to
your ${user.home}/.m2 directory. Maven’s default settings.xml is a
template with comments and examples so you can quickly tweak it to
match your needs.
Maven Settings Reference Guide
So simply
navigate to your maven directory under ${maven.home}/conf/settings.xml
and copy&paste your settings.xml to ${user.home}/.m2/
Run mvn -X to get information about your maven installation like below
Apache Maven 3.6.0
Maven home: /usr/share/maven
Java version: 11.0.2, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: en_IN, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-47-generic", arch: "amd64", family: "unix"
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$1 (file:/usr/share/maven/lib/guice.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$1
In the above information you will be able to find settings.xml location like below
[DEBUG] Message styles: debug info warning error success failure strong mojo project
[DEBUG] Reading global settings from /usr/share/maven/conf/settings.xml
[DEBUG] Reading user settings from /home/test/.m2/settings.xml
[DEBUG] Reading global toolchains from /usr/share/maven/conf/toolchains.xml
[DEBUG] Reading user toolchains from /home/test/.m2/toolchains.xml
There is no settings.xml file by default.
If you need it you should create the file.
Related
and this is my command on cmd:
C:\Users\ADMIN\Downloads\apache-ofbiz-18.12.06>ant run-install
Buildfile: build.xml does not exist!
Build failed
What version of OFBiz are you using? Since 16.12 we no longer use Ant but Gradle. Have a look at the main README file (different suffixes are possible depending on version)
I got this error when deploying Maven through GitlabCI, docker image: maven:3-jdk-8.
Some problems were encountered while processing the POMs:
[FATAL] Non-resolvable parent POM for com.mycompany.app:app-all:0.9.3-SNAPSHOT:
Could not transfer artifact com.mycompany:parent:pom:8 from/to maven-default-http-blocker (http://0.0.0.0/):
Blocked mirror for repositories: [app-releases (http://nexus.mycompany.com/content/repositories/app-releases, default, releases+snapshots),
app-snapshots (http://nexus.mycompany.com/content/repositories/app-snapshots, default, releases+snapshots)] and 'parent.relativePath' points at wrong local POM # line 5, column 10
I found some answers here about editing the mirrors in the settings.xml file. I add the mirrors with blocked: false in /usr/share/maven/conf/settings.xml
<mirrors>
<mirror>
<id>app-releases</id>
<mirrorOf>app-releases</mirrorOf>
<url>http://nexus.mycompany.com/content/repositories/app-releases</url>
<blocked>false</blocked>
</mirror>
<mirror>
<id>app-snapshots</id>
<mirrorOf>app-snapshots</mirrorOf>
<url>http://nexus.mycompany.com/content/repositories/app-snapshots</url>
<blocked>false</blocked>
</mirror>
</mirrors>
But still got this error, I don't get why it search artifact in maven-default-http-blocker (http://0.0.0.0/) while option -X (debug) shows the settings.xml file is being used so the mirrors I set should be used.
1100 [DEBUG] Reading global settings from /usr/share/maven/conf/settings.xml
1100 [DEBUG] Reading user settings from /root/.m2/settings.xml
Did I make a mistake in the mirrors definition ?
This is probably due to Maven 3.8.1 blocking http repositories.
I would switch to https repositories if your company supports them.
You can do a mirroring in local. Add this in ~/.m2/settings.xml(which is a user-specific version of <maven_dir>/conf/settings.xml.
<settings>
<!-- if you need http connection, enable it and don't block -->
<mirrors>
<mirror>
<id>maven-default-http-blocker</id>
<mirrorOf>external:http:*</mirrorOf>
<name>Pseudo repository to mirror external repositories initially using HTTP.</name>
<url>http://0.0.0.0</url>
<blocked>false</blocked>
</mirror>
</mirrors>
...
</settings>
I even changed the url to file:/home/<my_user>/.m2/repository, which solved my problem.
I was facing the same issues.
Maven Version 3.8.6
JDK Java17
The problem is maven was referring to some dependencies which are listed over http protocol, however with latest maven it comes with the mirror to block the http dependencies as it want to encourage or enforce dependencies only over https
Solution
Switch to the https dependencies.
If https version of dependencies are not available then we can locally suppress the error by commenting the http-block mirror
Below steps are for macos, so do relevant for your OS
Run mvn --version to find the location of maven installation
bash-3.2$ mvn --version
Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Maven home: /usr/local/Cellar/maven/3.8.6/libexec
Now go to conf and open settings.xml
Comment the below mirror
<mirror>
<id>maven-default-http-blocker</id>
<mirrorOf>external:http:*</mirrorOf>
<name>Pseudo repository to mirror external repositories initially using HTTP.</name>
<url>http://0.0.0.0/</url>
<blocked>true</blocked>
</mirror>
Save it and re run the maven job, it should fix your issue.
GAPID uses bazel, and has external dependency that uses maven. I get this error:
ERROR: C:/users/pemgithub/_bazel_pemgithub/3mdmxsrc/external/gapic_third_party/BUILD.bazel:19:1: no such package '#io_grpc_context//jar': Failed to fetch Maven dependency: Could not transfer artifact io.grpc:grpc-context:jar:1.16.1 from/to io_grpc_context (https://repo1.maven.org/maven2/): connect timed out and referenced by '#gapic_third_party//:grpc'
ERROR: Analysis of target '//:pkg' failed; build aborted: no such package '#io_grpc_context//jar': Failed to fetch Maven dependency: Could not transfer artifact io.grpc:grpc-context:jar:1.16.1 from/to io_grpc_context (https://repo1.maven.org/maven2/): connect timed out
INFO: Elapsed time: 11.014s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 0 targets configured)
Fetching #com_github_pkg_errors; Restarting. 10s
I think it's related to proxy (corporate network). I tried adding proxy settings to C:/users/pemgithub/.m2/settings.html. However, bazel maven does not seem to be using the proxy settings.
So I'd rather just download the jar files manually and tell bazel maven to use the local jar files. How do I do this?
Bazel currently (July 2019) does not support this properly. While rules_jvm_external is recommended as the successor to maven_jar, it does not read Maven's ~/.m2/settings.xml and it also does not supporting using already downloaded artifacts from ~/.m2/repository.
One workaround is to use your own little reverse proxy, which reads from ~/.m2/repository and tell Bazel to download from localhost. I've created bazel-maven-proxy for this purpose. It does support proxies the same way Bazel does, i.e. reading http(s) and no_proxy environment variables.
Please do not use the maven_jar rule. It is being deprecated in favor of the Maven resolver ruleset rules_jvm_external.
In rules_jvm_external, you can use a proxy through the HTTP_PROXY/HTTPS_PROXY environment variables (documentation), and set a custom repository URL with auth credentials (documentation).
I have jenkins installed on a remote machine. How can I point my POM location in Jenkins. If I give the POM.xml location as C:\Automation\pom.xml I am getting the error no such file exists.
Started by user anonymous
Building in workspace C:\Users\Administrator\.jenkins\workspace\RegressionTestJob
Parsing POMs
ERROR: No such file C:\Automation\pom.xml
Perhaps you need to specify the correct POM file path in the project configuration?
TestNG Reports Processing: START
Looking for TestNG results report in workspace using pattern: **/testng-results.xml
Did not find any matching files.
Finished: FAILURE
Your pom should be in your workspace, like how you would build your project in an IDE e.g. eclipse and when you build your project Jenkins will find the pom on its own in the workspace and build the project
Incase you still wish to specify the location you can use the -f option
mvn -f PomFile.xml
Hope it helps :)
I have a few questions about Maven and Eclipse which I do not know much about them. I'm new to all these tools. Let me describe what I've done:
1 - installed apache-maven-3.3.9 on my window and placed at "C:\Program Files (x86)\apache-maven-3.3.9".
2 - Added MAVEN_HOME (and M2_HOME) environment variables.
3 - Added the "C:\Program Files (x86)\apache-maven-3.3.9\bin" to the Path environment variable.
4 - Set a proxy for Maven download by creating a xml file under ${user.home".m2]settings.xml. The content of the settings.xml is:
<settings>
<proxies>
<proxy>
<active>true</active>
<protocol>https</protocol>
<host>www.github.com</host>
<port>8080</port>
<nonProxyHosts>www.google.com</nonProxyHosts>
</proxy>
</proxies>
</settings>
5 - Tested and see if the Maven was properly installed:
C:\>mvn --version
C:\
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5 2015-11-10T11:41:47-05:00)
Maven home: C:\Program Files (x86)\apache-maven-3.3.9
Java version: 1.8.0_101, vendor: Oracle Corporation
Java home: C:\Program Files (x86)\Java\jdk1.8.0_101\jrr
Default locale: en_US, platform encoding: Cp1252
OS name: "windows server 2008 r2", version: "6.1", arch: "x86", family: "dos"
6 - Tried to generate archetype and got a bunch of errors. Only one error is shown below. Basically, Maven tries to download the plugin but fails. I doubt the errors are caused by internet connection, but I don't know where else I need to look in order to fix this issue. The reason I said I doubted it was the internet connection issue is because I configure my POM file with the external jars on the web and all were downloaded correctly.
C:\>mvn archetype:generate
C:\
[INFO] Scanning for projects...
Downloading: https://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:mave
n-clean-plugin:2.5: Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or on
e of its dependencies could not be resolved: Failed to read artifact descriptor
for org.apache.maven.plugins:maven-clean-plugin:jar:2.5
Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven
-install-plugin/2.4/maven-install-plugin-2.4.pom
Terminate batch job (Y/N)? y
C:\>
So... that is the maven plugins downloading problem.
And here is the Eclipse problem:
1 - Installed Eclipse Neon.
2 - Tried to add the Maven plugins and it say that all maven plugins already installed. I did the Maven plugins before with the previously installed Neon. Then I deleted the Neon Eclipse because it fails to create a simple Maven-archetype project. Then I re-installed the Neon Eclipse. But before I re-installed Eclipse I already deleted all previously-installed Eclipse folders but I do not know where the Eclipse keeps all of Maven info. When the newly-installed Eclipse tries to download the Maven plugins, it recognized that all of the Maven plugins were already installed. I have no ideas where Eclipse keeps all those info about Maven plugins?
3 - Tried again to create an simple Maven-archetype project, then I got this error message:
Could not resolve archetype org.apache.maven.archetypes:maven-archetype-quickstart:1.1 from any of the configured repositories.
Could not resolve artifact org.apache.maven.archetypes:maven-archetype-quickstart:pom:1.1
Could not transfer artifact org.apache.maven.archetypes:maven-archetype-quickstart:pom:1.1 from/to central (https://repo.maven.apache.org/maven2): connect timed out
Could not transfer artifact org.apache.maven.archetypes:maven-archetype-quickstart:pom:1.1 from/to central (https://repo.maven.apache.org/maven2): connect timed out
So.. basically, it is the same error message that Maven has.
Questions:
1 - What are the things I need to do get Maven plugins download via command line?
2 - Similarly, what are the things I need to do to get Eclipse to create a simple maven-archetype project?
I did checked out all of questions and answers about the issues of Maven not being able to download the plugins. I did try everything in last several days but no prevail. I understand that the answers/solutions are good but they do not work for me. Maybe I need to other things that I don't know where else I need to look for?
3 - Let say that after all these efforts fail, can I manually download the Maven plugins and configure them via my POM.xml? I checked the apache Maven website and it seems that the answer is "yes" but it does not provide the "how". I know it is NOT the best solution for maven plugins download but if I couldn't fix the download issue, the I will have to resort to the manual download and then configure the POM file.
Would you please show me how to configure the POM.xml file with the Maven Plugins?
Sorry about the long questions, but I'm new to these tools and I'm just trying to get a simple Java project built by Maven via Eclipse.
The proxy in the settings file is for case where the machine you run is behind a proxy (lets say a corporate proxy). You have put github.com as the proxy host which is not right.
If you have the maven installation bundled with eclipse that provides you integration with the IDE itself during the maven lifecycle process. You are however free to add a maven installation of your own by adding a existing maven installation from eclipse as well (you want to use a specific installation of maven with its settings).
If you are behind a corporate proxy , you will have to get the proxy through which the machine connects to the internet. You can then add that detail into the proxy settings in maven. In the case that your corporate proxy uses a dynamic proxy (e.g. a .pac file opposed to static host) you will need to look at options like CNTLM or wagon to work around and get it running.