apply plugin: 'com.android.library'
apply plugin: 'com.github.dcendents.android-maven'
apply plugin: 'com.jfrog.bintray'

ext {
	bintrayRepo = 'maven'
	bintrayName = 'pb'

	publishedGroupId = 'io.textile'
	libraryName = 'pb'
	artifact = 'pb'

	libraryDescription = 'Generated protobuf classes for Textile'

	siteUrl = 'https://github.com/textileio/go-textile'
	gitUrl = 'https://github.com/textileio/go-textile.git'

	libraryVersion = '<version>'

	developerId = 'textile'
	developerName = 'Textile'
	developerEmail = 'contact@textile.io'

	licenseName = 'The Apache Software License, Version 2.0'
	licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
	allLicenses = ["Apache-2.0"]
}

android {
    compileSdkVersion 28


    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    implementation 'androidx.appcompat:appcompat:1.0.0'
	api 'com.google.protobuf:protobuf-java:3.6.1'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
}

group = publishedGroupId
version = libraryVersion

install {
	repositories.mavenInstaller {
		pom.project {
			packaging 'aar'
			groupId publishedGroupId
			artifactId artifact

			name libraryName
			description libraryDescription
			url siteUrl

			licenses {
				license {
					name licenseName
					url licenseUrl
				}
			}
			developers {
				developer {
					id developerId
					name developerName
					email developerEmail
				}
			}
			scm {
				connection gitUrl
				developerConnection gitUrl
				url siteUrl
			}
		}

		pom.withXml {
			def dependenciesNode = asNode().getAt('dependencies')[0] ?: asNode().appendNode('dependencies')
			// Iterate over the implementation dependencies (we don't want the test ones), adding a <dependency> node for each
			configurations.api.allDependencies.each {
				// Ensure dependencies such as fileTree are not included.
				if (it.name != 'unspecified') {
					def dependencyNode = dependenciesNode.appendNode('dependency')
					dependencyNode.appendNode('groupId', it.group)
					dependencyNode.appendNode('artifactId', it.name)
					dependencyNode.appendNode('version', it.version)
				}
			}
		}
	}
}

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

task javadoc(type: Javadoc) {
	source = android.sourceSets.main.java.srcDirs
	classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
}

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

artifacts {
	archives javadocJar
	archives sourcesJar
}

bintray {
	user = String.valueOf(System.getenv("BINTRAY_USERNAME"))
	key = String.valueOf(System.getenv("BINTRAY_API_KEY"))

	configurations = ['archives']
	pkg {
		repo = bintrayRepo
		name = bintrayName
		desc = libraryDescription
		websiteUrl = siteUrl
		vcsUrl = gitUrl
		licenses = allLicenses
		dryRun = false
		publish = true
		override = false
		publicDownloadNumbers = true
		version {
			desc = libraryDescription
		}
	}
}
