diff --git a/gradle/convention/src/main/kotlin/AndroidApplicationConvention.kt b/gradle/convention/src/main/kotlin/AndroidApplicationConvention.kt index 0e5092c4bb1941616247a5f803088166875e11e1..108982e11cf623573d9bca58298b70730edbaa4b 100644 --- a/gradle/convention/src/main/kotlin/AndroidApplicationConvention.kt +++ b/gradle/convention/src/main/kotlin/AndroidApplicationConvention.kt @@ -1,7 +1,27 @@ +/* + * Quasseldroid - Quassel client for Android + * + * Copyright (c) 2024 Janne Mareike Koschinski + * Copyright (c) 2024 The Quassel Project + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + import com.android.build.api.dsl.ApplicationExtension import org.gradle.api.JavaVersion import org.gradle.api.Plugin import org.gradle.api.Project +import org.gradle.api.plugins.BasePluginExtension import org.gradle.kotlin.dsl.configure import util.git import java.util.* @@ -15,6 +35,18 @@ class AndroidApplicationConvention : Plugin<Project> { apply("justjanne.signing") } + val commit = git("rev-parse", "HEAD").orNull + val code = git("rev-list", "--count", "HEAD", "--tags").orNull + val name = git("describe", "--always", "--tags", "HEAD").orNull + + extensions.configure<BasePluginExtension> { + if (name == null) { + archivesName.set("${rootProject.name}") + } else { + archivesName.set("${rootProject.name}-$name") + } + } + extensions.configure<ApplicationExtension> { compileSdk = 35 @@ -24,23 +56,18 @@ class AndroidApplicationConvention : Plugin<Project> { applicationId = "${rootProject.group}.${rootProject.name.lowercase(Locale.ROOT)}" - val commit = git("rev-parse", "HEAD") - val name = git("describe", "--always", "--tags", "HEAD") - - versionCode = git("rev-list", "--count", "HEAD", "--tags")?.toIntOrNull() - versionName = git("describe", "--always", "--tags", "HEAD") + versionCode = code?.toIntOrNull() + versionName = name val fancyVersionName = if (commit == null || name == null) name else "<a href=\\\"https://git.kuschku.de/justJanne/QuasselDroid-ng/commit/$commit\\\">$name</a>" - buildConfigField("String", "GIT_HEAD", "\"${git("rev-parse", "HEAD") ?: ""}\"") + buildConfigField("String", "GIT_HEAD", "\"${git("rev-parse", "HEAD").getOrElse("")}\"") buildConfigField("String", "FANCY_VERSION_NAME", "\"${fancyVersionName ?: ""}\"") - buildConfigField("long", "GIT_COMMIT_DATE", "${git("show", "-s", "--format=%ct") ?: 0}L") + buildConfigField("long", "GIT_COMMIT_DATE", "${git("show", "-s", "--format=%ct").getOrElse("0")}L") signingConfig = signingConfigs.findByName("default") - setProperty("archivesBaseName", "${rootProject.name}-$versionName") - // Disable test runner analytics testInstrumentationRunnerArguments["disableAnalytics"] = "true" } @@ -58,6 +85,12 @@ class AndroidApplicationConvention : Plugin<Project> { unitTests.isIncludeAndroidResources = true } + packaging { + resources { + excludes.add("/META-INF/*.md") + } + } + lint { warningsAsErrors = true lintConfig = file("../lint.xml") diff --git a/gradle/convention/src/main/kotlin/AndroidLibraryConvention.kt b/gradle/convention/src/main/kotlin/AndroidLibraryConvention.kt index d5ffa54645b08d43835b4b3b98cb779a4a9772f0..d647c8ed39c43ba170b37f8f8b54748abcefafc2 100644 --- a/gradle/convention/src/main/kotlin/AndroidLibraryConvention.kt +++ b/gradle/convention/src/main/kotlin/AndroidLibraryConvention.kt @@ -1,9 +1,27 @@ -import org.gradle.api.JavaVersion +/* + * Quasseldroid - Quassel client for Android + * + * Copyright (c) 2024 Janne Mareike Koschinski + * Copyright (c) 2024 The Quassel Project + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + import com.android.build.api.dsl.LibraryExtension +import org.gradle.api.JavaVersion import org.gradle.api.Plugin import org.gradle.api.Project import org.gradle.kotlin.dsl.configure -import java.util.* class AndroidLibraryConvention : Plugin<Project> { override fun apply(target: Project) { @@ -30,6 +48,12 @@ class AndroidLibraryConvention : Plugin<Project> { targetCompatibility = JavaVersion.VERSION_11 } + packaging { + resources { + excludes.add("/META-INF/*.md") + } + } + lint { warningsAsErrors = true lintConfig = file("../lint.xml") diff --git a/gradle/convention/src/main/kotlin/KotlinAndroidConvention.kt b/gradle/convention/src/main/kotlin/KotlinAndroidConvention.kt index 26ea31548cf6716bcf21f8ef69b637a0ca78799f..20caf9cf412754cf27e20ce9d1ed0961ea2045ff 100644 --- a/gradle/convention/src/main/kotlin/KotlinAndroidConvention.kt +++ b/gradle/convention/src/main/kotlin/KotlinAndroidConvention.kt @@ -1,3 +1,22 @@ +/* + * Quasseldroid - Quassel client for Android + * + * Copyright (c) 2024 Janne Mareike Koschinski + * Copyright (c) 2024 The Quassel Project + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + import org.gradle.api.JavaVersion import org.gradle.api.Plugin import org.gradle.api.Project @@ -7,6 +26,7 @@ import org.gradle.jvm.toolchain.JavaLanguageVersion import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.provideDelegate import org.gradle.kotlin.dsl.withType +import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.tasks.KotlinCompile class KotlinAndroidConvention : Plugin<Project> { @@ -20,14 +40,14 @@ class KotlinAndroidConvention : Plugin<Project> { // Use withType to workaround https://youtrack.jetbrains.com/issue/KT-55947 tasks.withType<KotlinCompile>().configureEach { - kotlinOptions { + compilerOptions { // Set JVM target to 11 - jvmTarget = JavaVersion.VERSION_11.toString() + jvmTarget.set(JvmTarget.JVM_11) // Treat all Kotlin warnings as errors (disabled by default) // Override by setting warningsAsErrors=true in your ~/.gradle/gradle.properties val warningsAsErrors: String? by target - allWarningsAsErrors = warningsAsErrors.toBoolean() - freeCompilerArgs = freeCompilerArgs + listOf( + allWarningsAsErrors.set(warningsAsErrors.toBoolean()) + freeCompilerArgs.add( "-opt-in=kotlin.ExperimentalUnsignedTypes" ) } diff --git a/gradle/convention/src/main/kotlin/KotlinConvention.kt b/gradle/convention/src/main/kotlin/KotlinConvention.kt index 378f59d7f509527e12e131938dbbd1aff284c56b..0c8b834d4e47872f9daf0e393324fa1b7fe3b694 100644 --- a/gradle/convention/src/main/kotlin/KotlinConvention.kt +++ b/gradle/convention/src/main/kotlin/KotlinConvention.kt @@ -1,3 +1,22 @@ +/* + * Quasseldroid - Quassel client for Android + * + * Copyright (c) 2024 Janne Mareike Koschinski + * Copyright (c) 2024 The Quassel Project + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + import org.gradle.api.JavaVersion import org.gradle.api.Plugin import org.gradle.api.Project @@ -7,6 +26,7 @@ import org.gradle.jvm.toolchain.JavaLanguageVersion import org.gradle.kotlin.dsl.configure import org.gradle.kotlin.dsl.provideDelegate import org.gradle.kotlin.dsl.withType +import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.tasks.KotlinCompile class KotlinConvention : Plugin<Project> { @@ -20,14 +40,14 @@ class KotlinConvention : Plugin<Project> { // Use withType to workaround https://youtrack.jetbrains.com/issue/KT-55947 tasks.withType<KotlinCompile>().configureEach { - kotlinOptions { + compilerOptions { // Set JVM target to 11 - jvmTarget = JavaVersion.VERSION_11.toString() + jvmTarget.set(JvmTarget.JVM_11) // Treat all Kotlin warnings as errors (disabled by default) // Override by setting warningsAsErrors=true in your ~/.gradle/gradle.properties val warningsAsErrors: String? by target - allWarningsAsErrors = warningsAsErrors.toBoolean() - freeCompilerArgs = freeCompilerArgs + listOf( + allWarningsAsErrors.set(warningsAsErrors.toBoolean()) + freeCompilerArgs.add( "-opt-in=kotlin.ExperimentalUnsignedTypes" ) } diff --git a/gradle/convention/src/main/kotlin/SigningConvention.kt b/gradle/convention/src/main/kotlin/SigningConvention.kt index d2813f220a960c3251c37c2945cbeeee2ddfa0e9..c0c4a3e158f19e4daa54eb7546d6ad2c50bbe646 100644 --- a/gradle/convention/src/main/kotlin/SigningConvention.kt +++ b/gradle/convention/src/main/kotlin/SigningConvention.kt @@ -1,3 +1,22 @@ +/* + * Quasseldroid - Quassel client for Android + * + * Copyright (c) 2024 Janne Mareike Koschinski + * Copyright (c) 2024 The Quassel Project + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + import com.android.build.api.dsl.ApplicationExtension import org.gradle.api.Plugin import org.gradle.api.Project @@ -14,7 +33,7 @@ class SigningConvention : Plugin<Project> { extensions.configure<ApplicationExtension> { signingConfigs { - SigningData.of(rootProject.properties("signing.properties"))?.let { + SigningData.of(rootProject.properties("signing.properties").orNull)?.let { create("default") { storeFile = file(it.storeFile) storePassword = it.storePassword diff --git a/gradle/convention/src/main/kotlin/util/BaseExtensionExtensions.kt b/gradle/convention/src/main/kotlin/util/BaseExtensionExtensions.kt deleted file mode 100644 index 667f8dac0c5f3e58641f887081bd7af00ca9b388..0000000000000000000000000000000000000000 --- a/gradle/convention/src/main/kotlin/util/BaseExtensionExtensions.kt +++ /dev/null @@ -1,8 +0,0 @@ -package util - -import com.android.build.gradle.BaseExtension -import org.gradle.api.plugins.ExtensionAware -import org.jetbrains.kotlin.gradle.dsl.KotlinJvmOptions - -fun BaseExtension.kotlinOptions(configure: KotlinJvmOptions.() -> Unit): Unit = - (this as ExtensionAware).extensions.configure("kotlinOptions", configure) diff --git a/gradle/convention/src/main/kotlin/util/ProjectExtensions.kt b/gradle/convention/src/main/kotlin/util/ProjectExtensions.kt index 6352bbfe7ea48e5ef2943c7df2757735dba8e088..6110edeac6de29cd59f7d32320a311cf86ab5861 100644 --- a/gradle/convention/src/main/kotlin/util/ProjectExtensions.kt +++ b/gradle/convention/src/main/kotlin/util/ProjectExtensions.kt @@ -1,26 +1,36 @@ +/* + * Quasseldroid - Quassel client for Android + * + * Copyright (c) 2024 Janne Mareike Koschinski + * Copyright (c) 2024 The Quassel Project + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3 as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see <http://www.gnu.org/licenses/>. + */ + package util import org.gradle.api.Project -import java.io.ByteArrayOutputStream -import java.util.Properties +import org.gradle.api.provider.Provider +import java.util.* + -fun Project.git(vararg command: String) = try { - val stdOut = ByteArrayOutputStream() - exec { - commandLine("git", *command) - standardOutput = stdOut - } - stdOut.toString(Charsets.UTF_8.name()).trim() -} catch (e: Throwable) { - e.printStackTrace() - null -} +fun Project.git(vararg command: String): Provider<String> = + providers.exec { commandLine("git", *command) } + .standardOutput + .asText + .map { it.trim() } -fun Project.properties(fileName: String): Properties? { - val file = file(fileName) - if (!file.exists()) - return null - val props = Properties() - props.load(file.inputStream()) - return props -} +fun Project.properties(fileName: String): Provider<Properties> = + providers.fileContents(rootProject.layout.projectDirectory.file(fileName)) + .asBytes + .map { Properties().apply { load(it.inputStream()) } }