搭建maven私库之后的使用

本文使用默认的已创建好的仓库。

maven-center:中央库 (表示从中央库下载的jar包:这里可以使用代理,可以是阿里地址)

maven-releases:表示发布版,本地的发布版本到私库

maven-snapshots:表示本地发布的测试版本

如果以上的仓库不够用,或者想用自己命名的私库,就自己创建,要proxy要填写地址,本地releases版本需要选择allow deployed。

setting.xml配置:

<?xml version="1.0" encoding="UTF-8"?>



<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository -->
  <localRepository>F:/java/maven-3.5.3/repository</localRepository>
    
  <!-- pluginGroups
   | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
   | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
   | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
   |-->
  <pluginGroups>
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
  </pluginGroups>

  <!-- proxies
   | This is a list of proxies which can be used on this machine to connect to the network.
   | Unless otherwise specified (by system property or command-line switch), the first proxy
   | specification in this list marked as active will be used.
   |-->
  <proxies>
    <!-- proxy
     | Specification for one proxy, to be used in connecting to the network.
     |
    <proxy>
      <id>optional</id>
      <active>true</active>
      <protocol>http</protocol>
      <username>proxyuser</username>
      <password>proxypass</password>
      <host>proxy.host.net</host>
      <port>80</port>
      <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
    </proxy>
    -->
  </proxies>

  <!-- servers
   | This is a list of authentication profiles, keyed by the server-id used within the system.
   | Authentication profiles can be used whenever maven must make a connection to a remote server.
   |-->
  <servers>
    <!-- server
     | Specifies the authentication information to use when connecting to a particular server, identified by
     | a unique name within the system (referred to by the 'id' attribute below).
     |
     | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
     |       used together.
     |
       -->
   <server>
      <id>release</id>
      <username>admin</username>
      <password>123456</password>
    </server>
    
    <server>
      <id>snapshots</id>
      <username>admin</username>
      <password>123456</password>
    </server>
  </servers>

  <!-- mirrors
   | This is a list of mirrors to be used in downloading artifacts from remote repositories.
   |
   | It works like this: a POM may declare a repository to use in resolving certain artifacts.
   | However, this repository may have problems with heavy traffic at times, so people have mirrored
   | it to several places.
   |
   | That repository definition will have a unique id, so we can create a mirror reference for that
   | repository, to be used as an alternate download site. The mirror site will be the preferred
   | server for that repository.
   |-->
  <mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
    <!--  <mirror>  
        <id>nexus</id>  
        <name>nexus</name>  
        <url>http://localhost:8081/repository/zkj-group/</url>  
        <mirrorOf>central</mirrorOf>  
    </mirror>   -->   
      <mirror>
        <id>nexus-aliyun</id>

        <name>nexus-aliyun</name>

        <url>http://maven.aliyun.com/nexus/content/groups/public</url>

        <mirrorOf>central</mirrorOf>
    </mirror>
    
  </mirrors>

 
  <profiles>
     <repositories>
            
            
        <repository>
            <id>nexus</id>
            <name>maven-public</name>
            <url>http://localhost:8081/repository/maven-public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
     <!--
            <repository>
                <id>nexus-aliyun</id>
                <name>nexus-aliyun</name>
                <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>false</enabled>
                </snapshots>
            </repository>
            -->
        </repositories>
   
</profiles>

  <!-- activeProfiles
   | List of profiles that are active for all builds.
   |
  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
    <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  </activeProfiles>
  -->
</settings>

然后是项目里的pom.xml配置(在</project>结束标签前添加就行其他地方也行):

<distributionManagement>
        <repository>
            <id>release</id>
            <name>Releases</name>
            <url>http://localhost:8081/repository/maven-releases</url>
        </repository>
        <snapshotRepository>
            <id>snapshots</id>
            <name>Snapshot</name>
            <url>http://localhost:8081/repository/maven-snapshots</url>
        </snapshotRepository>
    </distributionManagement>

这里配置,告诉maven要打包和发布到的地址

猜你喜欢

转载自www.cnblogs.com/zkj1204/p/12449101.html
今日推荐