This project serves as a parent POM for managing Spring Boot applications, centralizing the Spring Boot version and shared configurations across multiple modules.
- Spring Boot Version Management: Centralizes the version of Spring Boot used across all child modules to ensure consistency and simplify updates.
- Common Plugin Configurations: Provides a common setup for Maven plugins, including:
- Spotless Code Formatter: Enforces code formatting rules using the Spotless plugin, ensuring code quality and consistency across the project.
- Java 17
- Spring Boot 3.4.1
- Apache Maven 3.8.6
-
Generate a Personal Access Token:
Go to your GitHub account -> Settings -> Developer settings -> Personal access tokens -> Tokens (classic) -> Generate new token (classic):
- Fill out the Note field:
Pull packages. - Set the scope:
read:packages(to download packages)
- Click Generate token.
- Fill out the Note field:
-
Set Up Maven Authentication:
In your local Maven
settings.xml, define the GitHub repository authentication using the following structure:<servers> <server> <id>github-spring-common-parent</id> <username>USERNAME</username> <password>TOKEN</password> </server> </servers>
NOTE: Replace
USERNAMEwith your GitHub username andTOKENwith the personal access token you just generated. -
Inherit from the Parent POM: In your child modules, configure the parent and repositories as follows in the
pom.xml:<parent> <groupId>com.erebelo</groupId> <artifactId>spring-common-parent</artifactId> <version>1.0.0</version> </parent>
<repositories> <repository> <id>github-spring-common-parent</id> <url>https://maven.pkg.github.com/erebelo/spring-common-parent</url> </repository> </repositories>
NOTE: Make sure to update the version of the parent POM as needed based on the project’s versioning.
-
Add Dependencies: Add your specific dependencies to the child module's
pom.xmlas needed. -
Build Your Project: When you build your project, the Spotless plugin will automatically format your code according to the specified rules.
Use the following command to build and format the project:
mvn clean installTo publish a new version of the package to GitHub Packages, follow these steps:
-
Generate a Personal Access Token:
Go to GitHub account -> Settings -> Developer settings -> Personal access tokens -> Tokens (classic) -> Generate new token (classic).
- Fill out the Note field:
Package publishing. - Set the following scopes:
write:packages(to publish packages)read:packages(to download packages)
- Click Generate token.
- Fill out the Note field:
-
Set Up Maven Authentication:
In your local Maven
settings.xml, define the GitHub repository authentication using the following structure:<servers> <server> <id>github-spring-common-parent</id> <username>USERNAME</username> <password>TOKEN</password> </server> </servers>
NOTE: Replace
USERNAMEwith your GitHub username andTOKENwith the personal access token you just generated. -
Configure Repository for Package Publishing:
To enable publishing and retrieval from GitHub Packages, ensure the following configuration is set in the
pom.xml:<distributionManagement> <repository> <id>github-spring-common-parent</id> <name>GitHub Packages - spring-common-parent</name> <url>https://maven.pkg.github.com/erebelo/spring-common-parent</url> </repository> </distributionManagement>
-
Update the Package Version:
-
Create a release branch from the
mainbranch, namedrelease-X.X.X, whereX.X.Xis the new version number you want to publish:git checkout main git checkout -b release-2.0.0
-
Update the version in pom.xml of the project to the desired new version number:
<version>2.0.0</version>
-
Commit and push the changes to the remote repository:
git add . git commit -m "Package release version 2.0.0" git push origin release-2.0.0
-
-
Deploy to GitHub Packages:
Inside IntelliJ IDEA, open your project and navigate to Maven -> Execute Maven Goal:
- Enter
deployand press Enter. This will runmvn deployusing the authentication settings from yoursettings.xml.
- Enter
-
Verify the Package:
Once the deployment is successful, navigate to your GitHub repository and go to the Packages section to verify that the new version of the package is listed.
-
Update the SNAPSHOT Version:
Update the
SNAPSHOTversion in pom.xml from themainbranch to the next one:<version>2.0.1-SNAPSHOT</version>