| 1 |
------ |
| 2 |
Deploying With Network Issues |
| 3 |
------ |
| 4 |
Hervé Boutemy |
| 5 |
------ |
| 6 |
2019-01-20 |
| 7 |
------ |
| 8 |
|
| 9 |
~~ Licensed to the Apache Software Foundation (ASF) under one |
| 10 |
~~ or more contributor license agreements. See the NOTICE file |
| 11 |
~~ distributed with this work for additional information |
| 12 |
~~ regarding copyright ownership. The ASF licenses this file |
| 13 |
~~ to you under the Apache License, Version 2.0 (the |
| 14 |
~~ "License"); you may not use this file except in compliance |
| 15 |
~~ with the License. You may obtain a copy of the License at |
| 16 |
~~ |
| 17 |
~~ http://www.apache.org/licenses/LICENSE-2.0 |
| 18 |
~~ |
| 19 |
~~ Unless required by applicable law or agreed to in writing, |
| 20 |
~~ software distributed under the License is distributed on an |
| 21 |
~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 22 |
~~ KIND, either express or implied. See the License for the |
| 23 |
~~ specific language governing permissions and limitations |
| 24 |
~~ under the License. |
| 25 |
|
| 26 |
~~ NOTE: For help with the syntax of this file, see: |
| 27 |
~~ http://maven.apache.org/doxia/references/apt-format.html |
| 28 |
|
| 29 |
Deploying With Network Issues |
| 30 |
|
| 31 |
Sometimes, network quality from building machine to the remote repository is not perfect. |
| 32 |
Of course, improving the network would be the best solution, but it is not always possible. |
| 33 |
|
| 34 |
There are a few strategies to work around the network issue. |
| 35 |
|
| 36 |
* Configuring Multiple Tries |
| 37 |
|
| 38 |
Deploy plugin provides {{{../deploy-mojo.html#retryFailedDeploymentCount}<<<retryFailedDeploymentCount>>> parameter}} |
| 39 |
to retry deployment multiple times before giving up and returning a failure for the <<<deploy>>> goal: |
| 40 |
|
| 41 |
+----+ |
| 42 |
<project> |
| 43 |
[...] |
| 44 |
<build> |
| 45 |
<plugins> |
| 46 |
<plugin> |
| 47 |
<groupId>org.apache.maven.plugins</groupId> |
| 48 |
<artifactId>maven-deploy-plugin</artifactId> |
| 49 |
<configuration> |
| 50 |
<retryFailedDeploymentCount>3</retryFailedDeploymentCount> |
| 51 |
<configuration> |
| 52 |
</plugin> |
| 53 |
</plugins> |
| 54 |
</build> |
| 55 |
[...] |
| 56 |
</project> |
| 57 |
+----+ |
| 58 |
|
| 59 |
* Deploying to a Local Staging Directory |
| 60 |
|
| 61 |
When the network is really not consistent, a deeper strategy is to deploy in 2 steps: |
| 62 |
|
| 63 |
1. <<<deploy>>> to a local directory during the build, for example <<<file:./target/staging-deploy>>>, |
| 64 |
|
| 65 |
2. then copy from the local area to the target remote repository, retrying as much as necessary. |
| 66 |
|
| 67 |
[] |
| 68 |
|
| 69 |
** Deploying to a Local Directory |
| 70 |
|
| 71 |
Deploying to a local directory can be done from command line, without changing POM, using |
| 72 |
{{{../deploy-mojo.html#altDeploymentRepository}<<<altDeploymentRepository>>> parameter}}: |
| 73 |
|
| 74 |
+----+ |
| 75 |
mvn deploy -DaltDeploymentRepository=local::file:./target/staging-deploy |
| 76 |
+----+ |
| 77 |
|
| 78 |
or for older 2.x version of maven-deploy-plugin |
| 79 |
|
| 80 |
+----+ |
| 81 |
mvn deploy -DaltDeploymentRepository=local::default::file:./target/staging-deploy |
| 82 |
+----+ |
| 83 |
|
| 84 |
Of course, you can configure the repository in your <<<pom.xml>>> if you want to go from a temporary strategy |
| 85 |
to the general strategy. |
| 86 |
|
| 87 |
** Copying from Local Directory to Target Remote Repository |
| 88 |
|
| 89 |
<<<wagon-maven-plugin>>>'s {{{https://www.mojohaus.org/wagon-maven-plugin/merge-maven-repos-mojo.html}<<<merge-maven-repos>>> goal}} |
| 90 |
provides a mechanism to copy from one remote repository to the other, while merging repository metadata. |
| 91 |
|
| 92 |
<<<wagon-maven-plugin>>>'s {{{https://www.mojohaus.org/wagon-maven-plugin/upload-mojo.html}<<<upload>>> goal}} |
| 93 |
will do the same without taking care of repository metadata: use it if you have an empty repository as target, |
| 94 |
like a staging repository provided by a repository manager. |
| 95 |
|
| 96 |
It can be invoked fully from command line (renaming <<<-Dwagon.>>> with <<<wagon.targetId>>> when |
| 97 |
{{{https://github.com/mojohaus/wagon-maven-plugin/pull/26}Wagon Maven Plugin 2.0.1 will be released}}): |
| 98 |
|
| 99 |
+----+ |
| 100 |
mvn org.codehaus.mojo:wagon-maven-plugin:2.0.0:merge-maven-repos \ |
| 101 |
-Dwagon.source=file:./target/staging-deploy \ |
| 102 |
-Dwagon.target=https://... \ |
| 103 |
-Dwagon.=id |
| 104 |
# or once wagon-maven-plugin 2.0.1 is released: |
| 105 |
-Dwagon.targetId=id |
| 106 |
+----+ |
| 107 |
|
| 108 |
or more simply with <<<mvn wagon:merge-maven-repos>>> with configuration in <<<pom.xml>>>: |
| 109 |
|
| 110 |
+----+ |
| 111 |
<project> |
| 112 |
[...] |
| 113 |
<build> |
| 114 |
<plugins> |
| 115 |
<plugin> |
| 116 |
<groupId>org.codehaus.mojo</groupId> |
| 117 |
<artifactId>wagon-maven-plugin</artifactId> |
| 118 |
<version>2.0.0</version> |
| 119 |
<configuration> |
| 120 |
<source>file:./target/staging-deploy</source> |
| 121 |
<target>${project.distributionManagement.repository.url}</target> |
| 122 |
<targetId>${project.distributionManagement.repository.id}</targetId> |
| 123 |
</configuration> |
| 124 |
</plugin> |
| 125 |
</plugins> |
| 126 |
</build> |
| 127 |
[...] |
| 128 |
</project> |
| 129 |
+----+ |