我刚在项目中添加了maven加密,因此我的settings.xml文件中的所有密码都是加密的。当我尝试通过
联系我的nexus服务器时mvn clean install -DskipTests
然后正确下载所有依赖项并构建成功。但是,当我通过执行
运行测试时mvn clean install
然后当测试阶段开始并且maven尝试联系nexus以获得测试相关的依赖关系时,似乎对nexus的访问被拒绝,好像surefire:test插件目标忽略了maven加密并尝试连接到nexus密码错误。
示例例外是:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.activity.dashboard.DashboardActivityTest
Downloading: org/robolectric/android-all/4.3_r2-robolectric-0/android-all-4.3_r2-robolectr
ic-0.pom from repository nexus at http://xxx.xxx.xxx.xxx:7222/nexus/content/groups/public
Access denied to: http://xxx.xxx.xxx.xxx:7222/nexus/content/groups/public/org/robolectric/a
ndroid-all/4.3_r2-robolectric-0/android-all-4.3_r2-robolectric-0.pom
[WARNING] Unable to get resource 'org.robolectric:android-all:pom:4.3_r2-robolectric-0' fr
om repository nexus (http://xxx.xxx.xxx.xxx:7222/nexus/content/groups/public): Authorizatio
n failed: Access denied to: http://xxx.xxx.xxx.xxx:7222/nexus/content/groups/public/org/rob
olectric/android-all/4.3_r2-robolectric-0/android-all-4.3_r2-robolectric-0.pom
编辑:
settings.xml如下所示:
<settings>
<servers>
<server>
<id>nexus</id>
<username>maven</username>
<password>{encryptedpassword}</password>
</server>
</servers>
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://xxx.xxx.xxx.xxx:7222/nexus/content/groups/public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<!--Overriding the central repo to allow snapshots.-->
<repository>
<id>central</id>
<!--Url will eventually get overridden by the mirror url.-->
<url>fake url</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
此外,我的父pom.xml包含可能相关的分发管理部分:
<distributionManagement>
<snapshotRepository>
<uniqueVersion>true</uniqueVersion>
<id>nexus</id>
<name>Nexus Follower Snapshot Repository</name>
<url>http://xxx.xxx.xxx.xxx:7222/nexus/content/repositories/snapshots/</url>
<layout>default</layout>
</snapshotRepository>
</distributionManagement>
上传和下载快照的工作正常。
答案 0 :(得分:0)
有趣的是,在今天给予加密另一个镜头后,它只是没有任何例外。不确定是什么导致这种情况,可能是在Intellij中缓存的东西,甚至是maven / nexus版本。