Skip to content
Snippets Groups Projects
Unverified Commit c4d8ef42 authored by Janne Mareike Koschinski's avatar Janne Mareike Koschinski
Browse files

chore: update gradle conventions

parent 254a55dc
No related branches found
No related tags found
No related merge requests found
/*
* 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")
......
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")
......
/*
* 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"
)
}
......
/*
* 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"
)
}
......
/*
* 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
......
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)
/*
* 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()) } }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment