I am using maven-release-plugin:2.5.1. I need to configure it to connect to SVN using public/private key authentication. I'm having problems getting the configuration to use the correct username when attempting the SSH connection to SVN.
My deploy-settings.xml <server> config looks like:
<server>
<id>my.server.org</id>
<username>[XXXX]</username>
<privateKey>/home/[YYYY]/.ssh/id_rsa</privateKey>
</server>
My pom.xml <scm> config looks like:
scm:svn:svn+ssh://my.server.org/data1/svns_zzzz/zzzz/path/to/the/project/trunk
My mvn command line looks like:
--batch-mode release:clean release:prepare release:perform
-s /home/[YYYY]/.m2/deploy-settings.xml
-Dsettings.security=/home/[YYYY]/.m2/master-settings.xml
When I tried the above configuration it failed. It could not commit the modified POM file to SVN. To help debug this problem, I set the following environment variable:
SVN_SSH="ssh -vvv"
When I did this, I saw in the debug statements too many authentication failures with a username other than the [XXXX] username defined in the <server> tag.
So then I tried to specify the username in the command line:
--batch-mode -Dusername=[XXXX] release:clean release:prepare release:perform...
That didn't work.
So then I tried to specify the username in the POM:
scm:svn:svn+ssh://[XXXX]#my.server.org/data1/svns_zzzz/zzzz/path/to/the/project/trunk
That didn't work either.
To debug and verify my [XXXX] username and /home/[YYYY]/.ssh/id_rsa key did in fact work, I added them to the environment variable:
SVN_SSH="ssh -vvv -l [XXXX] -i /home/[YYYY]/.ssh/id_rsa"
After setting the environment variable like this, it worked. The release plugin was able to successfully commit the modified POM file to SVN. So I know the username and password work.
So now the question is what is wrong with my Maven configuration? Setting the SVN_SSH environment variable helped diagnose the problem, and provides a work-around but I don't want to leave it as a long-term solution.
Any thoughts?
The release plugin forks the build, and doesn't pass the arguments you provide on the command line to the forked process by default. Try adding this: -Darguments="-s /home/[YYYY]/.m2/deploy-settings.xml -Dsettings.security=/home/[YYYY]/.m2/master-settings.xml" (note double quotes) to the current command line. This should pass the changes to the forked processes.
Related
When outside of a project, with no pom.xml, is it possible to change where Maven expects the user settings, always? As in, from a terminal window in the user's home directory?
I have been reading for days but I can't find an answer on the apache site, google, or here. In https://maven.apache.org/settings.html it says:
There are two locations where a settings.xml file may live:
The Maven install: ${maven.home}/conf/settings.xml
A user’s install: ${user.home}/.m2/settings.xml
I want to change the actual configuration of Maven installation/program on my machine to look for the user's settings somewhere else, always: /home/userFoo/bin/maven.config.directory/settings.xml instead of /home/userFoo/.m2/settings.xml
The settings.xml file says:
<!--
| This is the configuration file for Maven. It can be specified at two levels:
|
| 1. User Level. This settings.xml file provides configuration for a single user,
| and is normally provided in ${user.home}/.m2/settings.xml.
|
| NOTE: This location can be overridden with the CLI option:
|
| -s /path/to/user/settings.xml
But when I run that command, mvn -s /home/userFoo/bin/maven.config.directory/settings.xml i get many errors.
You can set MAVEN_OPTS environment variable to override user.home in the JVM.
export MAVEN_OPTS=-Duser.home=/home/userFoo/bin/maven.config.directory
# do something with Maven
mvn dependency:list
or Windows
set MAVEN_OPTS=-Duser.home=D:\home\userFoo\bin\maven.config.directory
:: do something with Maven
mvn dependency:list
You can also add MAVEN_OPTS to your .bashrc, .profile, or Windows Environment.
You can try using the command:
mvn --settings /home/userFoo/bin/maven.config.directory/settings.xml archetype:generate
You can verify if your custom settings file is being loaded by checking the output of the command:
mvn --settings /home/userFoo/bin/maven.config.directory/settings.xml help:effective-settings
Even the default global settings file location can be changed if you want that to be loaded from a shared location by appending to the above command before the goal:
--global-settings /${shared.location}/settings.xml
You may also want to create an alias for the command in case you do not want to enter it every time.
Putting this here because it is the only way I can make it work, but it feels wrong:
Make a soft link at ${user.home}/.m2/settings.xml with:
ln -s ~/.m2/settings.xml ~/bin/maven.config.directory/settings.xml
I'm performing a release of a project on Github using Maven. release:prepare fails with:
[ERROR] Provider message:
[ERROR] The git-push command failed.
[ERROR] Command output:
[ERROR] remote: Permission to FOO/BAR.git denied to BAZ.
[ERROR] fatal: unable to access 'https://github.com/FOO/BAR.git/': The requested URL returned error: 403
The weird thing is that BAZ is the "wrong" github.com account. It is one of two user names I use on Github, but not one I have ever used with the BAR project. Let's say the right account is FIZZ.
SCM settings don't specify a user name:
<scm>
<connection>scm:git:https://github.com/FOO/BAR.git</connection>
<url>scm:git:https://github.com/FOO/BAR.git</url>
<developerConnection>scm:git:https://github.com/FOO/BAR.git</developerConnection>
...
</scm>
(FOO is an organization that I'm part of.) In fact, I can't figure out where on earth BAZ is coming from. It's not in ~/.gitconfig or .git/config. There is no ~/.m2/settings.xml file. My Maven settings.xml file says nothing about Github.
If I use git on the command line it works -- push is fine for example.
Can anyone tell me where else this might be coming from? a hidden config file or directory somewhere, whether Maven- or Git-related?
Or, what's the best practice for recording the Github user to use in a private local file, like a Maven settings.xml or .git/config, such that I need not put my own user into the build file?
I'm using Mac OS X.
The simplest thing would be to explicitly use an ssh url, see more details in this answer.
git remote set-url origin git#github.com:FIZZ/FOO/BAR.git
Finally figured this out. The problem is that I'm on OS X, and had logged in to my second account BAZ via Safari. This saved the username and password for https://github.com in Keychain. Apparently, the Maven SCM plugin consults this for HTTPS URLs, although git won't. After clearing Keychain, it correctly prompted me for a username and password.
I am using Maven 3.0, and my .m2 folder location is C:\Users\me\.m2.
However, I do not have write access to that folder, but I want to change the repository location from the one defined in the settings.xml.
Due to restricted access, I am not able to edit the settings.xml to change the repository location.
How can I override the values of my settings.xml -or change the default location of the .m2 folder- without editing my C:\Users\me\.m2\conf\settings.xml file?
You need to add this line into your settings.xml (or uncomment if it's already there).
<localRepository>C:\Users\me\.m2\repo</localRepository>
Also it's possible to run your commands with mvn clean install -gs C:\Users\me\.m2\settings.xml - this parameter will force maven to use different settings.xml then the default one (which is in $HOME/.m2/settings.xml)
It's funny how other answers ignore the fact that you can't write to that file...
There are a few workarounds that come to my mind which could help use an arbitrary C:\redirected\settings.xml and use the mvn command as usual happily ever after.
mvn alias
In a Unix shell (or on Cygwin) you can create
alias mvn='mvn --global-settings "C:\redirected\settings.xml"'
so when you're calling mvn blah blah from anywhere the config is "automatically" picked up.
See How to create alias in cmd? if you want this, but don't have a Unix shell.
mvn wrapper
Configure your environment so that mvn is resolved to a wrapper script when typed in the command line:
Remove your MVN_HOME/bin or M2_HOME/bin from your PATH so mvn is not resolved any more.
Add a folder to PATH (or use an existing one)
In that folder create an mvn.bat file with contents:
call C:\your\path\to\maven\bin\mvn.bat --global-settings "C:\redirected\settings.xml" %*
Note: if you want some projects to behave differently you can just create mvn.bat in the same folder as pom.xml so when you run plain mvn it resolves to the local one.
Use where mvn at any time to check how it is resolved, the first one will be run when you type mvn.
mvn.bat hack
If you have write access to C:\your\path\to\maven\bin\mvn.bat, edit the file and add set MAVEN_CMD_LINE_ARG to the :runm2 part:
#REM Start MAVEN2
:runm2
set MAVEN_CMD_LINE_ARGS=--global-settings "C:\redirected\settings.xml" %MAVEN_CMD_LINE_ARGS%
set CLASSWORLDS_LAUNCHER=...
mvn.sh hack
For completeness, you can change the C:\your\path\to\maven\bin\mvn shell script too by changing the exec "$JAVACMD" command's
${CLASSWORLDS_LAUNCHER} "$#"
part to
${CLASSWORLDS_LAUNCHER} --global-settings "C:\redirected\settings.xml" "$#"
Suggestion/Rant
As a person in IT it's funny that you don't have access to your own home folder, for me this constitutes as incompetence from the company you're working for: this is equivalent of hiring someone to do software development, but not providing even the possibility to use anything other than notepad.exe or Microsoft Word to edit the source files. I'd suggest to contact your help desk or administrator and request write access at least to that particular file so that you can change the path of the local repository.
Disclaimer: None of these are tested for this particular use case, but I successfully used all of them previously for various other software.
Nobody suggested this, but you can use -Dmaven.repo.local command line argument to change where the repository is at. In addition, according to settings.xml documentation, you can set -Dmaven.home where it looks for the settings.xml file.
See: Settings.xml documentation
Below is the configuration in Maven software by default in MAVEN_HOME\conf\settings.xml.
<settings>
<!-- localRepository
| The path to the local repository maven will use to store artifacts.
|
| Default: ~/.m2/repository
<localRepository>/path/to/local/repo</localRepository>
-->
Add the below line under this configuration, will fulfill the requirement.
<localRepository>custom_path</localRepository>
Ex: <localRepository>D:/MYNAME/settings/.m2/repository</localRepository>
You can change the default location of .m2 directory in m2.conf file. It resides in your maven installation directory.
add modify this line in
m2.conf
set maven.home C:\Users\me\.m2
You can point to a different-settings.xml when you deploy your project. When deployed from the project folder you can have a relative path to get back to your home folder:
mvn clean deploy -s ../../.m2/different-settings.xml
I think I have run in to a maven deploy plugin bug, but I want to confirm that I am not doing it wrong before I open a bug report and start grepping through source.
I am trying to deploy an arbitrary binary (tar.gz,jar,box,etc) to a maven repository.
The user I am using is in the settings.xml file with a plaintext password.
The user is in an LDAP group that is connected to nexus with a Role.
That role has 3 privileges associated with it. Update, Create, Read which are in turn associated with the repository target.
Now using wget the user can pull data from the repo, and using this curl command I can deploy to the repo:
curl --request PUT --user USERNAME:PASSWORD https://NEXUS_URL/nexus/content/repositories/REPO_NAME/path/to/file/with/groupid/version/iamafile.jar \
--data #./iamafile.jar -H Content-Type:application/java-archive --verbose
This works fine, http 201 and the file is added. When I use a similiar mvn deploy command:
mvn deploy:deploy-file --settings /path/to/settings.xml \
-Durl=https://NEXUS_URL/nexus/content/repositories/REPOSITORYID -Dfile=iamafile.jar \
-DrepositoryId=REPOSITORYID -DartifactId=ARTIFACTID -DgroupId=GROUPID \
-Dversion=VERSION
I get an http 401 unauthorized error.
There have been multiple bug reports about this, but they supposedly have been fixed.
With a pom file with the same values for version, artifcatId, etc. mvn deploy works fine.
Have I found a bug, or am I using it improperly?
Edit:
I opened up this bug regarding the issue.
If the dev's end up saying that it isn't a bug, I will add that as an answer if someone hasn't beat me to it.
you need to additionally specify the -DrepositoryId
I'm trying to create a script to 'mavenize' a set of libraries. In order to make them available directly from an artifactory repository, i wanted the script to run the deploy command for each of my libs.
But i cannot seem to find the login+password command lines options; is the settings.xml file the only option to specify them ?
You can put the username and password in the URL:
http://username:password#hostname:port/path