build.gradle

Summary

Maintainability
Test Coverage
/*
 * Copyright (c) 2016-2022 Armel Soro
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

// Top-level build file where you can add configuration options common to all sub-projects/modules.

final homePath = System.properties['user.home']

buildscript {
    ext.maoni_group = 'org.rm3l'
    ext.maoni_version = '10.0.0'

    ext.kotlin_version = '1.9.23'
    ext.anko_version = '0.10.8'

    ext.aboutlibraries_version = '8.9.4'

    repositories {
        maven {
            url "https://plugins.gradle.org/m2/"
        }
        jcenter()
        mavenCentral()
        google()
    }
    dependencies {
        classpath "com.mikepenz.aboutlibraries.plugin:aboutlibraries-plugin:${aboutlibraries_version}"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.android.tools.build:gradle:7.3.1'
        classpath "io.github.gradle-nexus:publish-plugin:2.0.0"
    }
}

apply plugin: "io.github.gradle-nexus.publish-plugin"

group = maoni_group
version = maoni_version

allprojects {
    repositories {
        jcenter()
        mavenCentral()
        google()
        maven { url 'https://jitpack.io' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

task javadoc {
    logger.info("Fake 'javadoc' task from root project")
}

task generatePomFileForProductionPublication {
    logger.info("Fake 'generatePomFileForProductionPublication' task from root project")
}

ext.getDebugSigningConfig = {
    return ['androiddebugkey', new File("${rootDir}/debug.keystore"), 'android', 'android']
}

ext.getReleaseSigningInfo = {
    android ->
        def storeFile = null
        def storePassword = null
        def keyAlias = null
        def keyPassword = null

        //Attempt to read keystore.properties file, if any first
        final propsFile = new File(homePath.toString() + "/.droid/", "maoni-keystore.properties")
        final configName = 'release'

        if (propsFile.exists() && android.signingConfigs.hasProperty(configName)) {
            logger.info("Using properties file located at " + propsFile.absolutePath)
            final props = new Properties()
            props.load(new FileInputStream(propsFile))
            storeFile = new File(props['keystore'].toString())
            storePassword = props['storePassword']
            keyAlias = props['keyAlias']
            keyPassword = props['keyPassword']

        } else if (System.console() != null) {
            storeFile = System.console().readLine("\nPlease enter path to keystore file: ")
            storeFile = new File(storeFile)
            storePassword = System.console().readPassword("\nPlease enter the store password: ")
            keyAlias = System.console().readLine("\nPlease enter the key alias: ")
            keyPassword = System.console().readPassword("\nPlease enter the key password: ")
        }

        return [storeFile, storePassword, keyAlias, keyPassword]

}

subprojects { project ->
    afterEvaluate {
        if (project.plugins.hasPlugin("java")) {
            project.sourceCompatibility = JavaVersion.VERSION_1_8
            project.targetCompatibility = JavaVersion.VERSION_1_8
        }

        project.tasks.withType(Test) { Test task ->
            task.jvmArgs << "-Djava.awt.headless=true"
        }
    }
}

File secretPropsFile = project.rootProject.file('local.properties')
if (secretPropsFile.exists()) {
    Properties p = new Properties()
    new FileInputStream(secretPropsFile).withCloseable { is ->
        p.load(is)
    }
    p.each { name, value ->
        ext[name] = value
    }
} else {
    ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID')
    ext["signing.password"] = System.getenv('SIGNING_PASSWORD')
    ext["signing.secretKeyRingFile"] = System.getenv('SIGNING_SECRET_KEY_RING_FILE')
    ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME')
    ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD')
    ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID')
}

nexusPublishing {
    // packageGroup = "org.rm3l"  //defaults to 'project.group'
    repositories {
        sonatype {
            stagingProfileId = project.ext.has('sonatypeStagingProfileId') ? project.ext.sonatypeStagingProfileId : ''
            username = project.ext.has('ossrhUsername') ? project.ext.ossrhUsername : ''
            password = project.ext.has('ossrhPassword') ? project.ext.ossrhPassword : ''
        }
    }
}