Running Maven and Sonatype Nexus while offline wit

2019-05-03 22:21发布

问题:

I am trying to setup a maven environment with nexus so that maven downloads its artifacts from a local Nexus repository. The machine where Maven and Nexus is installed has no internet connectivity for security reasons.

I have a similar configuration on my workstation which does have internet connectivity. I installed Maven and Nexus on both machines. I also updated my local maven settings file in ~m2/settings.xml as shown below:

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <mirrors>
    <mirror>
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>http://localhost:8081/nexus/content/groups/public</url>
    </mirror>
  </mirrors>
  <proxies></proxies>
  <servers></servers>
  <pluginGroups></pluginGroups>
  <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://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
      <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>nexus</activeProfile>
  </activeProfiles>
</settings>

I have run to run a simple "mvn install" on the secure server and it complained about missing dependencies. This is expected because i have not downloaded and uploaded any artifacts onto the repository.

I would like to download the artifacts using my local workstation, zip them up and then upload them on to the Nexus repository on the secure machine. I have run 'mvn install' on my local workstation and everything has been downloaded. Now i need to copy the repository on the local workstation to the secure server.

According to the Nexus documentation, the folder $HOME/sonatype-work is the "storage" location.

  • Is this folder the only folder i need to copy to the secure server in order to copy the repository?
  • Are there any other files i need to worry about? e.g. configuration files?
  • I noticed that by default, Nexus disables the remote repositories. Does this mean that if i leave it as it is i dont need to do anything to prevent it to download anything from the central repository.

Thanks in advance.

回答1:

It's possible to upload the contents of your local repository to the Nexus server's storage area. You might need to re-index or regenerate the repositories metadata (tasks that can be invoked via the Nexus GUI).

However.... I would recommend that you consider an alternative solution that will ultimately result in less maintenance.

The Professional edition of Nexus has procurement suite feature that enables you to create repositories whose content is controlled by rules or based on a reference build.

Open up the firewall so that only Nexus has access to the internet. enables you to give development controlled access to any 3rd party Nexus repository.