我在settings.xml文件中为所有存储库定义了一个本地镜像:
<mirror>
<id>myMirror</id>
<mirrorOf>*</mirrorOf>
<url>file://${mypath}/maven/.m2/repository</url>
</mirror>
Run Code Online (Sandbox Code Playgroud)
我希望我的镜像指向本地路径,在这种情况下路径是:
file://${mypath}/maven/.m2/repository
Run Code Online (Sandbox Code Playgroud)
$ {mypath}是我在调用Maven时传递的变量:
mvn -Dmypath="/D:/test" package
Run Code Online (Sandbox Code Playgroud)
问题是Maven在调用变量时不会替换变量.我可以看到通过检查构建日志发生了这个错误.例如,Maven报告它正在从file:// $ {mypath} /maven/.m2/repository下载文件,正确的是file:/// D:/test/maven/.m2/repository.
我还注意到Maven在将变量插入repository标记的url子标记时正确替换了我的变量:
<repository>
<id>central</id>
<url>http://${mypath}/maven/.m2/repository</url>
</repository>
Run Code Online (Sandbox Code Playgroud)
当我使用完整的URL替换settings.xml中的变量时,构建工作正常,如下例所示:
<mirror>
<id>myMirror</id>
<mirrorOf>*</mirrorOf>
<url>file:///D:test/maven/.m2/repository</url>
</mirror>
Run Code Online (Sandbox Code Playgroud) 我想设置我的构建,如果我们的nexus服务器无法访问,它会自动尝试从maven中心下载工件.我在settings.xml中有以下内容,我不知道如何更改它(如果可能的话).
<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://mynexus</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://mynexus</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
Run Code Online (Sandbox Code Playgroud)