maven&gradle打包api上传私服详细步骤

一.maven打包流程

1.maven setting添加私服配置,完整配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
 | This is the configuration file for Maven. It can be specified at two levels:
 |
 |  1. User Level. This settings.xml file provides configuration for a single user,
 |                 and is normally provided in ${user.home}/.m2/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -s /path/to/user/settings.xml
 |
 |  2. Global Level. This settings.xml file provides configuration for all Maven
 |                 users on a machine (assuming they're all using the same Maven
 |                 installation). It's normally provided in
 |                 ${maven.conf}/settings.xml.
 |
 |                 NOTE: This location can be overridden with the CLI option:
 |
 |                 -gs /path/to/global/settings.xml
 |
 | The sections in this sample file are intended to give you a running start at
 | getting the most out of your Maven installation. Where appropriate, the default
 | values (values used when the setting is not specified) are provided.
 |
 |-->
<settings
    xmlns="http://maven.apache.org/SETTINGS/1.2.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
    <!-- localRepository
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->
    <localRepository>/Users/Documents/soft/apacheMaven/repos</localRepository>
    <!-- interactiveMode
   | This will determine whether maven prompts you when it needs input. If set to false,
   | maven will use a sensible default value, perhaps based on some other setting, for
   | the parameter in question.
   |
   | Default: true
  <interactiveMode>true</interactiveMode>
  -->
    <!-- offline
   | Determines whether maven should attempt to connect to the network when executing a build.
   | This will have an effect on artifact downloads, artifact deployment, and others.
   |
   | Default: false
  <offline>false</offline>
  -->
    <!-- pluginGroups
   | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
   | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
   | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
   |-->
    <pluginGroups>
        <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
    </pluginGroups>
    <!-- proxies
   | This is a list of proxies which can be used on this machine to connect to the network.
   | Unless otherwise specified (by system property or command-line switch), the first proxy
   | specification in this list marked as active will be used.
   |-->
    <proxies>
        <!-- proxy
     | Specification for one proxy, to be used in connecting to the network.
     |
    <proxy><id>optional</id><active>true</active><protocol>http</protocol><username>proxyuser</username><password>proxypass</password><host>proxy.host.net</host><port>80</port><nonProxyHosts>local.net|some.host.com</nonProxyHosts></proxy>
    -->
    </proxies>
    <!-- servers
   | This is a list of authentication profiles, keyed by the server-id used within the system.
   | Authentication profiles can be used whenever maven must make a connection to a remote server.
   |-->
    <servers>
        <!-- server
     | Specifies the authentication information to use when connecting to a particular server, identified by
     | a unique name within the system (referred to by the 'id' attribute below).
     |
     | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
     |       used together.
     |
    <server><id>deploymentRepo</id><username>repouser</username><password>repopwd</password></server>
    -->
        <!-- Another sample, using keys to authenticate.
    <server><id>siteServer</id><privateKey>/path/to/private/key</privateKey><passphrase>optional; leave empty if not used.</passphrase></server>
    -->
        <!-- 此处为我自己的私服账号配置 -->
        <server>
            <id>maven-releases</id>
            <username>name</username>
            <password>password</password>
        </server>
        <server>
            <id>maven-snapshots</id>
            <username>name</username>
            <password>password</password>
        </server>
    </servers>
    <mirrors>
        <!-- 此处的mirrorOf不能随便写,要和下面profile中的repository name标签的一致 ;如果配置的是central,后面profile中可以省略配置对应的central  -->
        <!-- 
            maven获取真正起作用的repository集合流程:首先会获取pom.xml里的repository集合,然后在settings.xml里找mirrors元素,
            如果repository的id和mirror的mirrorOf的值相同,则该mirror替代该repository,
            如果该repository找不到对应的mirror,
            则使用其本身,依此可以得到最终起作用的repository集合
        -->
        <!-- 将 central 的请求重定向到阿里云的公共 Maven 仓库 -->
        <!-- 其它的不重定向到阿里云 -->
        <mirror>
            <id>Nexus-aliyun</id>
            <mirrorOf>central</mirrorOf>
            <name>Nexus aliyun</name>
            <url>https://maven.aliyun.com/repository/central</url>
        </mirror>
    </mirrors>
    <profiles>
        <profile>
            <id>nexus-mr</id>
            <!-- 
                这里的 repositories 如果不配置的话,默认会有一个 Maven 中央仓库的配置,
                同样 pluginRepositories 中如果没有配置的话,默认也是有一个 Maven 中央仓库的配置。
                还有!如果 repositories 中没有配置 repository.id 是 central 的 repository,
                会自动增加一个 Maven 中央仓库的配置,并且是以追加的方式,也就是配置在 repositories 的最后一个。
                所以如果只配置了私服的 repository 情况下,就会先去私服中下载,私服中下载不到时再去追加上来的 Maven 中央仓库中下载
                
                -->
            <repositories>
                <!-- 配置的顺序决定了下载 jar 包的顺序 -->
                <repository>
                    <id>nexus</id>
                    <url>http://xxx.com/repository/xx-group/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
                <!-- 
                        如果前面mirrorOf配置了central定位到阿里云镜像,这里的central配置可以省略,nexus中找不到会自动根据central去阿里云镜像查找;
                    
                        如果上面mirrorOf没有配置central ,这里不配central的话,nexus中找不到会自动去maven默认中央仓库找
                    
                    -->
                <repository>
                    <id>central</id>
                    <url>https://maven.aliyun.com/repository/central</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>nexus</id>
                    <url>http://xxx.com/repository/xx-group/</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
                <pluginRepository>
                    <id>central</id>
                    <url>https://maven.aliyun.com/repository/central</url>
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
        <profile>
            <id>jdk-1.8</id>
            <activation>
                <activeByDefault>true</activeByDefault>
                <jdk>1.8</jdk>
            </activation>
            <properties>
                <maven.compiler.source>1.8</maven.compiler.source>
                <maven.compiler.target>1.8</maven.compiler.target>
                <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
            </properties>
        </profile>
    </profiles>
    <activeProfiles>
        <!-- 激活环境配置 ,使上面的配置生效 -->
        <activeProfile>nexus-mr</activeProfile>
    </activeProfiles>
</settings>

2.创建maven项目,配置pom

如果不需要上传源包则需要添加配置

<maven.javadoc.skip>true</maven.javadoc.skip> <maven.source.skip>true</maven.source.skip>

例子pom配置如下:

<?xml version="1.0" encoding="UTF-8"?>
<project 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/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>test-jar-maven</artifactId>
    <version>1.1-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>8</maven.compiler.source>
        <maven.compiler.target>8</maven.compiler.target>
        <!--下面两个配置不会将源包上传-->
        <maven.javadoc.skip>true</maven.javadoc.skip>
        <maven.source.skip>true</maven.source.skip>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-source-plugin</artifactId>
                <version>3.2.1</version>
                <configuration>
                    <attach>true</attach>
                </configuration>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>jar</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
    <distributionManagement>
        <!--稳定版本的仓库地址,必须是允许上传的私服地址-->
        <repository>
            <!--id和maven setting文件server id保持一致则不需要配置用户名密码,否则需要在pom中配置用户名密码-->
            <id>maven-releases</id>
            <url>http://xxx.com/repository/xxx-release/</url>
        </repository>
        <!--开发版本的仓库地址,必须是允许上传的私服地址-->
        <snapshotRepository>
            <id>maven-snapshots</id>
            <url>http://xxx.com/repository/xxx-snapshot/</url>
        </snapshotRepository>
    </distributionManagement>
</project>

3.执行打包(命令行也可以)

结果如下:

二.gradle打包流程配置

gradle接触不多,目前也只会上传不带源包,项目用的gradle是6.7有些方法看起来是过时了,但是还能用,先记录到这里,等有时间研究透了再更新记录下

打包上传配置

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值