maven2

文章链接:http://www.liuschen.com

maven同gradle以及git,svn等版本控制软件一样,都有局部设置(用户的目录下都有一个默认的.m2/repository/路径作为本地仓库,.m2文件夹中的settings.xml)和全局设置(maven目录下config中的settings.xml)。

maven的远程仓库分为中央仓库,和私服。中央仓库时默认的,因为新建的pom.xml默认继承了超级pom.xml而这个超级pom.xml配置了中央仓库的地址。可以在pom.xml中配置其他仓库地址:

<repositories>  
<repository>  
  <id>central</id>  
  <name>Central Repository</name>  
  <url>http://repo.maven.apache.org/maven2</url>  
  <layout>default</layout>  
  <snapshots>  
    <enabled>false</enabled>  
  </snapshots>  
</repository>  
  	</repositories>

如果要将项目发布到远程服务器上可以这样设置:

<distributionManagement>
	<repository>
		<id>releases</id>
		<name>Nexus Release Repository</name>
		<url>http://10.168.1.105:8081/nexus/content/repositories/releases/</url>
	</repository>
	<snapshotRepository>
		<id>snapshots</id>
		<name>Nexus Snapshots Repository</name>
		<url>http://10.168.1.105:8081/nexus/content/repositories/snapshots/</url>
	</snapshotRepository>
</distributionManagement>

需要验证身份信息的话,在settings.xml中配置:

<server>  
	<id>releases</id>  
	<username>deployment</username>  
	<password>deployment123</password>  
</server>
<server>
	<id>snapshots</id>  
	<username>deployment</username>  
	<password>deployment123</password>  
</server>

远程仓库的配置同样也是可以在settings.xml中:

<profile>
  <id>jdk-1.4</id>

  <activation>
    <jdk>1.4</jdk>
  </activation>

  <repositories>
    <repository>
      <id>jdk14</id>
      <name>Repository for JDK 1.4 builds</name>
      <url>http://www.myhost.com/maven/jdk14</url>
      <layout>default</layout>
      <snapshotPolicy>always</snapshotPolicy>
    </repository>
  </repositories>
</profile>

其中profile标签中的内容是满足条件时激活该profile,activation表示激活条件,也就是jdk版本是1.4时激活该profile,如果要始终生效,可以添加激活条件:

<activeProfiles>  
 <activeProfile>profileTest1</activeProfile>  
</activeProfiles>

这个激活条件时在settings.xml的根标签中配置的,profileTest1是要激活的profile的id,而profile中的activation是主动选择执行情况

还可以直接在项目中的pom.xml中配置私服地址(只在本项目起作用):

<repositories>  
    <repository>  
        <id>nexus</id>  
        <name>nexus</name>  
        <url>http://192.168.1.103:8081/nexus/content/groups/public/</url>  
        <releases>  
            <enabled>true</enabled>  
        </releases>  
        <snapshots>  
            <enabled>true</enabled>  
        </snapshots>  
    </repository>  
</repositories>  

指定插件地址:

<pluginRepositories>  
    <pluginRepository>  
        <id>nexus</id>  
        <name>nexus</name>  
        <url>http://192.168.1.103:8081/nexus/content/groups/public/</url>  
        <releases>  
            <enabled>true</enabled>  
        </releases>  
        <snapshots>  
            <enabled>true</enabled>  
        </snapshots>  
    </pluginRepository>  
</pluginRepositories>

或是在settdings.xml中配置:

mvn install 会将项目生成的构件安装到本地Maven仓库,mvn deploy 用来将项目生成的构件分发到远程Maven仓库。

正式版本在不更改版本号的情况下,编译打包时如果本地已经存在该版本的模块则不会主动去镜像服务器上下载。快照版本会主动下载最新。

Loading Disqus comments...
Table of Contents