preface
- Because I open source a JAR package, I want to publish it to the public network. But publishing it to Maven’s central repository was too cumbersome, so I decided to build my own private server and petition it on the public network at the same time. After some research, Github was chosen as maven’s central repository. At the same time, I also referred to some tutorials published by other bloggers, but they were not very detailed, so I summarized the process myself. I’m sure you’ll understand after you read the details. Ps: There are Easter eggs at the end!!
Modify the Maven configuration file
- Find the local Maven configuration file
setting.xml
To findserversAdd the following content to the tag:<server> <! -- Remember this id for future jar packages --> <id>github</id> <username>Github login username</username> <password>Password for logging in to Github</password> </server> Copy the code
Create a Github repository
- Using Github as a repository for Maven also requires a Github repository to store the jar packages that Maven prints to be published so that they can be accessed on Github
- The github repository tutorial is not covered here. And the name of the repository I created was
maven-repository
3. Set a github profile name
- The reason for configuring this is to prevent the following errors from being thrown during publishing
[ERROR] Failed to execute goal com.github.github:site-maven-plugin:0.12:site (default) on project rfcore: Error creating commit: Invalid request. [ERROR] For 'properties/name', nil is not a string. [ERROR] For 'properties/name', nil is not a string. (422) [ERROR] -> [Help 1] Copy the code
Add poM configuration to publish JAR package
- In projects that need to publish jar packages (here I will publish the project’s
artifactId
callspring-boot-zookeeper-client-starter
Add the following content to the POM file in) :<properties> <! The name must be the same as the serverId of the Maven configuration file. <github.global.server>github</github.global.server> </properties> <build> <! All plugins below this tag are dependencies for uploading JAR packages --> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.0.2</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>3.5.1 track of</version> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <version>3.0.1</version> <executions> <execution> <phase>package</phase> <goals> <goal>jar</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-deploy-plugin</artifactId> <version>2.8.2</version> <configuration> <! Jar: jar: jar: jar: jar: jar: jar: jar: jar: jar <altDeploymentRepository>internal.repo::default::file://${project.build.directory}/maven-repository</altDeploymentRepository> </configuration> </plugin> <plugin> <groupId>com.github.github</groupId> <artifactId>site-maven-plugin</artifactId> <version>0.12</version> <configuration> <message>Maven artifacts for ${project.artifactId}-${project.version}</message> <noJekyll>true</noJekyll> <! -- Specify where to pick up the package and upload it to Github --> <outputDirectory>${project.build.directory}/maven-repository</outputDirectory> <! Refs /heads specifies the branch to upload, refs/heads specifies the branch to upload, refs/heads specifies the branch to upload, refs/heads specifies the branch to upload. If multiple JARS are published in the same branch at the same time, this overwrites... --> <branch>refs/heads/master</branch> <! -- Contains all the contents of the folder in the outputDirectory tag --> <includes> <include>/ * * *</include> </includes> <! Github stores the contents of the outputDirectory folder --> <repositoryName>maven-repository</repositoryName> <! - making the user Name, attention is not login user Name, the need after logging in, go to https://github.com/settings/profile page configuration Name attribute, [ERROR] Failed to execute goal com.github. Github :site-maven-plugin:0.12:site (default) on project rfcore: Error creating commit: Invalid request. [ERROR] For 'properties/name', nil is not a string. [ERROR] For 'properties/name', Nil is not a string. (422) [ERROR] -> [Help 1] ERROR --> <repositoryOwner>AvengerEug</repositoryOwner> </configuration> <executions> <execution> <goals> <goal>site</goal> </goals> <phase>deploy</phase> </execution> </executions> </plugin> </plugins> </build> Copy the code
- In the project root directory (The directory where the pom.xml file resides) Run the following command
mvn clean deploy Copy the code
- After executing this command, you can view the following files in the target directory: (ps: Maven-repository is configured in the above POM file, and everything in this folder will be uploaded to Github later)
Then access the project directly from GithubGithub.com/AvengerEug/…As you can see, all the files in the above image have been uploaded to Github
5. Add github JARS to your project
- Add a dependency to publish jar packages
<! -- Jar package dependencies just released, configured according to your actual release project --> <dependency> <groupId>com.eugene.sumarry</groupId> <artifactId>spring-boot-zookeeper-client-starter</artifactId> <version>0.0.1</version> </dependency> Copy the code
- Add remote warehouse address:
<repositories> <repository> <id>github</id> <name>avengerEug</name> <! -- 1. https://raw.github.com => Connection reset => Connection reset => Connection reset => Connection reset AvengerEug => github login user name 3. Maven-repository => store published JAR repository 4. Master => which branch obtains jar package --> <url>https://raw.github.com/AvengerEug/maven-repository/master</url> </repository> </repositories> Copy the code
- Matters needing attention:
1. The repository on Github is basically a branch corresponding to a published JAR package. If you need to pull jar packages from other branches, you need to add reposotiry configuration. 2. To distribute different jars in the same repository, you can use different branches of the repository (as described in configuring POM.xml), and then change the branch name in the repositoryCopy the code
Six, summarized
- Finally use this blog to recommend their own open source JAR package. Links:Github.com/AvengerEug/…, if you feel good, please give a Star
- I am a slow walker, but I never walk backwards.