How to upload JAR files to Nexus Repository
https://medium.com/@abhisri784/maven-nexus-deployment-a347e64f9222

How to upload JAR files to Nexus Repository

Step 1: Create a Nexus User

  1. Log in securely as the admin user.
  2. Go to Server Administrator and configuration symbol.
  3. In the left sidebar, navigate to Users.
  4. Create a local user with the necessary permissions to upload artifacts.

No alt text provided for this image

Step 2: Create a Role for the User

  1. Create a role that will be assigned to the user you created.
  2. Define the appropriate permissions for the role, granting upload access to the hosted repository

No alt text provided for this image


Now we can use this Nexus user in our project to give Gradle/Maven credentials to this user to connect to Nexus.

Step 3: Configure Gradle Project with Nexus

No alt text provided for this image
No alt text provided for this image

  1. Follow the instructions in this article to configure a Gradle project with Nexus: Link to Medium article

Step 4: Deploy Maven Artifact to Nexus Repository

  1. Ensure that the group ID of the Maven and Gradle artifacts is the same.
  2. Use the appropriate Maven or Gradle command to deploy the artifacts to the Nexus repository.

  • For Maven: Use the mvn deploy command.
  • For Gradle: Use the gradle publish command.
  • Follow the steps as it is in the below images:

No alt text provided for this image
No alt text provided for this image
No alt text provided for this image
No alt text provided for this image

As you can notice the group id of Maven and Gradle artifacts are the same (com.example)

No alt text provided for this image
No alt text provided for this image

So, because we have two Jar files that have the same groupId so they are grouped together so basically using groupId you can group the artifact inside the repository (here, java-maven-app is the Maven artifact and my-app is the Gradle artifact)

No alt text provided for this image

Bonus:

Nexus API:

  • The Nexus API can be used to interact with Nexus programmatically.
  • You can use the REST API with a user:password combination that has access to the desired repositories.
  • For Maven snapshots, use the appropriate REST API with the corresponding credentials.
  • For administrative tasks, you can use the REST API with the admin_user:password combination, which has access to all created repositories.

Some Examples:

Rest Api with user:pwd who has access to only maven-snapshots.

No alt text provided for this image

Rest Api with admin_user:pwd who has access to all created repositories.

No alt text provided for this image

Just go through these two parts:

Blob Store:

  • The Blob Store is responsible for storing the binary artifacts in Nexus.
  • You can configure the Blob Store settings according to your requirements.
  • Refer to the documentation for configuring Blob Stores in Nexus: Link to Sonatype documentation

Components and Assets:

Components, Repositories, and Repository Formats

The Nexus platform, with Nexus Repository Pro, Nexus Repository OSS, and Nexus IQ Server is all about working with…help.sonatype.com

Clean-up Policy and Schedule Task:

  • Nexus allows you to set up clean-up policies and schedule tasks for managing artifacts.
  • You can define rules for artifact retention based on criteria like age, number of versions, etc.
  • Configure clean-up policies and schedule tasks to keep your repositories organized and efficient.

No alt text provided for this image
No alt text provided for this image
By following the steps outlined in this article, you can successfully upload JAR files to your Nexus repository and streamline your artifact management process. With a Nexus user created, Maven and Gradle configured to connect to Nexus, and the knowledge of deploying artifacts using the provided commands, you are well-equipped to manage your project dependencies effectively. Additionally, understanding the Nexus API, configuring Blob Stores, and utilizing clean-up policies and scheduled tasks will further enhance your artifact management capabilities. Embrace the power of Nexus and take control of your software artifacts with confidence. Happy uploading!
Omkar Kadam

Associate Cybersecurity Consultant. Microsoft DevOps Certified.

1 年

Thanks for posting. Great insight and well articulated article.????????????????

回复

要查看或添加评论,请登录

社区洞察

其他会员也浏览了