23) maven deploy:deploy-file 插件部署jar和pom

发布时间 2023-06-01 17:12:49作者: zno2

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

NameTypeSinceDescription
<file> File - File to be deployed.
User property isfile.
<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 isremote-repository.
User property isrepositoryId.
<url> String - URL where the artifact will be deployed.
ie ( file:///C:/m2-repo or scp://host.com/path/to/repo )
User property isurl.

Optional Parameters

NameTypeSinceDescription
<artifactId> String - ArtifactId of the artifact to be deployed. Retrieved from POM file if specified.
User property isartifactId.
<classifier> String - Add classifier to the artifact
User property isclassifier.
<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 isclassifiers.
<description> String - Description passed to a generated POM file (in case of generatePom=true)
User property isgeneratePom.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 isfiles.
<generatePom> boolean - Upload a POM for this artifact. Will generate a default POM if none is supplied with the pomFile argument.
Default value istrue.
User property isgeneratePom.
<groupId> String - GroupId of the artifact to be deployed. Retrieved from POM file if specified.
User property isgroupId.
<javadoc> File 2.6 The bundled API docs for the artifact.
User property isjavadoc.
<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 ispackaging.
<pomFile> File - Location of an existing POM file to be deployed alongside the main artifact, given by the ${file} parameter.
User property ispomFile.
<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 is1.
User property isretryFailedDeploymentCount.
<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:
  • true: will skip as usual
  • releases: will skip if current version of the project is a release
  • snapshots: will skip if current version of the project is a snapshot
  • any other values will be considered as false

Default value isfalse.
User property ismaven.deploy.file.skip.
<sources> File 2.6 The bundled sources for the artifact.
User property issources.
<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 istypes.
<version> String - Version of the artifact to be deployed. Retrieved from POM file if specified.
User property isversion.

Parameter Details

<artifactId>

ArtifactId of the artifact to be deployed. Retrieved from POM file if specified.
  • Typejava.lang.String
  • RequiredNo
  • User PropertyartifactId

<classifier>

Add classifier to the artifact
  • Typejava.lang.String
  • RequiredNo
  • User Propertyclassifier

<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.
  • Typejava.lang.String
  • RequiredNo
  • User Propertyclassifiers

<description>

Description passed to a generated POM file (in case of generatePom=true)
  • Typejava.lang.String
  • RequiredNo
  • User PropertygeneratePom.description

<file>

File to be deployed.
  • Typejava.io.File
  • RequiredYes
  • User Propertyfile

<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.
  • Typejava.lang.String
  • RequiredNo
  • User Propertyfiles

<generatePom>

Upload a POM for this artifact. Will generate a default POM if none is supplied with the pomFile argument.
  • Typeboolean
  • RequiredNo
  • User PropertygeneratePom
  • Defaulttrue

<groupId>

GroupId of the artifact to be deployed. Retrieved from POM file if specified.
  • Typejava.lang.String
  • RequiredNo
  • User PropertygroupId

<javadoc>

The bundled API docs for the artifact.
  • Typejava.io.File
  • Since2.6
  • RequiredNo
  • User Propertyjavadoc

<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.
  • Typejava.lang.String
  • RequiredNo
  • User Propertypackaging

<pomFile>

Location of an existing POM file to be deployed alongside the main artifact, given by the ${file} parameter.
  • Typejava.io.File
  • RequiredNo
  • User PropertypomFile

<repositoryId>

Server Id to map on the <id> under <server> section of settings.xml In most cases, this parameter will be required for authentication.
  • Typejava.lang.String
  • RequiredYes
  • User PropertyrepositoryId
  • Defaultremote-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.
  • Typeint
  • Since2.7
  • RequiredNo
  • User PropertyretryFailedDeploymentCount
  • Default1

<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 usual
  • releases: will skip if current version of the project is a release
  • snapshots: will skip if current version of the project is a snapshot
  • any other values will be considered as false
  • Typejava.lang.String
  • Since3.1.0
  • RequiredNo
  • User Propertymaven.deploy.file.skip
  • Defaultfalse

<sources>

The bundled sources for the artifact.
  • Typejava.io.File
  • Since2.6
  • RequiredNo
  • User Propertysources

<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.
  • Typejava.lang.String
  • RequiredNo
  • User Propertytypes

<url>

URL where the artifact will be deployed.
ie ( file:///C:/m2-repo or scp://host.com/path/to/repo )
  • Typejava.lang.String
  • RequiredYes
  • User Propertyurl

<version>

Version of the artifact to be deployed. Retrieved from POM file if specified.
    • Typejava.lang.String
    • RequiredNo
    • User Propertyversion