PokeAPI Library π
Tykok
Posted on October 5, 2023
I deploy my first library on Maven Central: https://central.sonatype.com/artifact/fr.tykok/pokeapi. β¨π
You can use this library to wrap easily all the data from pokeapi.co API.
Here I'm gonna explain why I create PokeAPI-Kotlin
for the pokeapi.co, and how I deploy it on Maven Central.
You can find all about this project on GitHub: PokeApi-Kotlin.
You are free to contribute to this project ππ½
What is a library?
Many library are available on Maven Central, but what is a library? π€
A library is just a piece of reusable code created by a developer or a team. A library can contains specific functions, classes or modules that can be used by other developers to simplify their work when creating software.
In short, a library is a set of pre-written codes that developers can use to solve common problems and accelerate the development of their software.
It's like a toolbox for developers, where they can find ready-made solutions for their needs.
Why I create a library π
I create this library to improve my skills and to understand how a library is deployed to Maven Central. My goal was also to create my own tool that I would use later, and that others can use.
π§πΌβπ» For this project, I used Kotlin with Gradle Kotlin DSL.This desire also came from a desire to create an application on the Play Store.
I wanted to create an Android application, to improve myself but also to understand how to deploy an application on the Play Store.
The aim was also to have one more app to add to my portfolio, and above all to have fun!
Problem: the Kotlin library offered on pokeapi.co has been out of date for a while (2021) and I've been getting errors when installing dependencies.
I didn't look far to correct this problem, as I saw an opportunity to create my own library that I'd later use for my application project.
That's how I managed to deploy my very first library on Maven Central!
How I deploy it on Maven Central
To deploy a package to Maven Central, you need to have an account on Jira.
π¬ Go to Jira to create your account.When itβs done, you need to create an Issue on Jira with your logged account. When you create an issue, you need to provide many information about your project :
-
Group Id
: For me it wasfr.tykok.pokeapi
- Project URL: Link it to your GitHub repository
- SCM URL: The URL to your source control system (just add
.git
to your GitHub URL)
Configure your Graddle Kotlin DSL
First, you need to define two variable will be used soon at the top of your build.gradle.kts
file. Here is mine :
description = "PokeApi is a simple library you can use to make request to get data about PokΓ©mon."
group = "fr.tykok"
version = "0.0.3"
val artifact = "pokeapi"
val projectName = "PokeApi"
val sonarSnapshotUri = "https://s01.oss.sonatype.org/content/repositories/snapshots/"
val sonarReleaseUri = "https://s01.oss.sonatype.org/content/repositories/releases/"
To define which URL, you need to use, I create a small function in my build.gradle.kts
file :
fun getUriSonar(): String = if (version.toString().endsWith("SNAPSHOT")) {
sonarSnapshotUri
} else {
sonarReleaseUri
}
Next, you need to add this plugins
in your build.gradle.kts
file :
plugins {
`maven-publish`
}
And finally, you need to configure the Maven publication:
publishing {
publications {
create<MavenPublication>("library") {
from(components["java"])
}
repositories {
maven {
url = uri(getUriSonar())
name = projectName
group = group
version = version.toString()
description = description
credentials {
username = project.findProperty("ossrh.username") as String?
?: System.getenv("OSSRH_USERNAME")
password = project.findProperty("ossrh.password") as String?
?: System.getenv("OSSRH_PASSWORD")
}
}
}
}
π If you want, you can check the documentation for MavenPublication
.
You need to add the credentials
too in the gradle.properties
:
ossrh.username="username"
ossrh.password="password"
π Here, I use Sytem.getenv()
function to get the credentials from Github Actions too.
If you want, you can check the main documentation I follow to publish my library.
What's the next step ?
Next step for me⦠Create a Pokedex on the Play Store with this library!
If you want, you can contribute to this project on GitHub !
Follow me
Twitter: https://twitter.com/TreportElie1
GitHub: https://github.com/Tykok
Medium: https://medium.com/@tykok
Posted on October 5, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.