当前位置:   article > 正文

maven打包上传到私有仓库的步骤_maven上传到私有仓库

maven上传到私有仓库


先准备私库地址:
http://localhost:8081/nexus3/repository/maven-releases
http://localhost:8081/nexus3/repository/maven-snapshots
假如现需要将私有的jar发布到私库,步骤过程如下:

一、pom.xml引入

如果发布到releases私库(与build标签平级放入)

    <distributionManagement>
        <repository>
            <id>releases</id>
            <url>http://localhost:8081/nexus3/repository/maven-releases/</url>
        </repository>
    </distributionManagement>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

如果发布到snapshots私库(与build标签平级放入)

    <distributionManagement>
        <snapshotRepository>
            <id>snapshots</id>
            <url>http://localhost:8081/nexus3/repository/maven-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

二、Maven的settings.xml

在servers标签下增加如下配置,配置发布到私库的账号和密码(如nexus3的账号admin和密码admin123)

    <server>
      <id>releases</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
    <server>
      <id>snapshots</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

三、pom.xml中添加源码插件

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<java.version>1.8</java.version>
	</properties>
  • 1
  • 2
  • 3
  • 4
			<!-- 编译插件 -->
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-compiler-plugin</artifactId>
				<configuration>
					<encoding>${project.build.sourceEncoding}</encoding>
					<source>${java.version}</source>
					<target>${java.version}</target>
					<compilerArgs>
						<arg>-parameters</arg>
					</compilerArgs>
				</configuration>
			</plugin>
			<!-- Source attach plugin -->
			<plugin>
			    <groupId>org.apache.maven.plugins</groupId>
			    <artifactId>maven-source-plugin</artifactId>
			    <executions>
			        <execution>
			            <id>attach-sources</id>
			            <goals>
			                <goal>jar</goal>
			            </goals>
			        </execution>
			    </executions>
			</plugin>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

四、执行发布命令

mvn clean deploy
  • 1
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/blog/article/detail/48451
推荐阅读
相关标签
  

闽ICP备14008679号