Maven uses the deploy command to deploy and build
For details about how to use the deploy command to deploy components on the nexus server, refer to the classic Maven Definitive Guide (Maven Operation Guide), which is described in section 16.7 in this document. Assume that the settings of the maven server in the Pom. xml file are as follows:
Nexus-releases Local nexus Repository Http: // 192.168.1.99: 8081/content/repositories/releases Nexus-snapshots Local nexus Repository Http: // 192.168.1.99: 8081/content/repositories/snapshots
Here I want to talk about the "failed to transfer file" errors encountered during usage. The error message is in the following format:
Error deploying artifact: failed to transfer file :... Return code is: 4xx
That is to say, the preceding error information is the same, but the returned HTTP status numbers are different.
1. Return code is: 405
This problem caused me to find out the root cause of the error after more than two hours. The simple error is that an HTTP 405 error occurs when Maven is executed to upload files to the server. At the beginning, I thought it was a Maven issue, so I wasted a lot of time on it. Later, I checked the meaning of the 405 error carefully: "The HTTP method used to access this page is not allowed." Finally, I found that the previous repository address was wrong, or the port was wrong, or a word in the address is spelled incorrectly. The reason is that the repository address is wrong.
2. Return code is: 401 or return code is: 403
In fact, the 403 error is the meaning of "Access prohibited", so the root cause of the problem must be authorization. Maven uses the deployment account (default password: deploy) to log on to the system by default. However, in the key nexus, the default deployment policy of the releases repository is "Disable redeploy ", so the problem of deployment failure lies in this place. You can change it to "allow redeploy.
This is not over yet, because if you directly follow the above settings, there will be a security problem, that is, all developers can deploy the components to the releases repository of nexus, A long time may cause chaos in the repository, which should also be the reason why nexus disabled the publishing permission of the release repository by default. To solve this problem, you need to use the username and password to log on to the deployment component. The operation is as follows:
(1) first, change the default deployment policy of the releases repository to "allow redeploy ";
(2) In the users under security on the right, modify the password of the deployment account by right-clicking the account and selecting "set password" (PS: I have been searching for this operation for a long time, and then I accidentally right-click it to find it, haha ~~);
(3) If the MVN deploy command is directly executed at this time, the 401 error will occur again. Another step is to set the password to Maven settings. xml. Open the settings. xml file ($ {user. Home}/. M/settings. xml or % {m2_home}/CONF/settings. XML) and find And then modify the information as follows:
Nexus-releases Deployment Deploydv89 Nexus-snapshots Deployment Deploydv89
Note that the ID must be consistent with the repository ID you set under distributionmanagement In the Pom. xml file of the project! Of course, you can also set an admin account or manually add a new account by referring to the permissions of deployment.
Of course, the problem has been completely liberated here, but it is not safe to directly put the account password in the configuration file if someone needs to be honest. As long as the admin account is not recommended, deployment cannot log on. To be safer, you can also use the password encryption feature provided after Maven 2.1.0. The procedure is as follows:
(1) Use "MVN-encrypt-master-Password XXX" or "MVN-emp xxx" to create a master key. The xxx following is the content of the key you want to set, this key is mainly used for subsequent encryption passwords. After the command is executed, a string similar to {jsmownopfgshvpmvz5vrit5krbzgpi8u + 9ef1ifqyjq =} is generated.
(2) create a file named settings-security.xml in the $ {user. Home}/. M/directory and place the generated master key in the file. The content of the file is as follows:
{Jsmownopfgshvpmvz5vrit5krbzgpi8u + 9ef1ifqyjq =}
Note that this settings-security.xml file must be placed under the $ {user. Home}/. M/directory, rather than under the $ {m2_home}/conf directory!
(3) Use the "MVN-encrypt-Password XXX" or "MVN-ep xxx" command to encrypt the password of the Account. The following XXX is the password of the account, after encryption, a "{XXX}" string will still be generated, replacing the string with the preceding settings. the content of the password node under the server in the XML file.
Another safer way is to put the master key in the USB flash drive. For more information, see the following references.
3. Return code is: 400
400 Error indicates "wrong request", which is often because it is not deployed in the nexus repository. Nexus repository has three types: hosted, proxy, and virtual. In addition, a repository group is used to combine multiple warehouses. You can only deploy the service to a hosted-type warehouse during deployment. If it is another type, this 400 error occurs.
In another case, the 400 error occurs, that is, by default, when the component is deployed to the releases warehouse, the 400 error occurs sometimes, as mentioned above, the default deployment policy of the releases repository in nexus is "Disable redeploy. if the username of the server is set to deployment or admin in the XML file, this 400 error occurs. This problem has also plagued me for a long time, and I also saw some people on the internet saying that admin has no permission to deploy components, which is wrong. For the modification method, refer to the above 2nd practices.