maven本地仓库--各种好玩的配置

目录

前提

1.自定义配置本地仓库目录

2.设置maven依赖的jdk版本

3.使用指定的阿里云maven中央仓库

4.配置私有仓库(假如所有的maven项目都使用私服,例如nexus3)

5.使用本地仓库的jar包,禁止从远端(有可能是外网的中央仓库,有可能是私服nexus3)下载

6.将本地jar包导入本地仓库

7.将本地jar包导入私服nexus的maven库中

8.将本地项目发布到Nexus私服


前提

下载并解压maven客户端apache-maven-3.6.3-bin.zip

1.自定义配置本地仓库目录

打开apache-maven-3.6.3\conf\settings.xml文件,查找内容如下:

去掉注释,并修改成:

D:/maven/local_repos

2.设置maven依赖的jdk版本

打开apache-maven-3.6.3\conf\settings.xml文件,查找内容如下:

去掉注释,并修改成:


	jdk-1.8    
	    
		true    
		1.8    
	
	    
		1.8    
		1.8    
		1.8    
	

3.使用指定的阿里云maven中央仓库

打开apache-maven-3.6.3\conf\settings.xml文件,查找内容如下:


去掉注释,并修改成:


  alimven
  central
  aliyun maven
  http://maven.aliyun.com/nexus/content/groups/public/

4.配置私有仓库(假如所有的maven项目都使用私服,例如nexus3)

打开apache-maven-3.6.3\conf\settings.xml文件,

1.查找内容如下:


去掉注释,并修改成:


  nexus_release
  nexus maven
  http://ip地址:8081/repository/子目录/
  *        

2.然后,查找内容如下:

去掉注释,并修改成:


  nexus_release
  登录私服的用户名
  登录私服的密码

3.然后,查找内容如下:

去掉注释,并修改成:


   nexus_profile
   
	 
	     nexus
	      http://私服ip地址:8081/repository/子目录/
	      
                true
          
	      
              true
          
	 
   
   
       
	       nexus
	       http://私服ip地址:8081/repository/子目录/
	       
		       true
	       
	       
		       true
	       
	   
    

4.最后,查找内容如下:

去掉注释,并修改成:


    nexus_profile

5.使用本地仓库的jar包,禁止从远端(有可能是外网的中央仓库,有可能是私服nexus3)下载

打开apache-maven-3.6.3\conf\settings.xml文件,查找内容如下:

去掉注释,并修改成:

true

6.将本地jar包导入本地仓库

mvn install:install-file -DgroupId=jar包的GID -DartifactId=jar包的AID -Dversion=Jar包的版本 -Dpackaging=jar -Dfile=你本地jar包的目录

例子:
mvn install:install-file -DgroupId=org.springframework -DartifactId=spring-webmvc -Dversion=3.0.5.RELEASE -Dpackaging=jar -Dfile=D:/spring.jar

7.将本地jar包导入私服nexus的maven库中

举个例子,前提是记得检查一下maven的类型是hosted类型,如果是group类型,需要进一步确定包含的hosted类型的依赖库是哪个,其中-Durl的路径是hosted类型的依赖库

mvn deploy:deploy-file -DgroupId=com.shanhy -DartifactId=shanhy-web-core -Dversion=1.1.0-SNAPSHOT -Dpackaging=jar -Dfile=shanhy-web-core-5.1.17-SNAPSHOT.jar -Durl=http://admin:[email protected]:8081/repository/maven-snapshots/

还可以指定文件格式是.pom文件进行导入,如果这个jar本来依赖了其他的库(可以打开jar包在META-INF最里面可以找到pom.xml文件),仅使用上面的命令,资源库中对应jar包的pom文件不会出现依赖的jar包。

-DpomFile=shanhy-web-core-5.1.17-SNAPSHOT.pom

8.将本地项目发布到Nexus私服

1.查看当前正在使用的settings.xml

mvn help:effective-settings

2.pom.xml文件中加入如下配置



	
	
		
		releases
		
		RELEASES PUBLISH
		
		http://xx.xx.xx.xx:xxxx/repository/maven-releases/
	
	
	
		
		snapshots
		
		SNAPSHOTS PUBLISH
		
		http://xx.xx.xx.xx:xxxx/repository/maven-snapshots/
	

3.在settings.xml文件中加入如下配置

 
    releases
    私服的用户名	
    私服的密码
 
 
    snapshots
    私服的用户名
    私服的密码
 

4.将本地项目发布到Nexus私服

mvn clean deploy

5.发生如下错误可能是配置的账号信息有误的原因

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project demo-childA: Failed to deploy artifacts: Could not transfer artifact com.ecp:demo-childA:jar:1.0-20190625.082808-
1 from/to maven-snapshots (http://xx.xxx.xx.xx:xxxx/repository/maven-snapshots/): Failed to transfer file http://xx.xxx.xx.xx:xxxx/repository/maven-snapshots/com/ecp/demo-childA/1.0-SNAPSHOT/demo-childA-1.0-20190625.082808-1
.jar with status code 401 -> [Help 1]

可以使用:mvn help:effective-settings命令查看settings.xml配置文件查看配置信息

你可能感兴趣的:(maven,java)