Skip to content
This repository has been archived by the owner on Nov 4, 2022. It is now read-only.

Commit

Permalink
Merge pull request #68 from zeoflow/buildSrc
Browse files Browse the repository at this point in the history
created `buildSrc` folder
  • Loading branch information
teogor authored Mar 23, 2021
2 parents 0991fa5 + aa645fe commit 52ec6a9
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 122 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.2'
classpath 'com.android.tools.build:gradle:4.1.3'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
212 changes: 212 additions & 0 deletions buildSrc/upload.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
apply plugin: 'maven-publish'
apply plugin: 'maven'
apply plugin: 'signing'

version = VERSION_NAME
group = GROUP

static def localMavenRepo() {
'file://' + new File(System.getProperty('user.home'), '.m2/repository').absolutePath
}

@SuppressWarnings("GrMethodMayBeStatic")
def isReleaseBuild() {
return !VERSION_NAME.contains("SNAPSHOT")
}

def getReleaseRepositoryUrl() {
return hasProperty('LOCAL') ? localMavenRepo()
: hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL
: 'https://oss.sonatype.org/service/local/staging/deploy/maven2/'
}

def getSnapshotRepositoryUrl() {
return hasProperty('LOCAL') ? localMavenRepo()
: hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL
: 'https://oss.sonatype.org/content/repositories/snapshots/'
}

def getRepositoryUsername() {
return hasProperty('USERNAME') ? USERNAME : (hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : '')
}

def getRepositoryPassword() {
return hasProperty('PASSWORD') ? PASSWORD : (hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : '')
}

afterEvaluate { project ->
def isAndroidProject = project.plugins.hasPlugin('com.android.application') || project.plugins.hasPlugin('com.android.library')
// To avoid uploading the default empty jar artifact in the project root directory, we use a custom
// configuration to specify which artifacts we want to upload.
uploadArchives {
repositories {
mavenDeployer {
// allow uploading through FTP protocol with the following command:
// gradle uploadArchives -PSNAPSHOT_REPOSITORY_URL=ftp://host/repo/path -PUSERNAME=uname -PPASSWORD=passwd
configuration = configurations.create('deployerJars')

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.whenConfigured { pom ->
pom.packaging = POM_PACKAGING
}

// Dependencies are only automatically included by the release plugin if the release
// variant is built. Since we've disabled the release variant to improve build
// times, we need to add the dependencies to the pom file explicitly.
if (isAndroidProject) {
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')

project.configurations.implementation.allDependencies.each {
def groupId = it.group
def artifactId = it.name
// If we specify an artifact id that differs from the project name, it won't
// match. To avoid that, we look up the artifact id (and group) by property
// for any project dependencies.
// TODO: there must be a neater way to do this.
if (it instanceof ProjectDependency) {
def properties = it.getDependencyProject().getProperties()
groupId = properties.get("GROUP")
artifactId = properties.get("POM_ARTIFACT_ID")
}
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', groupId)
dependencyNode.appendNode('artifactId', artifactId)
dependencyNode.appendNode('version', it.version)
dependencyNode.appendNode('scope', 'compile')
}
}
}

pom.project {
name = POM_NAME
description = POM_DESCRIPTION
url = POM_URL

scm {
url POM_SCM_URL
connection POM_SCM_CONNECTION
developerConnection POM_SCM_DEV_CONNECTION
}

licenses {
license {
name = 'Simplified BSD License'
url = 'http://www.opensource.org/licenses/bsd-license'
distribution = 'repo'
}
license {
name = 'The Apache Software License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution = 'repo'
}
}

developers {
developer {
id = POM_DEVELOPER_ID
name = POM_DEVELOPER_NAME
email = POM_DEVELOPER_EMAIL
}
}
}
}
}
}

signing {
required { isReleaseBuild() && gradle.taskGraph.hasTask('uploadArchives') }
sign configurations.archives
}

if (isAndroidProject) {
def variants = project.android.libraryVariants.findAll {
it.buildType.name.equalsIgnoreCase('debug')
}

def getAndroidSdkDirectory = project.android.sdkDirectory

def getAndroidJar = "${getAndroidSdkDirectory}/platforms/${project.android.compileSdkVersion}/android.jar"

task androidJavadocs(type: Javadoc, dependsOn: assembleDebug) {
source = variants.collect { it.getJavaCompileProvider().get().source }
classpath = files(
getAndroidJar,
project.file("build/intermediates/classes/debug")
)
doFirst {
classpath += files(variants.collect { it.javaCompile.classpath.files })
}
options {
links("http://docs.oracle.com/javase/7/docs/api/")
linksOffline("http://d.android.com/reference",
"${getAndroidSdkDirectory}/docs/reference")
}

exclude '**/R.java'
}

def cleanJavadocTask = task("cleanJavadocTask", type: Delete) {
delete androidJavadocs.destinationDir
} as Task
project.clean.dependsOn(cleanJavadocTask)

task androidJavadocsJar(type: Jar, dependsOn: androidJavadocs) {
archiveClassifier.set('javadoc')
from androidJavadocs.destinationDir
baseName "${project.name}"
}

task androidSourcesJar(type: Jar) {
archiveClassifier.set('sources')
from project.android.sourceSets.main.java.source
baseName "${project.name}"
}

task androidLibraryJar(type: Jar, dependsOn: compileDebugJavaWithJavac /* == variant.javaCompile */) {
from compileDebugJavaWithJavac.destinationDir
exclude '**/R.class'
exclude '**/R$*.class'
baseName "${project.name}"
}

artifacts {
archives androidLibraryJar
archives androidSourcesJar
// This is unnecessary with a release variant because by default the release variant
// includes the release aar in archives. Since we've disabled our release variants and
// want to include an aar, we need to manually specify the task that produces the aar
// here.
archives project.tasks.bundleDebugAar
}
} else if (project.plugins.hasPlugin('java') || project.plugins.hasPlugin('java-library')) {
task sourcesJar(type: Jar, dependsOn: classes) {
archiveClassifier.set('sources')
from sourceSets.main.allSource
}

task javadocsJar(type: Jar, dependsOn: javadoc) {
archiveClassifier.set('javadoc')
from javadoc.destinationDir
}

artifacts {
archives sourcesJar
archives javadocsJar
}
}
logger.info("Published artifacts in ${configurations.archives}:")
configurations.archives.artifacts.files.files.each { logger.info("\t$it") }
}
11 changes: 5 additions & 6 deletions material-elements/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
plugins {
id 'com.android.library'
id 'kotlin-android'
}

ext {
androidXVersions = [
Expand Down Expand Up @@ -176,7 +178,4 @@ android {
}
}

apply from: "${rootProject.projectDir}/material-elements/maven-push.gradle"
repositories {
mavenCentral()
}
apply from: '../buildSrc/upload.gradle'
18 changes: 6 additions & 12 deletions material-elements/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
POM_NAME=MaterialElements
POM_ARTIFACT_ID=material-elements
POM_PACKAGING=aar

VERSION_NAME=2.3.1
VERSION_CODE=12
GROUP=com.zeoflow

POM_DESCRIPTION=Material Elements help developers execute Material Elements. Developed by a core team of engineers and UX designers, these elements enable a reliable development workflow to build beautiful and functional Android apps.
POM_URL=https://github.com/zeoflow/material-elements
POM_SCM_URL=https://github.com/zeoflow/material-elements
POM_SCM_CONNECTION=scm:[email protected]:zeoflow/material-elements.git
POM_SCM_DEV_CONNECTION=scm:[email protected]:zeoflow/material-elements.git
POM_LICENCE_NAME=The Apache Software License, Version 2.0
POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
POM_LICENCE_DIST=repo
POM_DEVELOPER_ID=zeoflow
POM_DEVELOPER_NAME=ZeoFlow
POM_DEVELOPER_EMAIL[email protected]

org.gradle.daemon=true
POM_NAME=MaterialElements

POM_PACKAGING=jar

POM_ARTIFACT_ID=material-elements

NEXUS_USERNAME=
NEXUS_PASSWORD=
signing.keyId=
signing.password=
signing.secretKeyRingFile=
103 changes: 0 additions & 103 deletions material-elements/maven-push.gradle

This file was deleted.

0 comments on commit 52ec6a9

Please sign in to comment.