Skip to content

Commit

Permalink
[andoid] publishing to maven central (pytorch#53568)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: pytorch#53568

Bintray, JCenter are going to be unavailable on May 1st

https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/

Migrating publishing to Maven Central the same way as other fb oss projects, reference PR https://github.com/pytorch/pytorch/pull/53568/files

to publish
```
./android/gradlew -p android publish
```

<img width="697" alt="Screen Shot 2021-03-09 at 3 14 08 PM" src="https://user-images.githubusercontent.com/6638825/110551387-3e3fc000-80ea-11eb-9604-4e69d6e6d085.png">

Test Plan: Imported from OSS

Reviewed By: dreiss

Differential Revision: D26928884

Pulled By: IvanKobzarev

fbshipit-source-id: 8754c93a2542405870e2621be5b3f14e3d0081b9
  • Loading branch information
IvanKobzarev authored and facebook-github-bot committed Mar 10, 2021
1 parent 05e0ea9 commit 5658ab5
Show file tree
Hide file tree
Showing 10 changed files with 11 additions and 335 deletions.
4 changes: 1 addition & 3 deletions .circleci/docker/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ buildscript {

dependencies {
classpath 'com.android.tools.build:gradle:4.1.2'
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.0"
classpath "com.github.dcendents:android-maven-gradle-plugin:2.1"
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.9.8"
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.14.2'
}
}

Expand Down
2 changes: 2 additions & 0 deletions .circleci/scripts/publish_android_snapshot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ else
echo "ndk.dir=/opt/ndk" >> $GRADLE_LOCAL_PROPERTIES

echo "SONATYPE_NEXUS_USERNAME=${SONATYPE_NEXUS_USERNAME}" >> $GRADLE_PROPERTIES
echo "mavenCentralRepositoryUsername=${SONATYPE_NEXUS_USERNAME}" >> $GRADLE_PROPERTIES
echo "SONATYPE_NEXUS_PASSWORD=${SONATYPE_NEXUS_PASSWORD}" >> $GRADLE_PROPERTIES
echo "mavenCentralRepositoryPassword=${SONATYPE_NEXUS_PASSWORD}" >> $GRADLE_PROPERTIES

echo "signing.keyId=${ANDROID_SIGN_KEY}" >> $GRADLE_PROPERTIES
echo "signing.password=${ANDROID_SIGN_PASS}" >> $GRADLE_PROPERTIES
Expand Down
4 changes: 1 addition & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ allprojects {

dependencies {
classpath 'com.android.tools.build:gradle:4.1.2'
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:${GRADLE_BINTRAY_PLUGIN_VERSION}"
classpath "com.github.dcendents:android-maven-gradle-plugin:${ANDROID_MAVEN_GRADLE_PLUGIN_VERSION}"
classpath "org.jfrog.buildinfo:build-info-extractor-gradle:4.9.8"
classpath 'com.vanniktech:gradle-maven-publish-plugin:0.14.2'
}
}

Expand Down
6 changes: 1 addition & 5 deletions android/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ ABI_FILTERS=armeabi-v7a,arm64-v8a,x86,x86_64
VERSION_NAME=1.8.0-SNAPSHOT
GROUP=org.pytorch
MAVEN_GROUP=org.pytorch
SONATYPE_STAGING_PROFILE=orgpytorch
POM_URL=https://github.com/pytorch/pytorch/tree/master/android
POM_SCM_URL=https://github.com/pytorch/pytorch.git
POM_SCM_CONNECTION=scm:git:https://github.com/pytorch/pytorch
Expand All @@ -13,11 +14,6 @@ POM_ISSUES_URL=https://github.com/pytorch/pytorch/issues
POM_LICENSE_DIST=repo
POM_DEVELOPER_ID=pytorch
POM_DEVELOPER_NAME=pytorch
syncWithMavenCentral=true

GRADLE_BINTRAY_PLUGIN_VERSION=1.8.0
GRADLE_VERSIONS_PLUGIN_VERSION=0.15.0
ANDROID_MAVEN_GRADLE_PLUGIN_VERSION=2.1

# Gradle internals
org.gradle.internal.repository.max.retries=1
Expand Down
38 changes: 0 additions & 38 deletions android/gradle/android_maven_install.gradle

This file was deleted.

93 changes: 5 additions & 88 deletions android/gradle/android_tasks.gradle
Original file line number Diff line number Diff line change
@@ -1,94 +1,11 @@
import java.nio.file.Files
import java.nio.file.Paths
import java.io.FileOutputStream
import java.util.zip.ZipFile

// Android tasks for Javadoc and sources.jar generation

afterEvaluate { project ->
if (POM_PACKAGING == 'aar') {
task androidJavadoc(type: Javadoc, dependsOn: assembleDebug) {
source += files(android.sourceSets.main.java.srcDirs)
failOnError false
// This task will try to compile *everything* it finds in the above directory and
// will choke on text files it doesn't understand.
exclude '**/BUCK'
exclude '**/*.md'
}

task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
classifier = 'javadoc'
from androidJavadoc.destinationDir
}

task androidSourcesJar(type: Jar) {
classifier = 'sources'
from android.sourceSets.main.java.srcDirs
}

android.libraryVariants.all { variant ->
def name = variant.name.capitalize()
task "jar${name}"(type: Jar, dependsOn: variant.javaCompileProvider) {
from variant.javaCompileProvider.get().destinationDir
}

androidJavadoc.doFirst {
classpath += files(android.bootClasspath)
classpath += files(variant.javaCompileProvider.get().classpath.files)
// This is generated by `assembleDebug` and holds the JARs generated by the APT.
classpath += fileTree(dir: "$buildDir/intermediates/bundles/debug/", include: '**/*.jar')

// Process AAR dependencies
def aarDependencies = classpath.filter { it.name.endsWith('.aar') }
classpath -= aarDependencies
aarDependencies.each { aar ->
// Extract classes.jar from the AAR dependency, and add it to the javadoc classpath
def outputPath = "$buildDir/tmp/aarJar/${aar.name.replace('.aar', '.jar')}"
classpath += files(outputPath)

// Use a task so the actual extraction only happens before the javadoc task is run
dependsOn task(name: "extract ${aar.name}").doLast {
extractEntry(aar, 'classes.jar', outputPath)
}
}
}
}

artifacts.add('archives', androidJavadocJar)
artifacts.add('archives', androidSourcesJar)
}

if (POM_PACKAGING == 'jar') {
task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from javadoc.destinationDir
}

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

artifacts.add('archives', javadocJar)
artifacts.add('archives', sourcesJar)
}
}

// Utility method to extract only one entry in a zip file
private def extractEntry(archive, entryPath, outputPath) {
if (!archive.exists()) {
throw new GradleException("archive $archive not found")
}

def zip = new ZipFile(archive)
zip.entries().each {
if (it.name == entryPath) {
def path = Paths.get(outputPath)
if (!Files.exists(path)) {
Files.createDirectories(path.getParent())
Files.copy(zip.getInputStream(it), path)
task headersJar(type: Jar) {
archiveClassifier.set('headers')
from("$rootDir/cxx/") {
include '**/*.h'
}
}
artifacts.add('archives', headersJar)
}
zip.close()
}
64 changes: 0 additions & 64 deletions android/gradle/bintray.gradle

This file was deleted.

99 changes: 0 additions & 99 deletions android/gradle/gradle_maven_push.gradle

This file was deleted.

4 changes: 1 addition & 3 deletions android/gradle/release.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
apply from: rootProject.file('gradle/android_tasks.gradle')

apply from: rootProject.file('gradle/release_bintray.gradle')

apply from: rootProject.file('gradle/gradle_maven_push.gradle')
apply plugin: 'com.vanniktech.maven.publish'
32 changes: 0 additions & 32 deletions android/gradle/release_bintray.gradle

This file was deleted.

0 comments on commit 5658ab5

Please sign in to comment.