Release jar or aar to mvn (using github as the repository), integrate with gradle dependency, and use githubgradle
Android Studio developers all want to integrate jar and aar files through maven remote repository. But how can these files be released?
Generally, developers publish jar files to sonatype for integration with other developers. However, sonatype requires that the source code be provided. In some cases, the publisher does not want to provide the source code, in this way, you can use the method described in this article.
The following describes how to create a repository on github, publish jar and aar files to maven, and integrate them.
Step 1:
Create a repo on github.com for maven repository. Example https://github.com/ione/mvn-repo-ione
Step 2:
Run the git clone command to clone the file to the local machine.
Step 3:
1. Publish the aar File
In the project directorybuild.gradle
File:
apply plugin: 'maven'android{ // ...}// ext is a gradle closure allowing the declaration of global propertiesext { PUBLISH_GROUP_ID = 'com.ione' PUBLISH_ARTIFACT_ID = 'demo' PUBLISH_VERSION = android.defaultConfig.versionName}uploadArchives { repositories.mavenDeployer { def deployPath = file(getProperty('aar.deployPath')) repository(url: "file://${deployPath.absolutePath}") pom.project { groupId project.PUBLISH_GROUP_ID artifactId project.PUBLISH_ARTIFACT_ID version project.PUBLISH_VERSION } }}
Whereaar.deployPath
You cangradle.properties
File:
aar.deployPath=E:\\dev\\workspace\\mvn-repo-ione\\repository
The path is the directory selected by clone repo in step 2.
Before publishing the aar file, run the following command in the project directory:
gradlew uploadArchives
You can generate a file to be uploaded to github as a maven repository. Then, push the updated files in the directory selected by Step 2 clonerepo to github to complete the release.
2. Release the jar File
Run the following command to install the local jar package to this directory:
mvn install:install-file -DgroupId=com.ione -DartifactId=demo -Dversion=1.4.1 -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 preceding command, the required maven file is available in the local directory, for example:
mvn-repo-demogit:(master) tree . ├── LICENSE ├── README.md └── repository └── com └── ione └── demo ├── 1.4.1 │ ├── demo-1.4.1.jar │ ├── demo-1.4.1.jar.md5 │ ├── demo-1.4.1.jar.sha1 │ ├── demo-1.4.1.pom │ ├── deno-1.4.1.pom.md5 │ └── demo-1.4.1.pom.sha1 ├── maven-metadata-local.xml ├── maven-metadata-local.xml.md5 └── maven-metadata-local.xml.sha1 5 directories, 11 files
Then, use git push to push the generated maven file to github to complete the release.
Step 4:
Integrate jar files or aar files in Android Studio
Add the following in the build. grade file of the project:
repositories { jcenter() maven { url "https://raw.githubusercontent.com/ione/mvn-repo-ione/master/repository" } }
dependencies { compile 'com.ione.demo' }
You can complete the integration.