How to use Maven to develop in an environment that does not allow networking

Foreword: The operating mechanism of Maven is: Maven core components first go to the local library under the .m2 directory to find dependencies or plug-ins. If there is no local library, if the private server is configured, go to the private server to download the dependencies or plug-ins. If not, it will be downloaded from the Maven server such as the central service. Therefore, all dependencies and plugins originate from the central server. However, in some harsh environments, it is not allowed to have any connection between the local area network and the external network, and you want to use Maven to build the project, what should you do? The following will describe the specific steps:

       1) Find a computer that can be connected to the Internet, and build the nexus private server on it;

       2) Configure the setting.xml file so that the local development environment depends on the nexus private server:

            First add under the <mirrors> tag:

             <mirror>
                <id>nexus</id>
                <mirrorOf>*</mirrorOf>
                <name>Human Readable Name for this Mirror.</name>
                <url>http://localhost:8080/nexus/content/groups/public</ url>
             </mirror>
             and then add under the <profiles> tag:

             <profile>

                <repositories>
                  <repository>
      <id>central</id>
                    <url>http://central</url>
      <releases><enabled>true</enabled></releases>
                    <snapshots><enabled>true</ enabled></snapshots>
                  </repository>
                </repositories>

                <!--The following plugin library dependencies must be configured, so that Maven will depend 100% on the private server, otherwise Maven cannot find the plugin on the private server. After waiting for a while, it will Will go to the central server to download, plus the following configuration, it will not bypass the private server. -->
                <pluginRepositories>
                       <pluginRepository>
                         <id>central</id>
                         <!

      <releases><enabled>true</enabled></releases>
      <snapshots><enabled>true</enabled></snapshots>
      </pluginRepository>
                  </pluginRepositories>             
           </profile>
           Finally, under the <settings> tag Add the following configuration to activate the above <mirror>

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

            If you do not understand the meaning of the mirror <mirror>, you can check other information. Only by forcibly controlling maven to rely on private servers, can maven development be carried out in a closed local area network, otherwise maven will still go to the central server to download dependencies and plug-ins, and errors will occur.

        3) Use maven to build a development environment, and complete actions such as clean, package, and test. In short, one purpose: to enable nexus to download as many plugins and dependencies as possible.

        4) Copy nuxus (maybe in bundle form or in war form) and .

        5) Use the configuration method described above to configure the setting.xml file of the development machine in the LAN so that it completely depends on the private server deployed in the LAN.

        At this point, the deployment is complete. Pay attention to the snatype-work folder just now, open this directory, you can see that a lot of nexus data, such as indexes, dependencies, plug-ins, etc., are stored in the nexus folder under it. Among them, storage is stored in the central server, third-party components, etc. You can open and study it yourself.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326565167&siteId=291194637