展开
拓展 关闭
订阅号推广码
GitHub
视频
公告栏 关闭

github创建maven公有仓库

Settings->Developer settings->Personal access tokens

  • 报错
Error creating blob: Git Repository is empty. (409)

# 解决方案:远程仓库中没有上传文件,需先任意上传1个文件
  • 在在~/.m2/settings.xml中添加如下
<server>
   <id>github</id>
    <username>YOUR_USERNAME</username>
    <password>YOUR_PASSWORD</password>
</server>

# 方式2
<server>
    <id>github</id>
    <password>OAUTH2TOKEN</password>
</server>
  • pom.xml
<?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>com.ychen.demo</groupId>
    <artifactId>demo</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
        <github.global.server>github</github.global.server>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.20</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <distributionManagement>
        <repository>
            <id>maven.repo</id>
            <name>Local Staging Repository</name>
            <url>file://${project.build.directory}/mvn-repo</url>
        </repository>
    </distributionManagement>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.8.2</version>
                <configuration>
                    <altDeploymentRepository>maven.repo::default::file://${project.build.directory}/mvn-repo</altDeploymentRepository>
                </configuration>
            </plugin>
            <plugin>
                <!-- Deploy the web site -->
                <groupId>com.github.github</groupId>
                <artifactId>site-maven-plugin</artifactId>
                <version>0.12</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>site</goal>
                        </goals>
                        <!-- select the Maven phase in which the plugin will be executed -->
                        <phase>deploy</phase>
                        <configuration>
                            <!-- Plugin configuration goes here -->
                            <server>github</server>
                            <!-- The commit message -->
                            <message>init git maven repository</message>
                            <!-- The location where the site is uploaded -->
                            <repositoryName>github-maven-repository</repositoryName> <!-- github repo name -->
                            <repositoryOwner>chniny</repositoryOwner> <!-- organization or user name  -->
                            <!-- Use merge or override the content -->
                            <merge>true</merge>
                            <outputDirectory>${project.build.directory}/mvn-repo</outputDirectory>
                            <branch>refs/heads/mvn-repo</branch>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

  • 控制台
"C:\Program Files\Java\jdk-11.0.13\bin\java.exe" -Dmaven.multiModuleProjectDirectory=C:\work\git\spring_learn_repo\maven\demo "-Dmaven.home=C:\Program Files\apache-maven-3.6.3" "-Dclassworlds.conf=C:\Program Files\apache-maven-3.6.3\bin\m2.conf" "-Dmaven.ext.class.path=C:\Program Files\JetBrains\IntelliJ IDEA 2021.1.3\plugins\maven\lib\maven-event-listener.jar" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2021.1.3\lib\idea_rt.jar=63845:C:\Program Files\JetBrains\IntelliJ IDEA 2021.1.3\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\apache-maven-3.6.3\boot\plexus-classworlds-2.6.0.jar;C:\Program Files\apache-maven-3.6.3\boot\plexus-classworlds.license" org.codehaus.classworlds.Launcher -Didea.version=2021.1.3 deploy
[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------< com.ychen.demo:demo >-------------------------
[INFO] Building demo 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\work\git\spring_learn_repo\maven\demo\src\main\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ demo ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ demo ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\work\git\spring_learn_repo\maven\demo\src\test\resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ demo ---
[INFO] No sources to compile
[INFO] 
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ demo ---
[INFO] No tests to run.
[INFO] 
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ demo ---
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ demo ---
[INFO] Installing C:\work\git\spring_learn_repo\maven\demo\target\demo-1.0-SNAPSHOT.jar to C:\Users\ychen\.m2\repository\com\ychen\demo\demo\1.0-SNAPSHOT\demo-1.0-SNAPSHOT.jar
[INFO] Installing C:\work\git\spring_learn_repo\maven\demo\pom.xml to C:\Users\ychen\.m2\repository\com\ychen\demo\demo\1.0-SNAPSHOT\demo-1.0-SNAPSHOT.pom
[INFO] 
[INFO] --- maven-deploy-plugin:2.8.2:deploy (default-deploy) @ demo ---
[INFO] Using alternate deployment repository maven.repo::default::file://C:\work\git\spring_learn_repo\maven\demo\target/mvn-repo
Downloading from maven.repo: file://C:\work\git\spring_learn_repo\maven\demo\target/mvn-repo/com/ychen/demo/demo/1.0-SNAPSHOT/maven-metadata.xml
Uploading to maven.repo: file://C:\work\git\spring_learn_repo\maven\demo\target/mvn-repo/com/ychen/demo/demo/1.0-SNAPSHOT/demo-1.0-20220513.115258-1.jar
Uploaded to maven.repo: file://C:\work\git\spring_learn_repo\maven\demo\target/mvn-repo/com/ychen/demo/demo/1.0-SNAPSHOT/demo-1.0-20220513.115258-1.jar (4.8 kB at 299 kB/s)
Uploading to maven.repo: file://C:\work\git\spring_learn_repo\maven\demo\target/mvn-repo/com/ychen/demo/demo/1.0-SNAPSHOT/demo-1.0-20220513.115258-1.pom
Uploaded to maven.repo: file://C:\work\git\spring_learn_repo\maven\demo\target/mvn-repo/com/ychen/demo/demo/1.0-SNAPSHOT/demo-1.0-20220513.115258-1.pom (3.1 kB at 784 kB/s)
Downloading from maven.repo: file://C:\work\git\spring_learn_repo\maven\demo\target/mvn-repo/com/ychen/demo/demo/maven-metadata.xml
Uploading to maven.repo: file://C:\work\git\spring_learn_repo\maven\demo\target/mvn-repo/com/ychen/demo/demo/1.0-SNAPSHOT/maven-metadata.xml
Uploaded to maven.repo: file://C:\work\git\spring_learn_repo\maven\demo\target/mvn-repo/com/ychen/demo/demo/1.0-SNAPSHOT/maven-metadata.xml (762 B at 254 kB/s)
Uploading to maven.repo: file://C:\work\git\spring_learn_repo\maven\demo\target/mvn-repo/com/ychen/demo/demo/maven-metadata.xml
Uploaded to maven.repo: file://C:\work\git\spring_learn_repo\maven\demo\target/mvn-repo/com/ychen/demo/demo/maven-metadata.xml (276 B at 92 kB/s)
[INFO] 
[INFO] --- site-maven-plugin:0.12:site (default) @ demo ---
[INFO] Creating 12 blobs
[INFO] Creating tree with 12 blob entries
[INFO] Creating commit with SHA-1: 1ef9a0295b5b26f437c137eabb6d958c1b31386e
[INFO] Creating reference refs/heads/mvn-repo starting at commit 1ef9a0295b5b26f437c137eabb6d958c1b31386e
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  44.141 s
[INFO] Finished at: 2022-05-13T19:53:41+08:00
[INFO] ------------------------------------------------------------------------

Process finished with exit code 0

  • 使用该依赖
<dependency>
    <groupId>YOUR.PROJECT.GROUPID</groupId>
    <artifactId>ARTIFACT-ID</artifactId>
    <version>VERSION</version>
</dependency>

<repository>
    <id>ARTIFACT-ID</id>
    <url>https://raw.github.com/flydean/github-maven-repository/mvn-repo/</url>
</repository>
posted @ 2022-05-13 17:03  DogLeftover  阅读(57)  评论(0编辑  收藏  举报