maven 提交jar文件到私库

      maven 提交jar文件到私库无评论

由于一些特殊原因需要把特定的jar文件发布到私有的maven库,方便发布和打包使用。下边给出简单的步骤和说明。

  1. 准备jar 文件, maven的配置文件和pom.xml
  2. maven的配置文件settings.xml 需要添加私库的用户信息
    1. <server>
      <username>{username}</username>
      <password>{password}</password>
      <id>{registryId}</id>
      </server>
  3. pom.xml文件需要添加如下信息:
    1. groupid
    2. version
    3. artifactId
    4. name
    5. distributionManagement
    6. 示例如下:
    7. <?xml version=”1.0″?>
      <project
      xsi:schemaLocation=”http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd”
      xmlns=”http://maven.apache.org/POM/4.0.0″
      xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”>
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.abc.xxx</groupId>
      <version>x.x.x</version>
      <artifactId>{artifactId}</artifactId>
      <name>{artifactId}</name><distributionManagement>
      <repository>
      <id>central</id>
      <name>artifactory-xxxxx-releases</name>
      <url>https://{私库地址}/artifactory/{maven artifactoryId}</url>
      </repository>
      <snapshotRepository>
      <id>snapshots</id>
      <name>artifactory-xxxxx-snapshots</name>
      <url>https://{私库地址}/artifactory/{maven artifactoryId}</url>
      </snapshotRepository>
      </distributionManagement></project>
  4. 复制jar文件和pom.xml到同一个目录,执行下边的命令
    1. mvn deploy:deploy-file -DgroupId={groupId} -DartifactId={DartifactId} -Dversion={version} -Dpackaging=jar -DrepositoryId={registryId 在settings.xml} -Dfile={jar文件} -DpomFile=pom.xml -Durl=https://{私库地址}/artifactory/{maven artifactoryId}
    2. pomFile是必须的,否则会自动创建一个文件,但是会导致jar无法使用
    3. url 和server的认证信息和ID要是正确的,路径也得正确
    4. 如果jar有其他的依赖,可以添加-Dclassifier=jar-with-dependencies
    5. 其他参数可以mvn –help查看

沟通交流合作请加微信!