把本身的項目發佈到maven倉庫並在maven和gradle中開始使用

把本身的項目發佈到maven倉庫並在maven和gradle中開始使用html

上一條博客中提到的日誌打印項目總算是維護的差很少了, 不過如今使用它仍是打成jar包放到其餘項目內, 因此決定把項目傳到maven倉庫內, 使用時只須要配置一下便可了maven

我使用的是阿里雲的maven倉庫服務, 如何購買阿里雲倉庫這裏就很少說了, 去阿里雲上找很容易找到gradle

1. 修改maven配置文件conf/settings.xmlui

首先添加服務配置項, 至關於令牌, 鏈接遠程倉庫

    <servers>
        <server>
            <id>rdc-releases</id>
            <username>阿里倉庫帳號</username>
            <password>密碼</password>
        </server>
        <server>
            <id>rdc-snapshots</id>
            <username>阿里倉庫帳號</username>
            <password>密碼</password>
        </server>
    </servers>

 

再添加倉庫地址的配置:

<mirrors>
        <mirror>
            <id>mirror</id>
            <mirrorOf>!rdc-releases,!rdc-snapshots</mirrorOf>
            <name>mirror</name>
            <url>https://maven.aliyun.com/nexus/content/groups/public</url>
        </mirror>

    </mirrors>

 

而後是私有倉庫的配置

<profiles>
    <profile>
        <id>rdc-private-repo</id>
        <repositories>
            <repository>
                <id>rdc-releases</id>
                <url>https://repo.rdc.aliyun.com/repository/119569-release-xxxx/</url>
            </repository>
            <repository>
                <id>rdc-snapshots</id>
                <url>https://repo.rdc.aliyun.com/repository/119569-snapshot-xxxx/</url>
            </repository>
        </repositories>
    </profile>

2.修改項目內的pom.xml文件

<groupId>com.xxx.common</groupId>
    <artifactId>xxxx-log</artifactId>
    <version>1.0</version>
    <packaging>jar</packaging>

有一點要注意, 項目的pom.xml文件呢不能有<build>標籤, 否則下一步會失敗, 並且正式版的版本號內不能帶有SNAPSHOT阿里雲

3.部署項目到倉庫

在pom.xml文件中右擊,run As – Maven build … 打開以下的框。
在 Goal輸入以下命令:url

 

 上傳成功後如圖:spa

 

 4.開始使用

maven:.net

首先在settings.xml中添加配置:3d

<servers>
    <server>
        <id>rdc-releases</id>
        <username>帳號</username>
        <password>******</password>
    </server>
    <server>
        <id>rdc-snapshots</id>
        <username>帳號</username>
        <password>******</password>
    </server>

<profile>
    <id>rdc-private-repo</id>
    <repositories>
        <repository>
            <id>rdc-releases</id>
            <url>https://repo.rdc.aliyun.com/repository/119569-release-xxx/</url>
        </repository>
        <repository>
            <id>rdc-snapshots</id>
            <url>https://repo.rdc.aliyun.com/repository/119569-snapshot-xxx/</url>
        </repository>
    </repositories>
</profile>

 在項目的pom.xml文件中加入依賴項日誌

        <dependency>
            <groupId>剛纔上傳時的分組id</groupId>
            <artifactId>剛纔上傳時的項目id</artifactId>
            <version>1.0</version>
        </dependency>

 

 

gradle:

 在build.gradle文件內加入配置:

allprojects {
    repositories {
        maven {
            url 'https://maven.aliyun.com/repository/public'
        }

        maven {
            credentials {
                username '帳號'
                password '******'
            }
            url 'https://repo.rdc.aliyun.com/repository/119569-release-xxx/'
        }
        maven {
            credentials {
                username '帳號'
                password '******'
            }
            url 'https://repo.rdc.aliyun.com/repository/119569-snapshot-xxx/'
        }
    }
}

 

 在build.gradle文件內加入依賴項

 

compile group: '剛纔上傳時的分組id', name: '剛纔上傳時的項目id', version: '1.0'

 

 

 參考文章:

http://www.javashuo.com/article/p-uytoscfg-kv.html

https://blog.csdn.net/loveshunyi/article/details/88813433

 本文連接:

 http://www.javashuo.com/article/p-tfuslpox-kn.html

相關文章
相關標籤/搜索