Nexus配置内部仓库

关于创建Nexus不想多说,到官方网站http://www.sonatype.org/nexus下载WAR,直接在TOMCAT下发布就OK了。具体记录怎样配置Maven使用Nexus作为内部库,官方有一篇文章《Configuring Maven to Use a Single Nexus Group》

If you are adopting Nexus for internal development you should configure a single Nexus group which contains both releases and snapshots. To do this, add snapshot repositories to your public group, and add the following mirror configuration to your Maven settings in ~/.m2/settings.xml

<settings>
  <mirrors>
    <mirror>
      <!--This sends everything else to /public -->
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>http://localhost:8081/nexus/content/groups/public</url>
    </mirror>
  </mirrors>
  <profiles>
    <profile>
      <id>nexus</id>
      <!--Enable snapshots for the built in central repo to direct -->
      <!--all requests to nexus via the mirror -->
      <repositories>
        <repository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
     <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <!--make the profile active all the time -->
    <activeProfile>nexus</activeProfile>
  </activeProfiles>
</settings>


 In Configuring Maven to Use a Single Nexus Group we have defined a single profile: nexus profile is configured to download from the central repository with a bogus URL. This URL is overridden by the mirror setting in the same settings.xml file to point to the URL of your single Nexus group. The nexus group is then listed as an active profile in the activeProfiles element.

配置完成后,使用mv package命令出错,提示:
org.apache.maven.plugins:maven-resources-plugin:2.5 or one of its dependencies could not be resolved

最后不断尝试,发现将<mirror>节点的<id>的值改为central,package命令成功执行。而且发现无须配置<profiles>,依然可以执行成功。

settings.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: ~/.m2/repository
  <localRepository>C:/apache-maven-3.0.4/repository</localRepository>
  -->

  <!-- interactiveMode
   | This will determine whether maven prompts you when it needs input. If set to false,
   | maven will use a sensible default value, perhaps based on some other setting, for
   | the parameter in question.
   |
   | Default: true
  <interactiveMode>true</interactiveMode>
  -->

  <!-- offline
   | Determines whether maven should attempt to connect to the network when executing a build.
   | This will have an effect on artifact downloads, artifact deployment, and others.
   |
   | Default: false
  <offline>false</offline>
  -->

  <!-- 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>
    -->

	<pluginGroup>org.mortbay.jetty</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>
  </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>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
    -->
    
    <!-- Another sample, using keys to authenticate.
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
    <server>
      <id>nexus</id>
      <username>admin</username>
      <password>xxxxxx</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>central</id>
      <mirrorOf>*</mirrorOf> 
      <name>Maven Central</name>  
      <url>http://localhost:8081/nexus/content/repositories/central/</url>  
    </mirror>    
     -->
  </mirrors>
  

  <profiles>
   <profile>
      <id>dev</id>

      <repositories>
        <repository>
          <id>nexus</id>
          <name>Nexus Repository</name>
          <url>http://localhost:8081/nexus/content/groups/public/</url>
	 <releases>
	       <enabled>true</enabled>
	 </releases>
          <snapshots>
                <enabled>false</enabled>
          </snapshots>
        </repository>

        <repository>
          <id>thirdparty</id>
          <name>thirdparty</name>
          <url>http://localhost:8081/nexus/content/repositories/thirdparty/</url>
	 <releases>
	       <enabled>true</enabled>
	 </releases>
          <snapshots>
                <enabled>false</enabled>
          </snapshots>
        </repository>
      </repositories>
      
      <pluginRepositories>
		<pluginRepository>
			<id>nexus</id>
			<url>http://localhost:8081/nexus/content/groups/public/</url>
			<releases>
			  <enabled>true</enabled>
		    </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
		</pluginRepository>
	</pluginRepositories>
	
    </profile>
  </profiles>

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

  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
    <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  </activeProfiles>
  -->
</settings>


注意:<profile>中的<id>的值一定要为nexus,而且要与<server>的<id>的值相同个人认为此与Server配置下的Base URL:http://xxx.xx.xx.xxx:8081/nexus有关,另外我注释掉了<mirror>,主要在无法访问MAVEN中心库才启用。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值