maven 的pom.xml中的repository节点配置没有起作用怎么解决

问题描述:

       昨天用cas搭建一个单点登录服务器,下载源码后导入idea。没想到出师未捷身先死,第一步就挂了。
以下是我pom.xml配置文件的一部分。

    <repositories>
		<repository>
			<id>sonatype-releases</id>
			<url>http://oss.sonatype.org/content/repositories/releases/</url>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
			<releases>
				<enabled>true</enabled>
			</releases>
		</repository>
		<repository>
			<id>sonatype-snapshots</id>
			<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
			<snapshots>
				<enabled>true</enabled>
			</snapshots>
			<releases>
				<enabled>false</enabled>
			</releases>
		</repository>
		<repository>
			<id>shibboleth-releases</id>
			<url>https://build.shibboleth.net/nexus/content/repositories/releases</url>
		</repository>
	</repositories>

然后开心的mvn install,就报错了。错误如下:

-Dmaven.multiModuleProjectDirectory system property is not set.

百思不得其姐啊,maven 应该是先找当前项目的repository,然后找本地,然后再找私服,最后找中央仓库才对啊!明明在pom.xml里面配置了repository了啊!

解决方案:

今天有点时间,自己分析了下然后Google了下,解决了这个问题。问题原因及方案如下:

我的maven中的setting.xml配置文件里面关于mirror部分的配置如下:

<mirror>
    <id>ibiblio</id>
    <mirrorOf>*</mirrorOf>
    <name>Human Readable Name for this Mirror.</name>
    <url>http://mirrors.ibiblio.org/pub/mirrors/maven2/</url>
</mirror>

错误就出在mirrorOf节点了,如果写*会覆盖掉所有的,不管是哪个repository,最后都被这个镜像所mirror掉了,导致pom文件中的repository不生效了。
解决方案也很简单,把这个mirrorOf改掉就好了。具体修改建议参考maven官方说明:

* = everything
external:* = everything not on the localhost and not file based.
repo,repo1 = repo or repo1
*,!repo1 = everything except repo1

 

其它需要注意的问题及推荐

  1. 尽量不要配置mirrorOf为*
  2. 私服的配置推荐用profile配置而不是mirror(毕竟mirror是镜像,私服其实是n个镜像及自己的开发库等的合集)
    <profile>
      <id>nexus</id>
      <repositories>
        <repository>
          <id>nexus</id>
          <url>http://192.168.163.xx:xx/nexus/content/groups/public/</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>nexus</id>
          <url>http://192.168.163.xx:xx/nexus/content/groups/public/</url>
          <releases>
            <enabled>true</enabled>
          </releases>
          <snapshots>
            <enabled>true</enabled>
          </snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>nexus</activeProfile>
  </activeProfiles>

猜你喜欢

转载自blog.csdn.net/snail_bing/article/details/81626710
今日推荐