DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • How To Deploy Helidon Application to Kubernetes With Kubernetes Maven Plugin
  • Deploy MuleSoft App to CloudHub2 Using GitHub Actions CI/CD Pipeline
  • Ensuring Reliable Microservice Deployment With Spring Boot Build Info Maven Plugin
  • How To Approach Dependency Management in Java [Video]

Trending

  • How TIBCO Is Evolving Integration for the Multi-Cloud Era
  • Multi-Tenancy With Keycloak, Angular, and SpringBoot
  • Build a Digital Collectibles Portal Using Flow and Cadence (Part 1)
  • Five Tools for Data Scientists to 10X their Productivity
  1. DZone
  2. Coding
  3. Java
  4. Introducing Random Generator to Maven Central

Introducing Random Generator to Maven Central

With the project grunt work done, it's time to put our Random Generator onto Maven Central for everyone to use, including a simple example of the library in action.

John Vester user avatar by
John Vester
CORE ·
Feb. 16, 17 · Tutorial
Like (3)
Save
Tweet
Share
78.45K Views

Join the DZone community and get the full member experience.

Join For Free

Continuing with my series on a library I have created, called RandomGenerator, I am going to focus on the steps necessary to getting the library into Maven Central so that others can utilize my creation in their Java projects. I will also include a simple example of using RandomGenerator in a Maven project.

If you need to get up to speed on RandomGenerator, below are links to my prior articles in this series:

  • Building a Random Generator

  • Inside the Random Generator

  • Advanced Options for Random Generator

If you are interested in seeing my actual code or JavaDocs, they can be found at the following URLs:

  • https://gitlab.com/johnjvester/RandomGenerator
  • http://johnjvester.gitlab.io/RandomGenerator-JavaDoc/

Publishing to Maven Central

The process to add your project into Maven Central is quite detailed. The reason for this is to ensure a minimum level of quality within their repository. These same requirements include providing metadata so that end-users are able to find all the relevant details on your contribution.

At a high level, the steps required to add your component into Maven Central are listed below:

  • Supply JavaDoc and Source Files

  • Sign Files with GPG/PGP

  • Sufficient Metadata

    • groupId

    • artifactId

    • Version

    • Project Name

    • Description

    • URL

    • License Information

    • Developer Information

    • Source Control (SCM) Information

You can read more about this process here:

http://central.sonatype.org/pages/requirements.html

Once you are ready to begin the process, the required steps are listed here:

http://central.sonatype.org/pages/producers.html

At first glance, reviewing the Producers page may seem like the process is very complicated. However, I was able to figure everything out in my spare time, and I am far from an expert on everything involved with the process.

Once finished, your project will appear on Maven Central or any of the related mirrors. Below, is a link to the 1.2 version of RandomGenerator: RandomGenerator 1.2 on Maven Central

Using RandomGenerator in a Maven Project

With RandomGenerator 1.2 available for use in Maven Central, the library can be added to your project without much effort. Using IntelliJ, I was able to do so following the steps provided below:

  • Launch IntelliJ

  • Select File | New Project ...

  • Select Maven option and single-click Next

  • Enter a groupId and artifictId for you test project. I used a groupId of test and an artifact of testing, just for fun.

  • Single-click the Next button to continue.

  • Enter a Project Name, which I simply called testing, and single-click the Finish button.

  • Open the pom.xml and include the following dependency:

<dependencies>
    <dependency>
        <groupId>com.gitlab.johnjvester</groupId>
        <artifactId>random-generator</artifactId>
        <version>1.2</version>
    </dependency>
</dependencies>
  • Navigate to the src/main/java folder and create a new class using File | New | Java Class

  • Provide a name for your Java class. I simply chose Test as my class name.

  • I decided to mimic the example in the README.md for RandomGenerator, which introduced an inner class called Destination:

public static class Destination {
    private String name;
    private Integer rating;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getRating() {
        return rating;
    }

    public void setRating(Integer rating) {
        this.rating = rating;
    }
}
  • I then added a main() method for my Test class, which included a reference to randomGenerator:

public static void main(String[] args) {
RandomGenerator randomGenerator = new RandomGenerator();
}

  • At this point, the Test class has access to the RandomGenerator library, without having to seek and find the jar file.

  • I then added some code (which I realize is very simplistic) to map out the options in the README.md on GitLab for RandomGenerator. The full main() method is shown below:

public static void main(String[] args) {
    RandomGenerator randomGenerator = new RandomGenerator();
    ArrayList<Destination> myList = new ArrayList<Destination>();

    Destination destination = new Destination();
    destination.setName("Boston, MA");
    destination.setRating(2);
    myList.add(destination);

    destination = new Destination();
    destination.setName("Las Vegas, NV");
    destination.setRating(3);
    myList.add(destination);

    destination = new Destination();
    destination.setName("Maui, HI");
    destination.setRating(5);
    myList.add(destination);

    destination = new Destination();
    destination.setName("Miami, FL");
    destination.setRating(4);
    myList.add(destination);

    destination = new Destination();
    destination.setName("New York, NY");
    destination.setRating(1);
    myList.add(destination);

    destination = new Destination();
    destination.setName("San Diego, CA");
    destination.setRating(4);
    myList.add(destination);

    destination = new Destination();
    destination.setName("Tampa, FL");
    destination.setRating(5);
    myList.add(destination);

    System.out.println("before");

    for (Destination thisDestination : myList) {
        System.out.println("name = " + thisDestination.getName());
    }

    List<Destination> myRandomizedList = randomGenerator.randomize(myList);

    System.out.println("after - standard");

    for (Destination thisDestination : myRandomizedList) {
        System.out.println("name = " + thisDestination.getName());
    }

    myRandomizedList = randomGenerator.randomize(myList, true);

    System.out.println("after - standard with rating");

    for (Destination thisDestination : myRandomizedList) {
        System.out.println("name = " + thisDestination.getName());
    }
}
  • The example provides outputs for the original list, then an unranked sort of the list, followed by a weighted list sort of the original list.

  • Running the main() method within IntelliJ produced the following results:

before
name = Boston, MA
name = Las Vegas, NV
name = Maui, HI
name = Miami, FL
name = New York, NY
name = San Diego, CA
name = Tampa, FL
after - standard
name = Boston, MA
name = Miami, FL
name = Tampa, FL
name = New York, NY
name = San Diego, CA
name = Las Vegas, NV
name = Maui, HI
after - standard with rating
name = Tampa, FL
name = Miami, FL
name = Maui, HI
name = San Diego, CA
name = Boston, MA
name = Las Vegas, NV
name = New York, NY

Process finished with exit code 0

Conclusion

When I started working on my project over the recent holiday break, I had planned to continue working on an application I started working on a few years ago. As I looked at the randomization code in the application, I felt like it would provide more value as a stand-alone library. Now, spending some of my free time focused on this effort has produced the reality that is RandomGenerator 1.2.

It feels great to give back to the open source community and feedback, suggestions and contributions are certainly welcome. I don't have any grand plans for version 1.3 of RandomGenerator, but I am not opposed to any new ideas either.

Have a really great day!

Apache Maven

Opinions expressed by DZone contributors are their own.

Related

  • How To Deploy Helidon Application to Kubernetes With Kubernetes Maven Plugin
  • Deploy MuleSoft App to CloudHub2 Using GitHub Actions CI/CD Pipeline
  • Ensuring Reliable Microservice Deployment With Spring Boot Build Info Maven Plugin
  • How To Approach Dependency Management in Java [Video]

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: