Maven не может загружать артефакты с HTTPS Nexus с обязательной аутентификацией

У меня есть Nexus, который доступен через HTTPS. Доступ к нему имеют только авторизованные пользователи. Используя Maven, когда все необходимые артефакты находятся в локальном репозитории, я мог даже развернуть строительный артефакт. Но когда я удаляю некоторые из необходимых артефактов из локального репозитория, сборка завершается сбоем.

Downloading: https://example.com/nexus/content/groups/all/org/springframework/spring-test-mvc/1.0.0.BUILD-SNAPSHOT/spring-test-mvc-1.0.0.BUILD-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] example - project1 ..................................... SUCCESS [0.500s]
[INFO] example - project2 ..................................... FAILURE [2.951s]
[INFO] example - project3 ...................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.599s
[INFO] Finished at: Tue May 15 13:58:13 EEST 2012
[INFO] Final Memory: 6M/121M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project example - project2: Could not resolve dependencies for project com.example:example-project:jar:1.2.0-SNAPSHOT: Failed to collect dependencies for [com.example:example-project:jar:1.2.0-SNAPSHOT (compile), org.springframework:spring-beans:jar:3.1.1.RELEASE (compile), org.springframework:spring-context:jar:3.1.1.RELEASE (compile), org.springframework:spring-core:jar:3.1.1.RELEASE (compile), org.springframework:spring-test:jar:3.1.1.RELEASE (test), org.springframework:spring-web:jar:3.1.1.RELEASE (compile), org.apache.httpcomponents:httpclient:jar:4.1.1 (test), org.codehaus.jackson:jackson-mapper-asl:jar:1.9.6 (compile), org.springframework:spring-test-mvc:jar:1.0.0.BUILD-SNAPSHOT (test), junit:junit:jar:4.10 (test), org.mockito:mockito-all:jar:1.9.0 (test), org.hamcrest:hamcrest-all:jar:1.1 (compile), org.slf4j:slf4j-api:jar:1.6.1 (compile), org.slf4j:slf4j-log4j12:jar:1.6.1 (compile), log4j:log4j:jar:1.2.16 (compile), log4j:apache-log4j-extras:jar:1.1 (compile)]: Failed to read artifact descriptor for org.springframework:spring-test-mvc:jar:1.0.0.BUILD-SNAPSHOT: Could not transfer artifact org.springframework:spring-test-mvc:pom:1.0.0.BUILD-SNAPSHOT from/to nexus (https://example.com/nexus/content/groups/all): Not authorized, ReasonPhrase:Unauthorized. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :grc-webclient-services

В settings.xml моего пользователя есть следующее содержимое:

<settings>
<pluginGroups>
    </pluginGroups>
    <proxies>
    </proxies>
    <mirrors>
      <mirror>
        <id>nexus</id>
        <mirrorOf>*</mirrorOf>
        <url>https://example.com/nexus/content/groups/all</url>
      </mirror>
    </mirrors>

    <profiles>
        <profile>

            <id>nexus</id>

            <properties>
                <sonar.jdbc.url>jdbc:mysql://localhost:3306/sonardb?useUnicode=true&amp;characterEncoding=utf8</sonar.jdbc.url>
                <sonar.jdbc.driverClassName>com.mysql.jdbc.Driver</sonar.jdbc.driverClassName>
                <sonar.jdbc.username>sonarusername</sonar.jdbc.username>
                <sonar.jdbc.password>sonarpw</sonar.jdbc.password>
                <sonar.host.url>http://localhost:9000/</sonar.host.url>
            </properties>


            <repositories>
                <repository>
                    <id>central</id>
                    <url>https://example.com/nexus/content/groups/all</url>
                    <releases><enabled>true</enabled></releases>
                    <snapshots><enabled>true</enabled></snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>central</id>
                    <url>https://example.com/nexus/content/groups/all</url>
                    <releases><enabled>true</enabled></releases>
                    <snapshots><enabled>true</enabled></snapshots>
                </pluginRepository>
            </pluginRepositories>

        </profile>
    </profiles>

    <servers>
        <server>
            <id>all</id>
            <username>user</username>
            <password>pw</password>
        </server>
        <server>
            <id>releases</id>
            <username>user</username>
            <password>pw</password>
        </server>
        <server>
            <id>snapshots</id>
            <username>user</username>
            <password>pw</password>
        </server>
    </servers>

    <activeProfiles>
        <activeProfile>nexus</activeProfile>
    </activeProfiles>

</settings>

Когда я загружал артефакты с этого Nexus с помощью wget, мне пришлось добавить ключ --no-check-certificate, чтобы пропустить сертификат сервера (потому что он самоподписанный), и после этого я мог загрузить его с помощью wget.

Я добавил ключ Java -Dsun.security.ssl.allowUnsafeRenegotiation=true, но это вообще ничего не изменило.

После этого я обнаружил, что, возможно, это не проблема с самозаверяющим сертификатом, потому что я добавил сертификат сервера в список доверенных с помощью команды:

keytool -keystore $JAVA_HOME/jre/lib/security/cacerts -import -file certificate.cer

У кого-нибудь есть идея, как я могу загружать артефакты из Nexus во время сборки?


person Dmitriy Sukharev    schedule 15.05.2012    source источник
comment
Русскую часть было немного сложно понять :-) Но пробовали ли вы это руководство?   -  person Paaske    schedule 15.05.2012
comment
Я не уверен, что предыдущий комментарий охватывает то, что вам нужно. Если это просто вопрос доступа к репозиторию на сервере с самозаверяющим сертификатом, добавления сертификата в хранилище ключей Java должно быть достаточно.   -  person Paaske    schedule 15.05.2012
comment
Я уже добавил один. Может быть, не в должном порядке. Как я могу проверить, что сертификат добавлен? Также я проанализировал трафик с помощью WireShark при подключении к Nexus, я вижу пакет Encription Alert с SSL Content-type: Alert (21).   -  person Dmitriy Sukharev    schedule 15.05.2012
comment
В разделе серверов вашего файла настроек maven отсутствует запись для nexus. Я предполагаю, что вы включили базовую аутентификацию? В этом случае вам нужно указать имя пользователя и пароль, которые Maven должен использовать при доступе к нексусу.   -  person Mark O'Connor    schedule 15.05.2012
comment
Да, ты прав. Я решил эту проблему несколько часов назад, но не смог ответить на свой вопрос из-за ограничения репутации. Отвечу, как только смогу.   -  person Dmitriy Sukharev    schedule 15.05.2012


Ответы (2)


я должен был изменить

<server>
    <id>all</id>
    <username>user</username>
    <password>pw</password>
</server>

to

<server>
    <id>nexus</id>
    <username>user</username>
    <password>pw</password>
</server>

где «нексус» — это идентификатор моего зеркала в верхней части settings.xml.

person Dmitriy Sukharev    schedule 15.05.2012

Добавьте расширение wagon-http-lightweight, Хорошее объяснение

Лучшее решение для настройки прокси-сервера maven

person Nagappa L M    schedule 10.06.2013
comment
Пожалуйста, добавьте некоторый контент и объяснение в основную часть ответа, а не просто ссылку на другой сайт, чтобы пользователи могли прочитать - person Crowie; 09.04.2014