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.
Go to https://bintray.com/.
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.
I decided to sign up on Github.
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.
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.
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.
Click Add New Repository.
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/
Click Create.
The repository is now created.
Click Add New Package from the repository screen to create a package. Make it corresponding to each library to be published.
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.
The package has been created.
It is better to upload automatically using gradle described later, but you can also upload already built jar etc. manually.
Click New Viewsion under Versions.
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.
After creating the version, select Upload Files from the top of the screen.
Then you will see the following screen
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.
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 ...
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.
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.
You can get the API Key by selecting Edit Profile → API Key. This key must not be disclosed. Let's not leak.
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 "
bintray_user=xxxxxx
bintray_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
** * 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.
After uploading, execute Publish from the Bintray site.
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>'
}
}
From Linked to on the package page, click Add to jCenter.
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.
Jcetenr has been added under Linked to.
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