Maven learning (seven): Using maven PW

A, maven PW structure

1, nexus warehouse type

1.1, hosted (hosted repository)

Deploy your own jar to this type of warehouse, including releases and a snapshot of two parts, internal Releases released version warehouse, internal test version Snapshots company warehouse.

1.2, proxy (proxy warehouse)

A remote repository for public agency, such as a central repository maven, the user connects PW, PW automatically downloaded to the central warehouse jar package or plug.

1.3, group (warehouse group)

To combine multiple hosted / proxy warehouse, we usually configure their connection maven warehouse group.

1.4, virtual (virtual)

Maven1 compatible version of the jar or plug-ins.

2, nexus warehouse

  • central: Acting warehouse, central warehouse agent
  • pache-snapshots: Agent warehouse, store snapshots member, proxy address https://repository.apache.org/snapshots/
  • central-m1: virtual warehouse type, compatible version of the jar or plug Maven1
  • releases: local repository, storage means releases.
  • snapshots: local repository, memory snapshots member.
  • thirdparty: third-party warehouse
  • public: Warehouse Group

Two, maven PW use

1, will publish a project to PW

1.1, the configuration file settings.xml in maven configure user and password to connect PW

1.2, configure address PW warehouse in pom.xml file for the project

    <!--配置私服仓库的地址-->
    <distributionManagement>
        <repository>
            <id>releases</id>
            <url>http://localhost:8081/nexus/content/repositories/releases/</url>
        </repository>
        <snapshotRepository>
            <id>snapshots</id>
            <url>http://localhost:8081/nexus/content/repositories/snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

2. Download jar package from PW

2.1, nexus open configuration repository group, as follows:

2.2, the configuration file settings.xml in maven repository configuration

	<profiles>
		<!-- 下载jar包配置 -->
		<profile>
			<!--profile的id -->
			<id>dev</id>
			<repositories>
				<repository> <!--仓库id,repositories可以配置多个仓库,保证id不重复 -->
					<id>nexus</id> <!--仓库地址,即nexus仓库组的地址 -->
					<url>http://localhost:8081/nexus/content/groups/public/</url> <!--是否下载releases构件 -->
					<releases>
						<enabled>true</enabled>
					</releases> <!--是否下载snapshots构件 -->
					<snapshots>
						<enabled>true</enabled>
					</snapshots>
				</repository>
			</repositories>
			<pluginRepositories> <!-- 插件仓库,maven的运行依赖插件,也需要从私服下载插件 -->
				<pluginRepository> <!-- 插件仓库的id不允许重复,如果重复后边配置会覆盖前边 -->
					<id>public</id>
					<name>Public Repositories</name>
					<url>http://localhost:8081/nexus/content/groups/public/</url>
				</pluginRepository>
			</pluginRepositories>
		</profile>
		<profile>    
			<id>jdk-1.8</id>    
			<activation>    
				<activeByDefault>true</activeByDefault>    
				<jdk>1.8</jdk>    
			</activation>    
			<properties>    
				<maven.compiler.source>1.8</maven.compiler.source>    
				<maven.compiler.target>1.8</maven.compiler.target>    
				<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>    
			</properties>     
		</profile>
	</profiles>

 2.3, activated using the profile defined warehouse, bring it into force.

<!--激活使用profile定义的仓库-->
<activeProfiles>
	<activeProfile>dev</activeProfile>
</activeProfiles>

3, third-party jar package into PW

1, server configuration information of a third party warehouse in the configuration file settings.xml maven's

<!--配置第三方仓库的server信息-->
<server>
	<id>thirdparty</id>
	<username>admin</username>
	<password>admin123</password>
</server>

2, the installation package to a third-party jar commands PW

mvn deploy:deploy-file -DgroupId=项目的名称 -DartifactId=jar包名称 -Dversion=jar包版本 -Dpackaging=jar -Dfile=jar包所在目录及jar包文件名 -Durl=私服下载地址 -DrepositoryId=thirdparty

如:
mvn deploy:deploy-file -DgroupId=com.alibaba -DartifactId=fastjson -Dversion=1.1.37 -Dpackaging=jar -Dfile=H:\Technology\Java\repository\fastjson-1.1.37.jar -Durl=http://localhost:8081/nexus/content/repositories/thirdparty/ -DrepositoryId=thirdparty

 

发布了134 篇原创文章 · 获赞 10 · 访问量 7336

Guess you like

Origin blog.csdn.net/yu1755128147/article/details/104034734