diff --git a/android/build.gradle b/android/build.gradle index 6ece2d6a0..a323f3419 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -1,5 +1,5 @@ apply plugin: 'com.android.library' - +apply plugin: 'maven' apply plugin: 'de.undercouch.download' import de.undercouch.gradle.tasks.download.Download @@ -253,4 +253,11 @@ android { project.afterEvaluate { preBuild.dependsOn prepareAllLibs + +apply from: rootProject.file('gradle/release.gradle') + +task sourcesJar(type: Jar) { + from android.sourceSets.main.java.srcDirs + classifier = 'sources' } +artifacts.add('archives', sourcesJar)} diff --git a/android/gradle.properties b/android/gradle.properties new file mode 100644 index 000000000..edb417466 --- /dev/null +++ b/android/gradle.properties @@ -0,0 +1,21 @@ +# +# Copyright 2014-present Facebook, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +POM_NAME=Sonar +POM_DESCRIPTION=Sonar SDK for Android +POM_ARTIFACT_ID=sonar +POM_PACKAGING=aar + diff --git a/gradle.properties b/gradle.properties index 40cb82f06..89dcb0184 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,20 @@ -GRADLE_VERSIONS_PLUGIN_VERSION=0.15.0 +# POM publishing constants +VERSION_NAME=0.0.1 +GROUP=com.facebook.sonar +POM_URL=https://github.com/facebook/sonar +POM_SCM_URL=https://github.com/facebook/sonar.git +POM_SCM_CONNECTION=scm:git:https://github.com/facebook/sonar.git +POM_SCM_DEV_CONNECTION=scm:git:git@github.com:facebook/sonar.git +POM_LICENSE_NAME=MIT +POM_LICENSE_URL=https://github.com/facebook/sonar/blob/master/LICENSE +POM_LICENSE_DIST=repo +POM_DEVELOPER_ID=facebook +POM_DEVELOPER_NAME=facebook +# Kotlin KOTLIN_VERSION=1.2.41 # Deps for publishing GRADLE_BINTRAY_PLUGIN_VERSION=1.8.0 +GRADLE_VERSIONS_PLUGIN_VERSION=0.15.0 ANDROID_MAVEN_GRADLE_PLUGIN_VERSION=2.1 diff --git a/gradle/android-maven-install.gradle b/gradle/android-maven-install.gradle new file mode 100644 index 000000000..d85d74ccc --- /dev/null +++ b/gradle/android-maven-install.gradle @@ -0,0 +1,53 @@ +/* + * Copyright 2014-present Facebook, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Configure the Android maven publication + +apply plugin: 'com.github.dcendents.android-maven' + +version = VERSION_NAME +group = GROUP +// Set the .aar / .jar base file name to match the artifact ID +// in case the module has a different name +project.archivesBaseName = POM_ARTIFACT_ID + +install { + repositories.mavenInstaller { + // This generates POM.xml with proper parameters + pom.project { + name POM_NAME + artifactId POM_ARTIFACT_ID + packaging POM_PACKAGING + description POM_DESCRIPTION + url projectUrl + + scm { + url scmUrl + connection scmConnection + developerConnection scmDeveloperConnection + } + + licenses projectLicenses + + developers { + developer { + id developerId + name developerName + } + } + } + } +} diff --git a/gradle/android-tasks.gradle b/gradle/android-tasks.gradle new file mode 100644 index 000000000..b614ed95e --- /dev/null +++ b/gradle/android-tasks.gradle @@ -0,0 +1,110 @@ +/* + * Copyright 2014-present Facebook, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +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.javaCompile) { + from variant.javaCompile.destinationDir + } + + androidJavadoc.doFirst { + classpath += files(android.bootClasspath) + classpath += files(variant.javaCompile.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) + } + } + } + zip.close() +} diff --git a/gradle/bintray.gradle b/gradle/bintray.gradle new file mode 100644 index 000000000..e32233188 --- /dev/null +++ b/gradle/bintray.gradle @@ -0,0 +1,79 @@ +/* + * Copyright 2014-present Facebook, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Upload to Bintray +apply plugin: 'com.jfrog.bintray' + +def getBintrayUsername() { + return project.hasProperty('bintrayUsername') ? property('bintrayUsername') : System.getenv('BINTRAY_USERNAME') +} + +def getBintrayApiKey() { + return project.hasProperty('bintrayApiKey') ? property('bintrayApiKey') : System.getenv('BINTRAY_API_KEY') +} + +def getBintrayGpgPassword() { + return project.hasProperty('bintrayGpgPassword') ? property('bintrayGpgPassword') : System.getenv('BINTRAY_GPG_PASSWORD') +} + +def getMavenCentralUsername() { + return project.hasProperty('mavenCentralUsername') ? property('mavenCentralUsername') : System.getenv('MAVEN_CENTRAL_USERNAME') +} + +def getMavenCentralPassword() { + return project.hasProperty('mavenCentralPassword') ? property('mavenCentralPassword') : System.getenv('MAVEN_CENTRAL_PASSWORD') +} + +def shouldSyncWithMavenCentral() { + return project.hasProperty('syncWithMavenCentral') ? property('syncWithMavenCentral').toBoolean() : false +} + +def dryRunOnly() { + return project.hasProperty('dryRun') ? property('dryRun').toBoolean() : false +} + +bintray { + user = getBintrayUsername() + key = getBintrayApiKey() + configurations = ['archives'] + pkg { + repo = bintrayRepo + userOrg = bintrayUserOrg + name = bintrayName + desc = bintrayDescription + websiteUrl = projectUrl + issueTrackerUrl = issuesUrl + vcsUrl = scmUrl + licenses = projectLicenses + dryRun = dryRunOnly() + override = true + publish = true + publicDownloadNumbers = true + version { + desc = bintrayDescription + gpg { + sign = true + passphrase = getBintrayGpgPassword() + } + mavenCentralSync { + sync = shouldSyncWithMavenCentral() + user = getMavenCentralUsername() + password = getMavenCentralPassword() + close = '1' // If set to 0, you have to manually click release + } + } + } +} diff --git a/gradle/gradle-mvn-push.gradle b/gradle/gradle-mvn-push.gradle new file mode 100644 index 000000000..2d3637185 --- /dev/null +++ b/gradle/gradle-mvn-push.gradle @@ -0,0 +1,96 @@ +/* + * Copyright 2013 Chris Banes + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +apply plugin: 'signing' + +version = VERSION_NAME +group = GROUP + +def isReleaseBuild() { + return !VERSION_NAME.contains('SNAPSHOT') +} + +def getReleaseRepositoryUrl() { + return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL + : "https://oss.sonatype.org/service/local/staging/deploy/maven2/" +} + +def getSnapshotRepositoryUrl() { + return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL + : "https://oss.sonatype.org/content/repositories/snapshots/" +} + +def getRepositoryUsername() { + return hasProperty('SONATYPE_NEXUS_USERNAME') ? SONATYPE_NEXUS_USERNAME : "" +} + +def getRepositoryPassword() { + return hasProperty('SONATYPE_NEXUS_PASSWORD') ? SONATYPE_NEXUS_PASSWORD : "" +} + +afterEvaluate { project -> + uploadArchives { + repositories { + mavenDeployer { + beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } + + pom.groupId = GROUP + pom.artifactId = POM_ARTIFACT_ID + pom.version = VERSION_NAME + + repository(url: getReleaseRepositoryUrl()) { + authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) + } + snapshotRepository(url: getSnapshotRepositoryUrl()) { + authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) + } + + pom.project { + name POM_NAME + packaging POM_PACKAGING + description POM_DESCRIPTION + url POM_URL + + scm { + url POM_SCM_URL + connection POM_SCM_CONNECTION + developerConnection POM_SCM_DEV_CONNECTION + } + + licenses { + license { + name POM_LICENSE_NAME + url POM_LICENSE_URL + distribution POM_LICENSE_DIST + } + } + + developers { + developer { + id POM_DEVELOPER_ID + name POM_DEVELOPER_NAME + } + } + } + } + } + } + + signing { + required { isReleaseBuild() && gradle.taskGraph.hasTask('uploadArchives') } + sign configurations.archives + } +} diff --git a/gradle/release-bintray.gradle b/gradle/release-bintray.gradle new file mode 100644 index 000000000..ea186e0ca --- /dev/null +++ b/gradle/release-bintray.gradle @@ -0,0 +1,49 @@ +/* + * Copyright 2014-present Facebook, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Set up everything required for releasing on Bintray +ext { + bintrayRepo = 'maven' + bintrayUserOrg = 'facebook' + bintrayName = "${GROUP}:${POM_ARTIFACT_ID}" + bintrayDescription = POM_DESCRIPTION + projectUrl = POM_URL + issuesUrl = 'https://github.com/facebook/litho/issues' + scmUrl = POM_SCM_URL + scmConnection = POM_SCM_CONNECTION + scmDeveloperConnection = POM_SCM_DEV_CONNECTION + + publishedGroupId = GROUP + libraryName = 'litho' + artifact = 'litho' + + developerId = POM_DEVELOPER_ID + developerName = POM_DEVELOPER_NAME + + projectLicenses = { + license { + name = POM_LICENSE_NAME + url = POM_LICENSE_URL + distribution = POM_LICENSE_DIST + } + } +} + +// Set up the Android Maven publication (POM etc.) +apply from: rootProject.file('gradle/android-maven-install.gradle') + +// Upload to Bintray +apply from: rootProject.file('gradle/bintray.gradle') diff --git a/gradle/release.gradle b/gradle/release.gradle new file mode 100644 index 000000000..0528caaf8 --- /dev/null +++ b/gradle/release.gradle @@ -0,0 +1,24 @@ +/* + * Copyright 2014-present Facebook, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// Common Android tasks for all releases that generate Javadocs, sources, etc. +apply from: rootProject.file('gradle/android-tasks.gradle') + +// Upload to Bintray +apply from: rootProject.file('gradle/release-bintray.gradle') + +// Upload directly to standard Maven Central (for SNAPSHOTs) +apply from: rootProject.file('gradle/gradle-mvn-push.gradle')