Java:以静态文件发布Maven开源库

发布开源库到Github

pom.xml


<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.0modelVersion>

    <groupId>com.moudaygroupId>
    <artifactId>hello-packageartifactId>
    <version>1.0-SNAPSHOTversion>

    
    <distributionManagement>
        <repository>
            <id>local-repo-releaseid>
            <name>GitHub Releasename>
            <url>file://${project.basedir}/maven-repourl>
        repository>
    distributionManagement>

    <build>
        <plugins>
            
            <plugin>
                <artifactId>maven-source-pluginartifactId>
                <executions>
                    <execution>
                        <id>attach-sourcesid>
                        <phase>packagephase>
                        <goals>
                            <goal>jar-no-forkgoal>
                        goals>
                    execution>
                executions>
            plugin>

            
            <plugin>
                <artifactId>maven-javadoc-pluginartifactId>
                <executions>
                    <execution>
                        <id>attach-javadocsid>
                        <phase>packagephase>
                        <goals>
                            <goal>jargoal>
                        goals>
                    execution>
                executions>
            plugin>
        plugins>
    build>

project>

构建功能

package com.mouday;

public class Hello {
    public void sayHello(){
        System.out.println("Hello");
    }
}

生成部署文件

mvn clean package deploy

生成如下文件

$ tree
.
├── README.md
├── hello-package.iml
├── maven-repo
│   └── com
│       └── mouday
│           └── hello-package
│               ├── 1.0-SNAPSHOT
│               │   ├── hello-package-1.0-20200731.025404-1-javadoc.jar
│               │   ├── hello-package-1.0-20200731.025404-1-javadoc.jar.md5
│               │   ├── hello-package-1.0-20200731.025404-1-javadoc.jar.sha1
│               │   ├── hello-package-1.0-20200731.025404-1-sources.jar
│               │   ├── hello-package-1.0-20200731.025404-1-sources.jar.md5
│               │   ├── hello-package-1.0-20200731.025404-1-sources.jar.sha1
│               │   ├── hello-package-1.0-20200731.025404-1.jar
│               │   ├── hello-package-1.0-20200731.025404-1.jar.md5
│               │   ├── hello-package-1.0-20200731.025404-1.jar.sha1
│               │   ├── hello-package-1.0-20200731.025404-1.pom
│               │   ├── hello-package-1.0-20200731.025404-1.pom.md5
│               │   ├── hello-package-1.0-20200731.025404-1.pom.sha1
│               │   ├── maven-metadata.xml
│               │   ├── maven-metadata.xml.md5
│               │   └── maven-metadata.xml.sha1
│               ├── maven-metadata.xml
│               ├── maven-metadata.xml.md5
│               └── maven-metadata.xml.sha1
├── pom.xml
└── src
    ├── main
    │   ├── java
    │   │   └── com
    │   │       └── mouday
    │   │           └── Hello.java
    │   └── resources
    └── test
        └── java

将代码推送到 Github,并开启Pages服务

仓库地址:https://github.com/mouday/hello-package

使用开源库

pom.xml


<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.0modelVersion>

    <groupId>com.moudaygroupId>
    <artifactId>import-hello-demoartifactId>
    <version>1.0-SNAPSHOTversion>


    <repositories>
        
        <repository>
            <id>github-rich-repoid>
            <name>The Maven Repository on Githubname>
            <url>https://www.pengshiyu.com/hello-package/maven-repo/url>
        repository>
    repositories>

    <dependencies>
        
        <dependency>
            <groupId>com.moudaygroupId>
            <artifactId>hello-packageartifactId>
            <version>1.0-SNAPSHOTversion>
        dependency>
    dependencies>
project>

使用测试

package com.mouday;

public class demo {
    public static void main(String[] args) {
        Hello hello =new Hello();
        hello.sayHello();
    }
}

参考
https://www.liaoxuefeng.com/wiki/1252599548343744/1347981037010977

你可能感兴趣的:(Java:以静态文件发布Maven开源库)