https://github.com/mark1708/github-maven-package-example
This is a guide on using Apache Maven registry
https://github.com/mark1708/github-maven-package-example
github-registry java maven
Last synced: 7 months ago
JSON representation
This is a guide on using Apache Maven registry
- Host: GitHub
- URL: https://github.com/mark1708/github-maven-package-example
- Owner: Mark1708
- License: mit
- Created: 2022-11-28T22:10:45.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-11-29T14:48:41.000Z (over 3 years ago)
- Last Synced: 2025-03-01T18:46:16.108Z (12 months ago)
- Topics: github-registry, java, maven
- Language: Java
- Homepage:
- Size: 20.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Apache Maven registry


### [Russian version](https://github.com/Mark1708/github-maven-package-example/blob/main/README.ru.md)
You can configure Apache Maven to publish packages to GitHub Packages and to use packages stored on GitHub Packages as dependencies in a Java project.
## Generate a standard Maven project
```bash
mvn archetype:generate -DgroupId=example.com -DartifactId=github-maven-package-example -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false
mvn validate
mvn clean install
```
## Edit pom.xml
#### Update properties
```xml
UTF-8
11
11
11
0.12
GITHUB_USERNAME
GITHUB_REPO
```
> Replacing and with real data
#### Add distributionManagement
```xml
github
GitHub ${github.repository.owner} Apache Maven Packages
https://maven.pkg.github.com/${github.repository.owner}/${github.repository.name}
```
#### Update build
```xml
org.apache.maven.plugins
maven-plugin-plugin
3.6.0
true
org.apache.maven.plugins
maven-site-plugin
3.9.1
org.apache.maven.plugins
maven-compiler-plugin
3.8.1
${java.version}
${java.version}
org.apache.maven.plugins
maven-release-plugin
3.0.0-M1
```
## Add simple class User
```java
public class User {
private String username;
private String password;
public User(String username, String password) {
this.username = username;
this.password = password;
}
public User() {
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof User)) return false;
User user = (User) o;
return getUsername().equals(user.getUsername()) && getPassword().equals(user.getPassword());
}
@Override
public int hashCode() {
return Objects.hash(getUsername(), getPassword());
}
@Override
public String toString() {
return "User{" +
"username='" + username + '\'' +
", password='" + password + '\'' +
'}';
}
}
```
## Let's make sure we didn't make a mistake and install the packages
```bash
mvn validate
mvn clean install
```
## Preparing for deployment
Edit the file `~/.m2/settings.xml ` to prove to Github the seriousness of their intentions)
`vim ~/.m2/settings.xml`
```xml
github
github
central
https://repo1.maven.org/maven2
github
https://maven.pkg.github.com//
true
github
```
> Replace , and with real data
> You need an access token to `publish, install, and delete private, internal, and public packages`.
## Deploy
Everything is simple here:
```shell
mvn deploy
```
## Result
In your repository you can find such a charm:
```xml
example.com
github-maven-package-example
1.0-SNAPSHOT
```
If the repository is public, then the dependency is available to everyone!
> But if you did it in private, then on the device where you will use this dependency, you will need to configure the same `~/.m2/settings.xml ` file.
### Good luck !)
## Other Resources
- [Boilerplates](https://github.com/Mark1708/boilerplates) - Templates for various projects
- [Cheat-Sheets](https://github.com/Mark1708/cheat-sheets) - Command Reference for various tools and technologies
- [Habr](https://habr.com/ru/users/Mark1708/posts) - Here I sometimes write about something interesting
## Contact
Created by [Gurianov Mark](https://mark1708.github.io/) - feel free to contact me!
#### +7(962)024-50-04 | mark1708.work@gmail.com | [github](http://github.com/Mark1708)
