Publish your project to maven repository and start using it in maven and gradle

Publish your project to maven repository and start using it in maven and gradle

The log printing project mentioned in the previous blog is almost maintained, but now it is still used as jar package and put it into other projects, so we decided to transfer the project to maven warehouse, and only need to configure it

I use Alibaba cloud's maven warehouse service. How to buy Alibaba cloud's warehouse is not covered here. It's easy to find it on Alibaba cloud

1. Modify the maven configuration file conf/settings.xml

First, add the service configuration item, which is equivalent to token, and connect to the remote warehouse

    <servers>
        <server>
            <id>rdc-releases</id>
            <username>Alibaba warehouse account</username>
            <password>Password</password>
        </server>
        <server>
            <id>rdc-snapshots</id>
            <username>Alibaba warehouse account</username>
            <password>Password</password>
        </server>
    </servers>

 

Add the configuration of warehouse address:

<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>

 

Then the configuration of private warehouse

<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. Modify pom.xml file in the project

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

It should be noted that the pom.xml file of the project should not have the < build > label, otherwise the next step will fail, and the official version cannot have SNAPSHOT in the version number

3. Deploy project to warehouse

Right click in the pom.xml file, run As – Maven build Open the following box.
Enter the following command in Goal:

 

After the upload is successful, as shown in the figure:

 

4. Start using

maven:

First, add the configuration in settings.xml:

<servers>
    <server>
        <id>rdc-releases</id>
        <username>Account number</username>
        <password>******</password>
    </server>
    <server>
        <id>rdc-snapshots</id>
        <username>Account number</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>

Add dependencies to the pom.xml file of the project

        <dependency>
            < groupid > group ID when uploading < / groupid >
            < artifactid > the item ID at the time of upload < / artifactid >
            <version>1.0</version>
        </dependency>

 

 

gradle:

Add configuration in the build.gradle file:

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

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

 

Add dependencies in the build.gradle file

 

compile group: 'Group just uploaded id', name: 'Items just uploaded id', version: '1.0'

 

 

Reference article:

https://www.cnblogs.com/supiaopiao/p/9804733.html

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

Link to this article:

 https://www.cnblogs.com/zizaiwuyou/p/12258916.html

Tags: Java Maven xml Gradle snapshot

Posted on Mon, 03 Feb 2020 23:45:24 -0500 by twizler