23) maven deploy:deploy-file 插件部署jar和pom
http://maven.apache.org/plugins/maven-deploy-plugin/deploy-file-mojo.html
1. 为什么用这个插件
想直接上传文件到仓库,而不是部署maven项目到仓库
2. 部署哪个文件?file
3. 部署到哪?url
4. 部署时权限怎么处理? repositoryId
5. 部署的package 等信息?groupId artifactId version packaging
I
mvn deploy:deploy-file -Dfile=a.jar -DartifactId=a -DgroupId=g -Dversion=1.0 -Dpackaging=jar -Durl=http://xxxxx/nexus/content/repositories/releases -DrepositoryId=Releases mvn deploy:deploy-file -Dfile=b.jar -DartifactId=b -DgroupId=g -Dversion=1.0 -Dpackaging=jar -Durl=http://xxxxx/nexus/content/repositories/releases -DrepositoryId=Releases
权限信息在 maven的配置文件中
<servers> <server> <id>Releases</id> <username>user01</username> <password>changeit</password> </server> <server> <id>Snapshots</id> <username>user01</username> <password>changeid</password> </server> </servers>
对应的pom中的信息是:
<distributionManagement> <repository> <id>Releases</id> <name>Internal Releases</name> <url>http://xxxxx/nexus/content/repositories/releases</url> </repository> <snapshotRepository> <id>Snapshots</id> <name>Internal Snapshots</name> <url>http://xxxxx/nexus/content/repositories/snapshots</url> </snapshotRepository> </distributionManagement>
II
还可以上传pom文件,相较jar这个需要指定pomFile
mvn deploy:deploy-file -Dfile=pom.xml -DpomFile=pom.xml -Dpackaging=pom -Durl=http://xxxxx/nexus/content/repositories/snapshots -DrepositoryId=Snapshots
file 可以是相对路径和绝对路径,能找到就可以
III 两个本地测试例子
这个插件运行时不需要在maven 项目根目录(包含pom.xml),即任意目录均可
F:\>mvn deploy:deploy-file -Dfile=a.jar -DartifactId=a -DgroupId=g -Dversion=1.0 -Dpackaging=jar -Durl=file:///C:/Users/wl/.m2/repository [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building Maven Stub Project (No POM) 1 [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-deploy-plugin:2.7:deploy-file (default-cli) @ standalone-pom --- Uploading: file:///C:/Users/wl/.m2/repository/g/a/1.0/a-1.0.jar Uploaded: file:///C:/Users/wl/.m2/repository/g/a/1.0/a-1.0.jar (1060 KB at 8901.8 KB/sec) Uploading: file:///C:/Users/wl/.m2/repository/g/a/1.0/a-1.0.pom Uploaded: file:///C:/Users/wl/.m2/repository/g/a/1.0/a-1.0.pom (373 B at 72.9 KB/sec) Downloading: file:///C:/Users/wl/.m2/repository/g/a/maven-metadata.xml Uploading: file:///C:/Users/wl/.m2/repository/g/a/maven-metadata.xml Uploaded: file:///C:/Users/wl/.m2/repository/g/a/maven-metadata.xml (278 B at 90.5 KB/sec) [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.823 s [INFO] Finished at: 2016-12-15T13:33:27+08:00 [INFO] Final Memory: 7M/75M [INFO] ------------------------------------------------------------------------
F:\>mvn deploy:deploy-file -Dfile=pom.xml -DpomFile=pom.xml -Dpackaging=pom -Durl=file:///C:/Users/wl/.m2/repository [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building z-test2 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-deploy-plugin:2.7:deploy-file (default-cli) @ z-test2 --- Downloading: file:///C:/Users/wl/.m2/repository/cn/zno/z-test2/0.0.1-SNAPSHOT/maven-metadata.xml Downloaded: file:///C:/Users/wl/.m2/repository/cn/zno/z-test2/0.0.1-SNAPSHOT/maven-metadata.xml (590 B at 3.7 KB/sec) Uploading: file:///C:/Users/wl/.m2/repository/cn/zno/z-test2/0.0.1-SNAPSHOT/z-test2-0.0.1-20161215.054005-2.pom Uploaded: file:///C:/Users/wl/.m2/repository/cn/zno/z-test2/0.0.1-SNAPSHOT/z-test2-0.0.1-20161215.054005-2.pom (4 KB at 300.3 KB/sec) Downloading: file:///C:/Users/wl/.m2/repository/cn/zno/z-test2/maven-metadata.xml Downloaded: file:///C:/Users/wl/.m2/repository/cn/zno/z-test2/maven-metadata.xml (273 B at 3.7 KB/sec) Uploading: file:///C:/Users/wl/.m2/repository/cn/zno/z-test2/0.0.1-SNAPSHOT/maven-metadata.xml Uploaded: file:///C:/Users/wl/.m2/repository/cn/zno/z-test2/0.0.1-SNAPSHOT/maven-metadata.xml (590 B at 96.0 KB/sec) Uploading: file:///C:/Users/wl/.m2/repository/cn/zno/z-test2/maven-metadata.xml Uploaded: file:///C:/Users/wl/.m2/repository/cn/zno/z-test2/maven-metadata.xml (273 B at 44.4 KB/sec) [INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO] ------------------------------------------------------------------------ [INFO] Total time: 0.921 s [INFO] Finished at: 2016-12-15T13:40:05+08:00 [INFO] Final Memory: 6M/111M [INFO] ------------------------------------------------------------------------
鉴于经常无法访问,将页面内容保存至此
deploy:deploy-file
Full name:
org.apache.maven.plugins:maven-deploy-plugin:3.1.0:deploy-file
Description:
Installs the artifact in the remote repository.
Attributes:
- The goal is thread-safe and supports parallel builds.
Required Parameters
Name | Type | Since | Description |
---|---|---|---|
<file> |
File |
- |
File to be deployed. User property is: file . |
<repositoryId> |
String |
- |
Server Id to map on the <id> under <server> section of settings.xml In most cases, this parameter will be required for authentication. Default value is: remote-repository .User property is: repositoryId . |
<url> |
String |
- |
URL where the artifact will be deployed. ie ( file:///C:/m2-repo or scp://host.com/path/to/repo ) User property is: url . |
Optional Parameters
Name | Type | Since | Description |
---|---|---|---|
<artifactId> |
String |
- |
ArtifactId of the artifact to be deployed. Retrieved from POM file if specified. User property is: artifactId . |
<classifier> |
String |
- |
Add classifier to the artifact User property is: classifier . |
<classifiers> |
String |
- |
A comma separated list of classifiers for each of the extra side artifacts to deploy. If there is a mis-match in the number of entries in files or types , then an error will be raised.User property is: classifiers . |
<description> |
String |
- |
Description passed to a generated POM file (in case of generatePom=true) User property is: generatePom.description . |
<files> |
String |
- |
A comma separated list of files for each of the extra side artifacts to deploy. If there is a mis-match in the number of entries in types or classifiers , then an error will be raised.User property is: files . |
<generatePom> |
boolean |
- |
Upload a POM for this artifact. Will generate a default POM if none is supplied with the pomFile argument. Default value is: true .User property is: generatePom . |
<groupId> |
String |
- |
GroupId of the artifact to be deployed. Retrieved from POM file if specified. User property is: groupId . |
<javadoc> |
File |
2.6 |
The bundled API docs for the artifact. User property is: javadoc . |
<packaging> |
String |
- |
Type of the artifact to be deployed. Retrieved from the <packaging> element of the POM file if a POM file specified. Defaults to the file extension if it is not specified via command line or POM. Maven uses two terms to refer to this datum: the <packaging> element for the entire POM, and the <type> element in a dependency specification. User property is: packaging . |
<pomFile> |
File |
- |
Location of an existing POM file to be deployed alongside the main artifact, given by the ${file} parameter. User property is: pomFile . |
<retryFailedDeploymentCount> |
int |
2.7 |
Parameter used to control how many times a failed deployment will be retried before giving up and failing. If a value outside the range 1-10 is specified it will be pulled to the nearest value within the range 1-10. Default value is: 1 .User property is: retryFailedDeploymentCount . |
<skip> |
String |
3.1.0 |
Set this to 'true' to bypass artifact deploy It's not a real boolean as it can have more than 2 values:
Default value is: false .User property is: maven.deploy.file.skip . |
<sources> |
File |
2.6 |
The bundled sources for the artifact. User property is: sources . |
<types> |
String |
- |
A comma separated list of types for each of the extra side artifacts to deploy. If there is a mis-match in the number of entries in files or classifiers , then an error will be raised.User property is: types . |
<version> |
String |
- |
Version of the artifact to be deployed. Retrieved from POM file if specified. User property is: version . |
Parameter Details
<artifactId>
ArtifactId of the artifact to be deployed. Retrieved from POM file if specified.
- Type:
java.lang.String
- Required:
No
- User Property:
artifactId
<classifier>
Add classifier to the artifact
- Type:
java.lang.String
- Required:
No
- User Property:
classifier
<classifiers>
A comma separated list of classifiers for each of the extra side artifacts to deploy. If there is a mis-match in the number of entries in
files
or types
, then an error will be raised.- Type:
java.lang.String
- Required:
No
- User Property:
classifiers
<description>
Description passed to a generated POM file (in case of generatePom=true)
- Type:
java.lang.String
- Required:
No
- User Property:
generatePom.description
<file>
File to be deployed.
- Type:
java.io.File
- Required:
Yes
- User Property:
file
<files>
A comma separated list of files for each of the extra side artifacts to deploy. If there is a mis-match in the number of entries in
types
or classifiers
, then an error will be raised.- Type:
java.lang.String
- Required:
No
- User Property:
files
<generatePom>
Upload a POM for this artifact. Will generate a default POM if none is supplied with the pomFile argument.
- Type:
boolean
- Required:
No
- User Property:
generatePom
- Default:
true
<groupId>
GroupId of the artifact to be deployed. Retrieved from POM file if specified.
- Type:
java.lang.String
- Required:
No
- User Property:
groupId
<javadoc>
The bundled API docs for the artifact.
- Type:
java.io.File
- Since:
2.6
- Required:
No
- User Property:
javadoc
<packaging>
Type of the artifact to be deployed. Retrieved from the <packaging> element of the POM file if a POM file specified. Defaults to the file extension if it is not specified via command line or POM.
Maven uses two terms to refer to this datum: the <packaging> element for the entire POM, and the <type> element in a dependency specification.
Maven uses two terms to refer to this datum: the <packaging> element for the entire POM, and the <type> element in a dependency specification.
- Type:
java.lang.String
- Required:
No
- User Property:
packaging
<pomFile>
Location of an existing POM file to be deployed alongside the main artifact, given by the ${file} parameter.
- Type:
java.io.File
- Required:
No
- User Property:
pomFile
<repositoryId>
Server Id to map on the <id> under <server> section of settings.xml In most cases, this parameter will be required for authentication.
- Type:
java.lang.String
- Required:
Yes
- User Property:
repositoryId
- Default:
remote-repository
<retryFailedDeploymentCount>
Parameter used to control how many times a failed deployment will be retried before giving up and failing. If a value outside the range 1-10 is specified it will be pulled to the nearest value within the range 1-10.
- Type:
int
- Since:
2.7
- Required:
No
- User Property:
retryFailedDeploymentCount
- Default:
1
<skip>
Set this to 'true' to bypass artifact deploy It's not a real boolean as it can have more than 2 values:
true
: will skip as usualreleases
: will skip if current version of the project is a releasesnapshots
: will skip if current version of the project is a snapshot- any other values will be considered as
false
- Type:
java.lang.String
- Since:
3.1.0
- Required:
No
- User Property:
maven.deploy.file.skip
- Default:
false
<sources>
The bundled sources for the artifact.
- Type:
java.io.File
- Since:
2.6
- Required:
No
- User Property:
sources
<types>
A comma separated list of types for each of the extra side artifacts to deploy. If there is a mis-match in the number of entries in
files
or classifiers
, then an error will be raised.- Type:
java.lang.String
- Required:
No
- User Property:
types
<url>
URL where the artifact will be deployed.
ie ( file:///C:/m2-repo or scp://host.com/path/to/repo )
ie ( file:///C:/m2-repo or scp://host.com/path/to/repo )
- Type:
java.lang.String
- Required:
Yes
- User Property:
url
<version>
Version of the artifact to be deployed. Retrieved from POM file if specified.
- Type:
java.lang.String
- Required:
No
- User Property:
version