JavaRush /Java Blog /Random EN /A guide to creating a client for the Skyscanner API and p...

A guide to creating a client for the Skyscanner API and publishing it to jCenter and Maven Central [Part 2]

Published in the Random EN group
A guide to creating a client for the Skyscanner API and publishing it to jCenver and Maven Central [Part 1]

Content:

A guide to creating a client for the Skyscanner API and publishing it to jCenter and Maven Central [Part 2] - 1

Part 2: Publishing the Client to JCenter and Maven Central

Now let's do the following step by step:
  • Create Sonatype account and register groupId via Jira issue;
  • Let's create a bintray account and a package for the client;
  • Let's prepare build.gradle for publication on bintray, publish it.

Step 1: create a bintray account and a package for the client

What is bintray and why do we need it? bintray is a library storage system that acts as an intermediary between JCenter, Maven Central, and other repositories. To create an account, follow this link and create an open-source account. Next, we create a repository in which the projects will be stored, as shown below: A guide to creating a client for the Skyscanner API and publishing it to jCenter and Maven Central [Part 2] - 2Fill in the required Name, Type and optionally Default Licenses and Description. In the Type field, select Maven, since we need it: A guide to creating a client for the Skyscanner API and publishing it to jCenter and Maven Central [Part 2] - 3Next, create a new package ( Add New Package ). Fill in the fields:
  • Name is a required field. In it, I usually put the same name as on GitHub;
  • Description - the field is optional, but it is better to fill it out so that if someone wants to use your solution, they at least know what it is;
  • License - here it is already necessary to select a license. This is generally a difficult question, and you need to think carefully about everything. I usually choose the license from Apache 2;
  • Tags - the same as Description: you can add, you can not add. Here, these are just tags by which you can find the project;
  • Maturity - here you should indicate at what stage the project is. Since my version is only 0.1, I set it to Development;
  • Website - here we indicate a link to the Github project ;
  • Issue tracker - link to Issues section in GitHub”
  • Version control - here is the same link to the project + add “.git” at the end: https://github.com/romankh3/skyscanner-flight-api-client.git .
A guide to creating a client for the Skyscanner API and publishing it to jCenter and Maven Central [Part 2] - 4And click Create Package.

Step 2: Create Sonatype account and register groupId via jira issue

We create an account in Sonatype and after creating we click on Create a new Jira ticket. Here we specify a link to the project, to .git as well as in bintray. A guide to creating a client for the Skyscanner API and publishing it to jCenter and Maven Central [Part 2] - 5A guide to creating a client for the Skyscanner API and publishing it to jCenter and Maven Central [Part 2] - 6This is what a Jira ticket will look like: A guide to creating a client for the Skyscanner API and publishing it to jCenter and Maven Central [Part 2] - 7A created Jira Issue will be processed by a human within 2-3 business days. If everything goes well, you will be told that the groupId - com.github.romankh3 has been prepared: A guide to creating a client for the Skyscanner API and publishing it to jCenter and Maven Central [Part 2] - 8Now we will bind the Sonatype account we created to bintray. To do this, go to the Edit profile section in bintray: A guide to creating a client for the Skyscanner API and publishing it to jCenter and Maven Central [Part 2] - 9Moving on!

Step 3: Preparing build.gradle to publish to bintray

For publishing on bintray, there is a plugin with which you can relatively conveniently and quickly publish the code. You need to add a new one to the plugins section:
plugins {
   id "com.jfrog.bintray" version "1.8.4"
}
For publishing, you need not only the client itself, but also the source code and javadocs. Add the following methods to the script:
task javadocJar(type: Jar) {
   classifier = 'javadoc'
   from javadoc
}

task sourcesJar(type: Jar) {
   classifier = 'sources'
   from sourceSets.main.allSource
}

artifacts {
   archives javadocJar, sourcesJar
}
Below is all the necessary information for publishing in Maven Central: name, description, link, who is the developer, license. Without this, Maven Central will not accept the project.
configure(install.repositories.mavenInstaller) {
   pom.project {
       inceptionYear '2019'
       name project.name
       packaging 'jar'
       description project.description

       url 'https://github.com/romankh3/skyscanner-flight-api-client'

       scm {
           connection 'scm:git:https://github.com/romankh3/skyscanner-flight-api-client'
           developerConnection 'scm:git:git@github.com:romankh3/skyscanner-flight-api-client.git'
           url 'https://github.com/romankh3/skyscanner-flight-api-client'
       }

       licenses {
           license {
               name 'The Apache Software License, Version 2.0'
               url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
           }
       }

       developers {
           developer {
               id 'romankh3'
               name 'Roman Beskrovnyi'
               email 'roman.beskrovnyy@gmail.com'
           }
       }
   }
}
And the information that is needed to publish to jCenter is the same information that is needed for bintray:
bintray {
   user = getProjectProperty "bintrayUserName"
   key = getProjectProperty "bintrayApiKey"
   configurations = ['archives']
   publish = true
   pkg {
       repo = 'maven'
       name = 'skyscanner-flight-api-client'
       licenses = ['Apache-2.0']
       labels = ['java', 'api-client ', ' skyscanner ', 'library ']
       publicDownloadNumbers = true

       //noinspection GroovyAssignabilityCheck
       version {
           name = project.version
           vcsTag = project.version
           gpg {
               sign = true
           }
           mavenCentralSync {
               sync = true
               user = getProjectProperty 'ossrhUsername'
               password = getProjectProperty 'ossrhPassword'
               close = '1' // '0' to NOT close
           }
       }
   }
}
The bintray plugin adds a gradle task for publishing - bintrayUpload , but for this to work, you also need to specify the bintray user and sonatype. To do this, I created an empty gradle.properties file , into which the values ​​are passed at the time of publishing:
bintrayUserName=bintray-name
bintrayApiKey=bintray-api-key
ossrhUsername=sonatypeAccountName
ossrhPassword=sonatypeAccountPassword
where bintray-api-key can be found, as shown in the picture below: A guide to creating a client for the Skyscanner API and publishing it to jCenter and Maven Central [Part 2] - 10The final build.gradle will look like this . After we write in the terminal or run through IDEA gradlew bintrayUpload and everything is ready! The result will be on the bintray account as shown below: A guide to creating a client for the Skyscanner API and publishing it to jCenter and Maven Central [Part 2] - 11This means that we have successfully published the client, but it is not yet in either Maven Central or jCentral. To add a client to jCenter, you need to click Add to jCenter , then enter the groupId under which the project will be, as follows: A guide to creating a client for the Skyscanner API and publishing it to jCenter and Maven Central [Part 2] - 12Now we wait until the request is processed. after that it will be possible to synchronize the client with jCenter. Within a day, I received a response that the request to add a client was confirmed: A guide to creating a client for the Skyscanner API and publishing it to jCenter and Maven Central [Part 2] - 13Now the last step is to add the client to Maven Central. To do this, you need to find the Maven Central option in the client package : We have A guide to creating a client for the Skyscanner API and publishing it to jCenter and Maven Central [Part 2] - 14already linked a Sonatype account, so all that remains is to click Sync , as shown below: A guide to creating a client for the Skyscanner API and publishing it to jCenter and Maven Central [Part 2] - 15And this is the desired answer as soon as Sonatype allows publishing to Maven Central: A guide to creating a client for the Skyscanner API and publishing it to jCenter and Maven Central [Part 2] - 16output that the validation was successful and the client was published successfully to Maven Central. This completes the publishing process to jCenter and Maven Central successfully! To whom it seemed that it was easy to do this - you are incredible people and it is difficult to surprise you :)

Part 3. Using the client for flights-monitoring

It's not serious to write something just like that, as long as it lies. The code should work, so right after the publication in the last part, I connect the client for the project that needs it - for flight-monitoring . For this:
  • I add one more dependency to pom.xml:

    <dependency>
      <groupId>com.github.romankh3</groupId>
      <artifactId>skyscanner-flight-api-client</artifactId>
      <version>0.1.8</version>
    </dependency>
  • remove the client package from the project;

  • I reuse imports on client links and instead of FlightPriceDto I use BrowseFlightPricesResponseDto;

  • and that's it :)

The result can be seen in an open Pull-Request 'e, which I don't merge into the master branch just so those who read the previous article won't be surprised. A guide to creating a client for the Skyscanner API and publishing it to jCenter and Maven Central [Part 2] - 17

Part 4: Summary

  • A client for the Skyscanner API has been written as a separate project .
  • The thorny path of publishing the client to Maven Central and jCenter through bintray has been done .
  • Successfully used the client for the needs of the project - flights-monitoring.
  • This article can be used as a step by step guide for those who want to get on the open-source path.

Useful links:

See also my other articles:
Comments
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION