Статьи

Настройка локального репозитория Nexus и развертывание файла WAR из Maven

Maven Central служит центральным менеджером репозитория, где двоичные артефакты загружаются различными командами / компаниями / частными лицами и передаются остальному миру. Подобно github и другим репозиториям исходного кода, которые очень эффективны для управления исходным кодом, эти менеджеры репозитория также действуют как назначение развертывания для ваших собственных сгенерированных двоичных артефактов.

Настройка менеджера локального хранилища имеет несколько преимуществ. Основными из них являются то, что они действуют как настраиваемый прокси-сервер между центральным Maven, так что не всем нужно загружать все зависимости из центрального репо. Другой основной причиной является контроль ваших временных сгенерированных артефактов в вашей команде. Причины использования Repository Manager предоставляют подробное объяснение полного набора преимуществ.

Этот технический совет покажет, как настроить локальный менеджер репозитория Nexus и передать в него артефакты — как моментальные снимки, так и выпуски.

Давайте начнем!

Установите и настройте локальный репозиторий Nexus

  1. Загрузите и распакуйте последнюю версию Nexus OSS . Логин / пароль администратора по умолчанию — admin / admin123. Логин / пароль для развертывания по умолчанию — развертывание / развертывание123
  2. Запустите Nexus как:
    1
    2
    3
    nexus-2.11.2-03> ./bin/nexus start
    Starting Nexus OSS...
    Started Nexus OSS.

    Журналы могут тогда быть замечены как:

    1
    nexus-2.11.2-03> tail -f logs/wrapper.log

    Или вы можете начать, где журналы отображаются в самой консоли:

    01
    02
    03
    04
    05
    06
    07
    08
    09
    10
    11
    12
    13
    14
    nexus-2.11.2-03> ./bin/nexus console
    Running Nexus OSS...
    wrapper  | --> Wrapper Started as Console
    wrapper  | Launching a JVM...
    jvm 1    | Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=192m; support was removed in 8.0
    jvm 1    | Wrapper (Version 3.2.3) http://wrapper.tanukisoftware.org
    jvm 1    |   Copyright 1999-2006 Tanuki Software, Inc.  All Rights Reserved.
    jvm 1    |
     
    . . .
     
    jvm 1    | 2015-02-24 00:17:28,706-0800 INFO  [jetty-main-1] *SYSTEM org.sonatype.nexus.bootstrap.jetty.JettyServer - Running
    jvm 1    | 2015-02-24 00:17:28,706-0800 INFO  [WrapperListener_start_runner] *SYSTEM org.sonatype.nexus.bootstrap.jetty.JettyServer - Started
    jvm 1    | 2015-02-24 00:17:30,713-0800 INFO  [ar-4-thread-3] *SYSTEM org.sonatype.nexus.proxy.maven.routing.internal.ManagerImpl - Updated and published prefix file of "Public Repositories" [id=public]
  3. Сконфигурируйте файл настроек Maven (~ .m2 / settings.xml), чтобы включить имя пользователя и пароль для развертывания по умолчанию:
    01
    02
    03
    04
    05
    06
    07
    08
    09
    10
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
       <servers>
          <server>
            <id>deployment</id>
            <username>deployment</username>
            <password>deployment123</password>
         </server>
      </servers>
    </settings>

Развернуть снимок в локальный репозиторий Nexus

  1. Ознакомьтесь с простым примером Java EE по адресу github.com/javaee-samples/javaee7-simple-sample .
  2. Создайте и разверните файл WAR в локальном репозитории Nexus как:
    01
    02
    03
    04
    05
    06
    07
    08
    09
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    javaee7-simple-sample> mvn deploy
    [INFO] Scanning for projects...
    [INFO]                                                                        
    [INFO] ------------------------------------------------------------------------
    [INFO] Building javaee7-simple-sample 1.0-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO]
    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ javaee7-simple-sample ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] Copying 0 resource
    [INFO]
    [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ javaee7-simple-sample ---
    [INFO] Changes detected - recompiling the module!
    [INFO] Compiling 4 source files to /Users/arungupta/workspaces/javaee7-simple-sample/target/classes
    [INFO]
    [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ javaee7-simple-sample ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] skip non existing resourceDirectory /Users/arungupta/workspaces/javaee7-simple-sample/src/test/resources
    [INFO]
    [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ javaee7-simple-sample ---
    [INFO] No sources to compile
    [INFO]
    [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ javaee7-simple-sample ---
    [INFO] No tests to run.
    [INFO]
    [INFO] --- maven-war-plugin:2.3:war (default-war) @ javaee7-simple-sample ---
    [INFO] Packaging webapp
    [INFO] Assembling webapp [javaee7-simple-sample] in [/Users/arungupta/workspaces/javaee7-simple-sample/target/javaee7-simple-sample]
    [INFO] Processing war project
    [INFO] Copying webapp resources [/Users/arungupta/workspaces/javaee7-simple-sample/src/main/webapp]
    [INFO] Webapp assembled in [33 msecs]
    [INFO] Building war: /Users/arungupta/workspaces/javaee7-simple-sample/target/javaee7-simple-sample.war
    [INFO]
    [INFO] --- maven-install-plugin:2.4:install (default-install) @ javaee7-simple-sample ---
    [INFO] Installing /Users/arungupta/workspaces/javaee7-simple-sample/target/javaee7-simple-sample.war to /Users/arungupta/.m2/repository/org/javaee7/sample/javaee7-simple-sample/1.0-SNAPSHOT/javaee7-simple-sample-1.0-SNAPSHOT.war
    [INFO] Installing /Users/arungupta/workspaces/javaee7-simple-sample/pom.xml to /Users/arungupta/.m2/repository/org/javaee7/sample/javaee7-simple-sample/1.0-SNAPSHOT/javaee7-simple-sample-1.0-SNAPSHOT.pom
    [INFO]
    [INFO] >>> wildfly-maven-plugin:1.0.2.Final:deploy (default) > package @ javaee7-simple-sample >>>
    [INFO]
    [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ javaee7-simple-sample ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] Copying 0 resource
    [INFO]
    [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ javaee7-simple-sample ---
    [INFO] Nothing to compile - all classes are up to date
    [INFO]
    [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ javaee7-simple-sample ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] skip non existing resourceDirectory /Users/arungupta/workspaces/javaee7-simple-sample/src/test/resources
    [INFO]
    [INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ javaee7-simple-sample ---
    [INFO] No sources to compile
    [INFO]
    [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ javaee7-simple-sample ---
    [INFO] No tests to run.
    [INFO] Skipping execution of surefire because it has already been run for this configuration
    [INFO]
    [INFO] --- maven-war-plugin:2.3:war (default-war) @ javaee7-simple-sample ---
    [INFO] Packaging webapp
    [INFO] Assembling webapp [javaee7-simple-sample] in [/Users/arungupta/workspaces/javaee7-simple-sample/target/javaee7-simple-sample]
    [INFO] Processing war project
    [INFO] Copying webapp resources [/Users/arungupta/workspaces/javaee7-simple-sample/src/main/webapp]
    [INFO] Webapp assembled in [3 msecs]
    [INFO] Building war: /Users/arungupta/workspaces/javaee7-simple-sample/target/javaee7-simple-sample.war
    [INFO]
    [INFO] <<< wildfly-maven-plugin:1.0.2.Final:deploy (default) < package @ javaee7-simple-sample <<<
    [INFO]
    [INFO] --- wildfly-maven-plugin:1.0.2.Final:deploy (default) @ javaee7-simple-sample ---
    Feb 24, 2015 1:02:46 AM org.xnio.Xnio <clinit>
    INFO: XNIO version 3.2.2.Final
    Feb 24, 2015 1:02:46 AM org.xnio.nio.NioXnio <clinit>
    INFO: XNIO NIO Implementation Version 3.2.2.Final
    Feb 24, 2015 1:02:46 AM org.jboss.remoting3.EndpointImpl <clinit>
    INFO: JBoss Remoting version 4.0.3.Final
    [INFO]
    [INFO] --- maven-deploy-plugin:2.7:deploy (default-deploy) @ javaee7-simple-sample ---
    Downloading: http://localhost:8081/nexus/content/repositories/snapshots/org/javaee7/sample/javaee7-simple-sample/1.0-SNAPSHOT/maven-metadata.xml
    Downloaded: http://localhost:8081/nexus/content/repositories/snapshots/org/javaee7/sample/javaee7-simple-sample/1.0-SNAPSHOT/maven-metadata.xml (783 B at 4.0 KB/sec)
    Uploading: http://localhost:8081/nexus/content/repositories/snapshots/org/javaee7/sample/javaee7-simple-sample/1.0-SNAPSHOT/javaee7-simple-sample-1.0-20150224.090247-2.war
    Uploaded: http://localhost:8081/nexus/content/repositories/snapshots/org/javaee7/sample/javaee7-simple-sample/1.0-SNAPSHOT/javaee7-simple-sample-1.0-20150224.090247-2.war (6 KB at 90.4 KB/sec)
    Uploading: http://localhost:8081/nexus/content/repositories/snapshots/org/javaee7/sample/javaee7-simple-sample/1.0-SNAPSHOT/javaee7-simple-sample-1.0-20150224.090247-2.pom
    Uploaded: http://localhost:8081/nexus/content/repositories/snapshots/org/javaee7/sample/javaee7-simple-sample/1.0-SNAPSHOT/javaee7-simple-sample-1.0-20150224.090247-2.pom (3 KB at 53.2 KB/sec)
    Downloading: http://localhost:8081/nexus/content/repositories/snapshots/org/javaee7/sample/javaee7-simple-sample/maven-metadata.xml
    Downloaded: http://localhost:8081/nexus/content/repositories/snapshots/org/javaee7/sample/javaee7-simple-sample/maven-metadata.xml (297 B at 13.8 KB/sec)
    Uploading: http://localhost:8081/nexus/content/repositories/snapshots/org/javaee7/sample/javaee7-simple-sample/1.0-SNAPSHOT/maven-metadata.xml
    Uploaded: http://localhost:8081/nexus/content/repositories/snapshots/org/javaee7/sample/javaee7-simple-sample/1.0-SNAPSHOT/maven-metadata.xml (783 B at 20.7 KB/sec)
    Uploading: http://localhost:8081/nexus/content/repositories/snapshots/org/javaee7/sample/javaee7-simple-sample/maven-metadata.xml
    Uploaded: http://localhost:8081/nexus/content/repositories/snapshots/org/javaee7/sample/javaee7-simple-sample/maven-metadata.xml (297 B at 6.7 KB/sec)
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 4.398 s
    [INFO] Finished at: 2015-02-24T01:02:47-08:00
    [INFO] Final Memory: 22M/310M
    [INFO] ------------------------------------------------------------------------

    Репозиторий моментальных снимков, после отправки нескольких сборок, можно увидеть по адресу localhost: 8081 / nexus / # view-repositories; snapshots ~ browsestorage и выглядит следующим образом:

    techtip73-связующей снимок-хранилищу 1024x749

    Фактическое хранилище находится в ../sonatype-work/nexus . Это создается параллельно с тем местом, где когда-либо был распакован комплект Nexus OSS.

Развертывание выпуска в локальном репозитории Nexus

  1. Очистите любой ранее выполненный релиз:
    01
    02
    03
    04
    05
    06
    07
    08
    09
    10
    11
    12
    13
    14
    15
    16
    javaee7-simple-sample> mvn release:clean -P release
    [INFO] Scanning for projects...
    [INFO]                                                                        
    [INFO] ------------------------------------------------------------------------
    [INFO] Building javaee7-simple-sample 1.1-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO]
    [INFO] --- maven-release-plugin:2.5.1:clean (default-cli) @ javaee7-simple-sample ---
    [INFO] Cleaning up after release...
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 0.912 s
    [INFO] Finished at: 2015-02-24T02:18:53-08:00
    [INFO] Final Memory: 10M/245M
    [INFO] ------------------------------------------------------------------------
  2. Подготовьтесь к следующему выпуску:
    01
    02
    03
    04
    05
    06
    07
    08
    09
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    javaee7-simple-sample> mvn release:prepare -P release
    [INFO] Scanning for projects...
    [INFO]                                                                        
    [INFO] ------------------------------------------------------------------------
    [INFO] Building javaee7-simple-sample 1.3-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO]
    [INFO] --- maven-release-plugin:2.5.1:prepare (default-cli) @ javaee7-simple-sample ---
    [INFO] Verifying that there are no local modifications...
    [INFO]   ignoring changes on: **/pom.xml.releaseBackup, **/pom.xml.next, **/pom.xml.tag, **/pom.xml.branch, **/release.properties, **/pom.xml.backup
    [INFO] Executing: /bin/sh -c cd /Users/arungupta/workspaces/javaee7-simple-sample && git rev-parse --show-toplevel
    [INFO] Working directory: /Users/arungupta/workspaces/javaee7-simple-sample
    [INFO] Executing: /bin/sh -c cd /Users/arungupta/workspaces/javaee7-simple-sample && git status --porcelain .
    [INFO] Working directory: /Users/arungupta/workspaces/javaee7-simple-sample
    [WARNING] Ignoring unrecognized line: ?? release.properties
    [INFO] Checking dependencies and plugins for snapshots ...
    What is the release version for "javaee7-simple-sample"? (org.javaee7.sample:javaee7-simple-sample) 1.3: :
    What is SCM release tag or label for "javaee7-simple-sample"? (org.javaee7.sample:javaee7-simple-sample) v1.3: :
    What is the new development version for "javaee7-simple-sample"? (org.javaee7.sample:javaee7-simple-sample) 1.4-SNAPSHOT: :
    [INFO] Transforming 'javaee7-simple-sample'...
    [INFO] Not generating release POMs
    [INFO] Executing goals 'clean verify'...
    [WARNING] Maven will be executed in interactive mode, but no input stream has been configured for this MavenInvoker instance.
    [INFO] [INFO] Scanning for projects...
    [INFO] [INFO]                                                                        
    [INFO] [INFO] ------------------------------------------------------------------------
    [INFO] [INFO] Building javaee7-simple-sample 1.3
    [INFO] [INFO] ------------------------------------------------------------------------
     
    . . .
     
    [INFO] Executing: /bin/sh -c cd /Users/arungupta/workspaces/javaee7-simple-sample && git symbolic-ref HEAD
    [INFO] Working directory: /Users/arungupta/workspaces/javaee7-simple-sample
    [INFO] Executing: /bin/sh -c cd /Users/arungupta/workspaces/javaee7-simple-sample && git push https://github.com/javaee-samples/javaee7-simple-sample.git refs/heads/master:refs/heads/master
    [INFO] Working directory: /Users/arungupta/workspaces/javaee7-simple-sample
    [INFO] Release preparation complete.
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 01:04 min
    [INFO] Finished at: 2015-02-24T02:55:59-08:00
    [INFO] Final Memory: 11M/245M
    [INFO] ------------------------------------------------------------------------
  3. Выполните релиз:
    01
    02
    03
    04
    05
    06
    07
    08
    09
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    javaee7-simple-sample> mvn javadoc:jar source:jar release:perform -P release
    [INFO] Scanning for projects...
    [INFO]                                                                        
    [INFO] ------------------------------------------------------------------------
    [INFO] Building javaee7-simple-sample 1.4-SNAPSHOT
    [INFO] ------------------------------------------------------------------------
    [INFO]
    [INFO] --- maven-javadoc-plugin:2.10.1:jar (default-cli) @ javaee7-simple-sample ---
     
    . . .
     
    [INFO] [INFO] ------------------------------------------------------------------------
    [INFO] [INFO] BUILD FAILURE
    [INFO] [INFO] ------------------------------------------------------------------------
    [INFO] [INFO] Total time: 5.820 s
    [INFO] [INFO] Finished at: 2015-02-24T02:58:16-08:00
    [INFO] [INFO] Final Memory: 31M/312M
    [INFO] [INFO] ------------------------------------------------------------------------
    [INFO] [ERROR] Failed to execute goal org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy (default-deploy) on project javaee7-simple-sample: Failed to deploy artifacts: Could not transfer artifact org.javaee7.sample:javaee7-simple-sample:war:1.3 from/to deployment (http://localhost:8081/nexus/content/repositories/releases/): Failed to transfer file: http://localhost:8081/nexus/content/repositories/releases/org/javaee7/sample/javaee7-simple-sample/1.3/javaee7-simple-sample-1.3.war. Return code is: 400, ReasonPhrase: Bad Request. -> [Help 1]

    Обратите внимание, как эта команда заканчивается ошибкой. Это похоже на сообщение здесь, но странно то, что файлы все еще загружаются на Nexus. Вот снимок с localhost: 8081 / nexus / # view-repositories; выпускает ~ browsestorage при попытке протестировать несколько выпусков и удивляться этим «ложным» сообщениям об ошибках:

    techtip73-нексус-релиз-хранилище

    Эта ошибка потребует дополнительной отладки, но по крайней мере снимки и сборки выпуска теперь могут храниться в локальном репозитории Nexus.

ОБНОВЛЕНИЕ: Манфред Мозер помог отладить эту ошибку, отправив запросы на извлечение . Эта ошибка теперь исчезла и вместо этого должна показать что-то вроде:

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
[INFO] Uploaded: http://localhost:8081/nexus/content/repositories/releases/org/javaee7/sample/javaee7-simple-sample/1.8/javaee7-simple-sample-1.8-sources.jar (3 KB at 74.7 KB/sec)
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] BUILD SUCCESS
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] [INFO] Total time: 5.673 s
[INFO] [INFO] Finished at: 2015-02-26T03:50:18+05:30
[INFO] [INFO] Final Memory: 31M/320M
[INFO] [INFO] ------------------------------------------------------------------------
[INFO] Cleaning up after release...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:10 min
[INFO] Finished at: 2015-02-26T03:50:30+05:30
[INFO] Final Memory: 13M/245M
[INFO] ------------------------------------------------------------------------

Вы узнали, как настроить локальный репозиторий Nexus, передать снимок и выпустить сборки для него. Последующие блоги покажут, как этот репозиторий можно использовать для CI / CD.

Наслаждайтесь!