How to publish a library in jCenter

Do you make an OSS library?

In Java and Android development, it is common sense that OSS libraries are fetched from the maven repository, and the style of downloading and using jars and aars is rarely seen.

Since it is a library created with much effort, let's publish it in the maven repository so that it can be widely used. If you host the output file on http / https, the maven repository will become a repository by itself, so if you use Github, you can store it on Github Pages to complete the stray maven repository. I also do this. However, this requires the stray repository path to be added to the project. just like this.

repositories {
    maven {
        url 'https://ohmae.github.com/maven'
    }
}

There is a little resistance on the part of publishing, and on the side of using it, I don't want to use stray repositories. Each time you add one OSS, the repository will increase. The build is likely to be slow. If you can put it in mavenCentral or jcenter, you don't need to write the path directly. In recent Android, the repository is described like this by default.

repositories {
    google()
    jcenter()
}

jcenter is written by default, but in the case of mavenCentral, you need to add mavenCentral ().

So I would like to explain how to publish the library in jcenter. (Although it was said to be easy, I had a lot of trouble, so don't say what number it was.)

Since I took screenshots in the process of publishing some libraries, it may be confusing because each library is different, but please read as appropriate.

Sign Up to Bintray

Go to https://bintray.com/.

image.png

You can easily create an account for an OSS project. In the case of OSS plan, it seems that the condition is 10GB storage and 1TB / m download, but if you use it as a maven repository that distributes jar / aar, there are few projects that get caught in this condition.

Click "Sign Up Here" in For an Open Source Account

A screen like this will appear, so enter the necessary information. If you have an OSS project, you probably have a Github account, so it's a good idea to sign up with your Github account. If you are worried about linking accounts, please.

image.png

I decided to sign up on Github.

image.png

As this happens, give permission to the binary-bot. It's read-only access to the email address of the account data, so I think it's something to worry about.

image.png

Your name, account name, and email address will be entered in the Github information. It seems that you can change anything other than your email address. In my case, I could use the account name on Github as it is, but there may be cases where it cannot be used. Perhaps. I don't know what will happen in that case.

image.png

It will be like this when you can create an account.

Since the password is not set immediately after creating the account, it is better to set the password from Edit Your Profile.

Create a maven repository in Bintray

Click Add New Repository.

image.png

It seems that private repositories are charged. With OSS you don't even have to keep it private and leave it Public.

Name Although it is a repository name, it is used in the URL and has the form "https://bintray.com/ / / ". If you want to create multiple repositories for each purpose, you can name them accordingly, but it seems that many people use maven for maven repositories. Type A pull-down menu will appear, so select Maven. Default Licenses It's an option, so you don't have to enter it, but if you know the license to use, enter it. I chose MIT. Description This is the description of this repository. I couldn't come up with a good explanation, so I left it blank.

Click Create.

image.png

The repository is now created.

Make a package

Click Add New Package from the repository screen to create a package. Make it corresponding to each library to be published.

image.png

Name It is not a Java package name. You can use the Java package name, but let's give it a name that simply represents this library. I decided to set groupId + artifactId. There should be no problem with artifactId alone, but I have given it a strangely simple name. Description Enter the description of the library to be published License This is required, so let's enter the license to use. If the license has not been decided yet, it cannot be published. Let's decide and start again. Tags Since it is a tag used for search etc., let's enter category information such as "Android". You can set more than one. Maturity Select from "Official", "Stable", "Development", and "Experimental". Put in the right things. Website It's not required, but if you publish the source code on Github, you can use the URL there. Issue tracker This is also not required, but you can use the issue URL on Github as well. Version Control Required. Enter the URL of Github.

The last checkbox is whether to publish the number of downloads, but it doesn't matter which one.

Click Create Package.

image.png

The package has been created.

Upload manually

It is better to upload automatically using gradle described later, but you can also upload already built jar etc. manually.

Create version

Click New Viewsion under Versions.

image.png

Name Enter a version name such as 0.0.1. I haven't found any rules for version names, but as long as you publish it, make sure to give it a meaningful version name according to Semantic Versioning. Release date Set the release date. It contains today's date by default, but it doesn't seem to be required. Description Description of this version is not required.

You can create an empty version by clicking Create Version.

File upload

After creating the version, select Upload Files from the top of the screen.

image.png

Then you will see the following screen

image.png

Target Repository Path Specify the path to upload the file.

For example, "net.mm2d.log" in this screenshot is a library with groupId net.mm2d, artifactIdlog, and version 0.0.2, so the destination to upload the pom file is" net. /mm2d/log/0.0.2 "is specified.

You can upload by dragging and dropping the pom / jar / aar file to be uploaded to Click to Add Files at the bottom right of the screen and clicking Save Changes.

image.png

Once the upload is complete, you can see the uploaded file on the Files tab. maven-metadata.xml is automatically created one level up.

In addition, it will not be published just by uploading. You need to click Publish. I uploaded it to a strange path! In such cases, deleting it before publishing has no effect. However, even uploading from Gradle, which will be described later, did not seem to be able to automate Publish, so after uploading each time, you need to log in to bintray and publish. A little troublesome ...

Allow upload from Gradle

A Gradle plugin is provided, and you can easily upload it by writing the settings in build.gradle. Use this method for normal development. If you are using CI, you can also upload the CI build artifacts as they are.

Create GPG Key ... not

It seems that you can sign the library by uploading the GPG Key, but I couldn't get rid of the question that I had to upload both the public key and the private key ... no, that's it. I decided not to. It seems that you can have your signature signed with the Bintray key without preparing it yourself, so you may choose that.

Get the API Key

You can get the API Key by selecting Edit Profile → API Key. This key must not be disclosed. Let's not leak.

Save the API Key in a local file

Since it is uploaded from Gradle, it is necessary to have Gradle read the API Key, but if you write it in a file in the public repository, anyone can upload it. Write it in a place where you won't accidentally commit. (If by any chance you accidentally publish it, you can revoke it and invalidate the key, so don't panic)

If it is " /.gradle/gradle.properties", it is outside the repository, there is a low risk of accidentally leaking the operation, and it is read by default so it is not troublesome, so the person who writes here It seems that there are many. If the file does not exist, create it. For Windows, it is "C: \ Users \ \ .gradle \ gradle.properties". Write as follows. The variable name doesn't have to be the same, but it should be unique.

bintray_user=xxxxxx
bintray_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Fix build.gradle

** * This build.gradle no longer works properly in the new version. Rewritten with build.gradle to upload to jCenter (bintray) **

Use the official plugin gradle-bintray-plugin. Add the following to dependenies of the root project. For Android library, also add android-maven-gradle-plugin.

buildscript {
...
    dependencies {
...
        classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
    }
}

Apply the plugin in the module build.gradle. Apply only com.jfrog.bintray for Java and 2 plugins for Android

apply plugin: 'com.jfrog.bintray'
apply plugin: 'com.github.dcendents.android-maven'

We will set the information for uploading, but since similar information will be set repeatedly, we will define the basic information first. If the module name and artifactId are different names, it seems that the jar name will be the module name unless the artifactId is set in archivesBaseName.

https://github.com/ohmae/preference-activity-compat shows the setting to upload aar. When using it, write the following in dependencies and use it.

implementation 'net.mm2d:preference:0.0.2'

In this case, the groupId is "net.mm2d", the artifactId is "preference", the version is "0.0.2", and the upload destination package is "net.mm2d.preference". Also, since the module name of the library is "lib", which is different from artifactId, it is necessary to set archivesBaseName.

def versionMajor = 0
def versionMinor = 0
def versionPatch = 2

group 'net.mm2d'
archivesBaseName = 'preference'
version "${versionMajor}.${versionMinor}.${versionPatch}"

def libraryId = 'log-android'
def siteUrl = 'https://github.com/ohmae/preference-activity-compat'
def githubUrl = 'https://github.com/ohmae/preference-activity-compat'

You can upload by defining the task as follows using this definition value.

bintray {
    user = project.hasProperty('bintray_user') ? bintray_user : ''
    key = project.hasProperty('bintray_key') ? bintray_key : ''
    configurations = ['archives']

    pkg {
        repo = 'maven'
        name = project.group + '.' + libraryId
        licenses = ['MIT']
        websiteUrl = siteUrl
        issueTrackerUrl = githubUrl + '/blob/master/LICENSE'
        vcsUrl = githubUrl + '.git'
        issueTrackerUrl = githubUrl + '/issues'
        publicDownloadNumbers = true
        version {
            name = project.version
        }
    }
}

install {
    repositories.mavenInstaller {
        pom.project {
            name libraryId
            url siteUrl

            packaging 'aar'
            groupId project.group
            artifactId libraryId
            version project.version

            licenses {
                license {
                    name 'The MIT License'
                    url 'https://opensource.org/licenses/MIT'
                    distribution 'repo'
                }
            }
            scm {
                connection githubUrl + '.git'
                url githubUrl
            }
        }
    }
}

You can now upload by running the bintrayUpload task. image.png

After uploading, execute Publish from the Bintray site. image.png

It will now be published from Bintray's personal repository. (Not published on jcenter yet) To use it at this point, you need to specify the following repository url.

repositories {
    maven {
        url 'https://dl.bintray.com/<account name>/<Repository name>'
    }
}

Publish on jCenter

From Linked to on the package page, click Add to jCenter. image.png

Make a request to publish via jCenter. The Group ID must be unique. At the stage of deciding the package name, you probably chose a unique domain-based thing, so entering the package name should be fine.

You will receive an approval reply within a few days of sending. In my case, it took about half a day, but I think that the people inside are responding manually, so it may be affected by the congestion of the application. Let's wait patiently.

image.png

Jcetenr has been added under Linked to.

image.png

Now it's published on jcenter and you can use it just by adding it to dependencies without adding the stray repository to gradle.

The library I worked on is around here. For your reference.

that's all.

Recommended Posts

How to publish a library in jCenter
How to insert a video in Rails
How to display a web page in Java
How to run a djUnit task in Ant
How to add a classpath in Spring Boot
How to create a theme in Liferay 7 / DXP
How to implement a like feature in Rails
How to easily create a pull-down in Rails
How to automatically generate a constructor in Eclipse
How to clear all data in a particular table
How to create a Java environment in just 3 seconds
How to implement a like feature in Ajax in Rails
How to use Z3 library in Scala with Eclipse
How to leave a comment
How to create a Spring Boot project in IntelliJ
How to create a data URI (base64) in Java
How to display a browser preview in VS Code
[How to insert a video in haml with Rails]
How to write a date comparison search in Rails
How to store Rakuten API data in a table
How to mock a super method call in PowerMock
How to use JDD library in Scala with Eclipse
How to convert A to a and a to A using AND and OR in Java
How to convert a file to a byte array in Java
[Rails 6] How to set a background image in Rails [CSS]
[Rails] How to load JavaScript in a specific view
How to write a core mod in Minecraft Forge 1.15.2
How to insert a video
How to create a method
[Ruby/Rails] How to generate a password in a regular expression
How to change a string in an array to a number in Ruby
How to create a placeholder part to use in the IN clause
How to select a specified date by code in FSCalendar
How to display a graph in Ruby on Rails (LazyHighChart)
How to add the same Indexes in a nested array
How to develop and register a Sota app in Java
How to create a service builder portlet in Liferay 7 / DXP
How to set up a proxy with authentication in Feign
How to use Lombok in Spring
How to find May'n in XPath
How to add columns to a table
How to hide scrollbars in WebView
How to run JUnit in Eclipse
How to iterate infinitely in Ruby
[Rails] How to write in Japanese
How to make a Java container
How to master programming in 3 months
How to sign a Minecraft MOD
How to get parameters in Spark
[Java] How to create a folder
How to insert an external library
How to write a ternary operator
How to use InjectorHolder in OpenAM
[Swift] How to send a notification
How to make a splash screen
How to introduce jQuery in Rails 6
How to make a Maven project
How to name variables in Java
How to set Lombok in Eclipse
How to make a Java array
How to concatenate strings in java