Close the release of the jar or AAR to MVN (using GitHub as the repository), integrated through the Gradle dependency approach

Source: Internet
Author: User
Tags sha1 sonatype

Users who are developing with Android studio want to integrate the jar, AAR files through the MAVEN remote repository, but how are these files published?

Often developers will publish jar files to Sonatype to provide integration to other developers, but Sonatype requires the source code, and in some cases the publisher does not want to provide the source code, so the method described in this article can be used.

Here's how to create a warehouse on GitHub, publish the jar and AAR files to maven, and how to integrate them.

The first step:

Create a repo on github.com dedicated to use as a Maven repository. such as Https://github.com/ione/mvn-repo-ione

Step Two:

Clone the file locally using the git clone command.

Step Three:

1. Publishing AAR files

Add the files in the project catalog build.gradle :

[Java]View PlainCopy  
  1. Apply plugin: ' maven '
  2. android{
  3. // ...  
  4. }
  5. Ext is a gradle closure allowing the declaration of global Properties
  6. ext {
  7. publish_group_id = ' Com.ione '
  8. publish_artifact_id = ' demo '
  9. Publish_version = Android.defaultConfig.versionName
  10. }
  11. uploadarchives {
  12. Repositories.mavendeployer {
  13. def deploypath = File (GetProperty (' Aar.deploypath '))
  14. Repository (URL: "File://${deploypath.absolutepath}")
  15. Pom.project {
  16. GroupId Project. publish_group_id
  17. Artifactid Project. publish_artifact_id
  18. Version Project. Publish_version
  19. }
  20. }
  21. }

Which aar.deployPath can be gradle.properties specified in the file:

[Java]View PlainCopy  
    1. Aar.deploypath=e:\\dev\\workspace\\mvn-repo-ione\\repository

The path is the directory selected for the second step of clone repo.

Before you publish an AAR file, you only need to execute the command in the project directory:

[Java]View PlainCopy 
    1. Gradlew uploadarchives

You can generate the required files to upload to GitHub as a maven repository. Then push the updated files in the directory selected in the second step Clonerepo to GitHub to complete the release.

2. Release the jar file

Install the local jar package into this directory by using the following command:

[Java]View PlainCopy 
    1. MVN install:install-file-dgroupid=com.ione-dartifactid=demo-dversion=1.0-dfile=e:\dev\libs\ com.ione.demo.jar-dpackaging=jar-dgeneratepom=true-dlocalrepositorypath=e:\dev\workspace\ione\ Mvn-repo-ione\repository-dcreatechecksum=true

Note the package name and path

After running the above command, a maven file is required in the local directory, for example:

[Java]View PlainCopy 
  1. Mvn-repo-demogit: (Master) tree
  2. .
  3. ├──license
  4. ├──readme.md
  5. └──repository
  6. └──com
  7. └──ione
  8. └──demo
  9. ├── 1.0
  10. │├──demo-1.0.jar
  11. │├──demo-1.0.jar.md5
  12. │├──demo-1.0.JAR.SHA1
  13. │├──demo-1.0.pom
  14. │├──deno-1.0.pom.md5
  15. │└──demo-1.0.POM.SHA1
  16. ├──maven-metadata-local.xml
  17. ├──maven-metadata-local.xml.md5
  18. └──maven-metadata-local.xml.sha1
  19. 5 directories, files



The resulting MAVEN file is then push to GitHub with Git push to complete the release.

Fourth Step:

Integration of jar files or AAR files in Android Studio

In the project's Build.grade file, add:

[Java]View PlainCopy 
    1. repositories {
    2. Jcenter ()
    3. Maven {URL "https://raw.githubusercontent.com/ione/mvn-repo-ione/master/repository"}
    4. }

[Java]View PlainCopy 
    1. dependencies {
    2. Compile ' com.ione:demo:1.0 '
    3. }




Integration can be completed.

Close the release of the jar or AAR to MVN (using GitHub as the repository), integrated through the Gradle dependency approach

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.