I am trying to fully automate a build and, most importantly, a release using maven in travis-ci. The way I am attempting to do it it to supply the username and password commandline as properties and have them substituted in the settings.xml file. Then, when running the build, I override the location of settings.xml to be a file I checked in. Everything needed to build and release needs to be checked into the repo. It doesn't look like maven is doing the property substitution though.
Example:
settings.xml
<?xml version='1.0' encoding='UTF-8'?>
<settings xsi:schemaLocation='http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd'
xmlns='http://maven.apache.org/SETTINGS/1.0.0' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
<servers>
<server>
<id>sonatype-nexus-snapshots</id>
<username>${SONATYPE_USERNAME}</username>
<password>${SONATYPE_PASSWORD}</password>
</server>
<server>
<id>sonatype-nexus-staging</id>
<username>${SONATYPE_USERNAME}</username>
<password>${SONATYPE_PASSWORD}</password>
</server>
</servers>
</settings>
build command:
mvn --settings $PWD/settings.xml -e -X -B release:prepare release:perform "-DSONATYPE_USERNAME=YYIaF/A4" "-DSONATYPE_PASSWORD=kowLPBgK+/kRiC+O96YZT1ibvxrdcKc" -Dgpg.passphrase=passphrase
These are not the actual credentials but I included the fact they have some funky characters incase that matters.
error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on project foo-parent: Failed to deploy artifacts: Could not transfer artifact com.baz:foo-parent:pom:3.0.3 from/to sonatype-nexus-staging (https://oss.sonatype.org/service/local/staging/deploy/maven2/): Failed to transfer file: https://oss.sonatype.org/service/local/staging/deploy/maven2/com/baz/foo-parent/3.0.3/foo-3.0.3.pom. Return code is: 401, ReasonPhrase: Unauthorized. -> [Help 1]
but if I do this the official way (.m2/settings.xml) - all is good.
Since the objective is to fully automate a release from travis-ci, if there is just a direct way to do that, I am all ears.
Related
I am new to clojure and I am trying to build a porject on a system that is behind a proxy server.
Every lein command I run tries to fetch middleware dependencies using the :middleware [lein-tools-deps.plugin/resolve-dependencies-with-deps-edn] tool. However, whenever it tries to download depedencies stated within the deps.edn file Java throws a connection timeout while trying to connect to https://repo1.maven.org/maven2/
environment variables
http_proxy
https_proxy
no_proxy
are configured properly.
I configured /home/<user>/.m2/settings.xml to use the proxy as well
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<proxies>
<proxy>
<id>my-proxy</id>
<active>true</active>
<protocol>http</protocol>
<host>myproxy.....</host>
<port>XXXX</port>
<nonProxyHosts>...|*.my.domain|localhost|127.0.0.1</nonProxyHosts>
</proxy>
</proxies>
</settings>
deps.edn is
{:deps {org.clojure/clojure {:mvn/version "1.10.0"}
org.clojure/clojurescript {:mvn/version "1.10.516}
.... }
:paths ["src/cljs" "resources" "target"]
:aliases {:build {:main-opts ["-m" "figwheel.main" "-b" "dev" "-r"]}}}
Any lein command (ex: lein deps) results in Could not transfer artifact org.clojure:clojure:pom:1.10.0 from/to central (https://repo1.maven.org/maven2/): connect timed out
However, removing :middleware from the file project.clj allows me to fetch any dependency not in defined in the plugin.
How can I get the plugin to use the http proxy?
I am trying to deploy maven artifact to central repository through Travis but I am facing below error:
[ERROR] Failed to execute goal org.sonatype.plugins:nexus-staging-maven-plugin:1.6.7:deploy (injected-nexus-deploy) on project Test-plugin: Execution injected-nexus-deploy of goal org.sonatype.plugins:nexus-staging-maven-plugin:1.6.7:deploy failed: Nexus connection problem to URL [https://oss.sonatype.org/ ]: 401 - Unauthorized -> [Help 1]
I have set correct username and password for sonatype account, still I am getting the same error.
Below are the files uploaded:
.travis.yml
settings.xml
Looks like your settings.xml in the .m2 folder in your home directory is not having proper authorization properties set for maven to look
I am enclosing a sample XML for your reference ..
https://maven.apache.org/settings.html
<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"> ... <servers>
<server>
<id>server001</id>
<username>my_login</username>
<password>my_password</password>
<privateKey>${user.home}/.ssh/id_dsa</privateKey>
<passphrase>some_passphrase</passphrase>
<filePermissions>664</filePermissions>
<directoryPermissions>775</directoryPermissions>
<configuration></configuration>
</server> </servers> ... </settings>
Here is the troubleshooting guide if you are getting 404
https://support.sonatype.com/hc/en-us/articles/213464518-Troubleshooting-Artifact-Download-Failures
From the docs
SNAPSHOT look-ups, or version ranges, or unversioned dependencies (typically plugins) will trigger metadata look-up. If the version referenced by the maven-metadata.xml is not there you will get a 404.
This can usually be fixed by running rebuild metadata on the affected artifact.
I'm trying to build a jar using maven and automatically scp it to a remote machine.
This is my pom.xml
<properties>
<deploy.username>root</deploy.username>
<deploy.host>10.10.4.10</deploy.host>
<deploy.port>22</deploy.port>
<deploy.dir>/root</deploy.dir>
</properties>
<distributionManagement>
<repository>
<id>repo1</id>
<url>scpexe://${deploy.host}:${deploy.dir}</url>
</repository>
</distributionManagement>
This is my settings.xml:
<?xml version="1.0" encoding="UTF-8"?>
<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 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<servers>
<server>
<id>repo1</id>
<username>root</username>
<password>root</password>
</server>
</servers>
</settings>
This the error log
Caused by: org.eclipse.aether.transfer.MetadataTransferException: Could not transfer metadata com.github.rssanders3.spark:spark_quick_start:1.0-SNAPSHOT/maven-metadata.xml from/to repo1 (scpexe://10.10.4.10:/root): Exit code: 1 - Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
at org.eclipse.aether.connector.basic.MetadataTransportListener.transferFailed(MetadataTransportListener.java:43)
at org.eclipse.aether.connector.basic.BasicRepositoryConnector$TaskRunner.run(BasicRepositoryConnector.java:355)
at org.eclipse.aether.util.concurrency.RunnableErrorForwarder$1.run(RunnableErrorForwarder.java:67)
at org.eclipse.aether.connector.basic.BasicRepositoryConnector$DirectExecutor.execute(BasicRepositoryConnector.java:581)
at org.eclipse.aether.connector.basic.BasicRepositoryConnector.get(BasicRepositoryConnector.java:222)
at org.eclipse.aether.internal.impl.DefaultDeployer.upload(DefaultDeployer.java:417)
... 28 more
Caused by: org.apache.maven.wagon.TransferFailedException: Exit code: 1 - Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
You can see the full output of maven -X in here
I'm submitting using the following command:
mvn deploy -DskipTests --settings settings.xml
The user name and and password is correct, I'm able to ssh to it use this credential. I even tried to scp a file to the remote without any problem.
I check maven debug output, it is loading the user defined settings.xml I created.
[DEBUG] Reading user settings from /Users/xuanyue/tmp/apache-spark-quickstart-project/settings.xml
And on the ssh server side, this is the only thing I get:
Feb 23 14:33:02 hadoop10 sshd[23804]: Connection closed by 192.168.100.26
I also tried replace scpexe with scp. Still not worked.
Try running it with the -X option:
mvn -X deploy -DskipTests --settings settings.xml
I suspect the problem may be to do with the user at the other side and their permissions (not necessarily file system permissions).
First you could restart sshd on your server with -v (or -vvv for full debug) and thus get more logs in your security file.
Also it looks to me you are trying to scp on a server, have you tried using the plugin org.apache.maven.wagon ?
See Mr Thivent's post: Uploading a File via SCP with Maven fails
You probably need the Maven Wagon Provider for SSH. Note that it must be added as a build extension.
<project>
...
<build>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.10</version>
</extension>
</extensions>
</build>
...
</project>
If you have this Wagon Provider, then the failure is likely due to your using an ancient version of Maven Wagon (you mentioned version 1.0-beta-6), which might work well with matching ancient versions (but certainly won't work well with the modern maven-dist-plugin).
Beta versions of Maven Wagon SSH do not need to be used. The current version as of now is 2.10.
Likewise, I don't believe you need to include the Maven Wagon Plugin as the maven-dist-plugin doesn't use that plugin, it directly uses the more modern wagon-provider-api. You should only need the SSH Wagon extension.
Finally, you should run a remote sshd instance for testing, from the command line (so the information goes to the terminal) with enough debugging on to determine if you are reaching the test box, and if you are actually passing in valid credentials (as sshd considers them).
It is important to remember that sshd has specific configuration options which deny root logins, if they are set. If you have access to the remote sshd box, you might also want to verify the sshd settings.
I am trying to run a mvn deploy goal with maven on my Liferay portlet but am getting the following error
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.8.
2:deploy (default-deploy) on project MyPortlet: Deployment failed: repository eleme
nt was not specified in the POM inside distributionManagement element or in -Dal
tDeploymentRepository=id::layout::url parameter -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal o
rg.apache.maven.plugins:maven-deploy-plugin:2.8.2:deploy (default-deploy) on pro
ject RiskID: Deployment failed: repository element was not specified in the POM
inside distributionManagement element or in -DaltDeploymentRepository=id::layout
I understand this error will return if you don't include the <distributionManagement /> tag in the pom.xml, however I don't wish to package this to a remote location and would like to instead deploy to my local tomcat instance; can this be configured?
The error is not about dependencyManagement but rather distributionManagement
Deployment failed: repository eleme
nt was not specified in the POM inside distributionManagement element or in -DaltDeploymentRepository=id::layout::url parameter
The alternative (if you don't want to place it in your pom.xml file) is also provided by using the altDeploymentRepository option:
Specifies an alternative repository to which the project artifacts should be deployed ( other than those specified in <distributionManagement> ).
Format: id::layout::url
The first element, the id, must have a matching with a server defined in your settings.xml file (where you specify the credentials to use for the specific server).
The layour and the url are then specific to the target repository.
You can then invoke the command as:
mvn deploy -DaltDeploymentRepository=test:Maven2:http://somewhere:someport
Where test is the id of a server element in your Maven settings
<servers>
<server>
<id>test</id>
<username>my_login</username>
<password>my_password</password>
</server>
</servers>
Update
Based on latest clarifications (via comments and edits), here some important points:
The Maven deploy phase is meant for
done in the build environment, copies the final package to the remote repository for sharing with other developers and projects.
Hence, in your case you don't need to use the deploy phase nor the maven-deploy-plugin.
Since Tomcat is the target server, you then need to use the tomcat7-maven-plugin
Here are few instructions:
Configure your pom.xml
Add to your pom.xml the following:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<url>http://localhost:8080/manager/text</url>
<server>tomcat8</server>
<path>/${project.build.finalName}</path>
</configuration>
</plugin>
Configure your settings.xml
Add to your Maven settings.xml the following in the servers section:
<server>
<username>maven</username>
<password>maven</password>
<id>tomcat8</id>
</server>
Note the matching tomcat8 id between the settings and the plugin configuration above, server element.
Configure Tomcat for deploy
In the tomcat conf folder, configure the tomcat-users.xml file:
<role rolename="manager-script"/>
<user username="maven" password="maven" roles="manager-gui,manager-script"/>
note the credentials matching with what we actually specified in the Maven settings.
Try it
Then from the command line you can finally invoke:
mvn tomcat7:deploy
If you don't want to configure settings.xml nor pom.xml, you then need to pass several parameters via command line as following:
mvn org.apache.tomcat.maven:tomcat7-maven-plugin:2.2:deploy \
-Durl=http://localhost:8080/manager/text \
-Dusername=maven -Dpassword=maven
Note: \ and newlines added for readibility
Check full list of options on the official documentation of its deploy goal.
#A_Di-Matteo's answer is correct for deploying to tomcat. But if you came here looking for how to deploy to a Maven repo without putting repo URLs in pom.xml then here's your answer:
mvn deploy -DskipTests -DaltDeploymentRepository=myrepoid::default::https://maven.example.org/repository/maven-releases
Instead of altDeploymentRepository, you could also use altReleaseDeploymentRepository or altSnapshotDeploymentRepository
More details in docs: https://maven.apache.org/plugins/maven-deploy-plugin/deploy-mojo.html
I added below dependency in pom.xml file:
<dependency>
<groupId>org.tuckey</groupId>
<artifactId>urlrewritefilter</artifactId>
<version>4.0.4</version>
</dependency>
I have alot of maven dependencies but when I add the one above I get:
Failed to read artifact descriptor for org.tuckey:urlrewritefilter:jar:4.0.4: Could not transfer artifact org.tuckey:urlrewritefilter:pom:4.0.4 from/to central (http://app1.stage.server.net/artifactory/libs-release): Not authorized, ReasonPhrase:Unauthorized. -> [Help 1]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
this is how the settings.xml file looks:
..
<servers>
<server>
<username>user</username>
<id>central</id>
<password>my-password</password>
</server>
<server>
<username>user</username>
<id>snapshots</id>
<password>my-password</password>
</server>
</servers>
<profiles>
...
</profiles>
<activeProfiles>
<activeProfile>artifactory</activeProfile>
</activeProfiles>
..
any help? tnx.
I faced this issue when my proxy server was not configured correctly for maven. You should check with your network administrator about proxy server and add the it in settings.xml under conf dir.
You can look for <proxies> tag and update the fields.
When I face this issue, I too felt it happened for just a few jars, but then all other required jar files were already present in my local repository and hence I was getting it for a few jars only.
I had this error trying to deploy to an internal instance of Nexus with a Maven client that was using proxies with no settings. Attempting to access a Nexus instance on the LAN via a proxy resulted in the Not authorized, ReasonPhrase:Unauthorized error.
<nonProxyHosts>internal.hostname</nonProxyHosts> fixed the issue.
Please check access of repository or password which had given in settings.xml
Adding this in case it helps someone else. In my case I was receiving this error and none of the solutions I found seemed to help. In the end I needed to add the config option to settings.xml to set interactiveMode to false.
If you are sure that your mirror links are configured properly in the settings.xml file, then please try this:
Navigate to .m2 -> repositories
Search for "lastupdated"
Delete all the files that come in the search result.
Then do a 'mvn clean install' -> new 'lastupdated' files would be created.
Try to changes groupId for the dependencies which you have added.
It work