Skip to content

Commit 18774c4

Browse files
authored
Merge pull request #428 from AppDevNext/KtsBuild
Build with kts
2 parents e3c56f8 + 0a5cebe commit 18774c4

File tree

8 files changed

+148
-108
lines changed

8 files changed

+148
-108
lines changed
Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,63 @@
1+
import info.git.versionHelper.getVersionText
2+
import java.net.URI
3+
14
plugins {
2-
id "com.android.library"
3-
id "maven-publish"
4-
id "kotlin-android"
5-
id "com.vanniktech.maven.publish" version "0.34.0"
5+
id("com.android.library")
6+
id("maven-publish")
7+
id("kotlin-android")
8+
id("com.vanniktech.maven.publish") version "0.34.0"
69
}
710

811
android {
9-
namespace "com.github.mikephil.charting"
12+
namespace = "com.github.mikephil.charting"
1013
defaultConfig {
11-
minSdkVersion 21
12-
compileSdk 35
13-
targetSdkVersion 35
14+
minSdk = 21
15+
compileSdk = 35
1416

1517
// VERSION_NAME no longer available as of 4.1
1618
// https://issuetracker.google.com/issues/158695880
17-
buildConfigField "String", "VERSION_NAME", "\"${getTag()}\""
19+
buildConfigField("String", "VERSION_NAME", "\"${getVersionText()}\"")
1820

19-
consumerProguardFiles "proguard-lib.pro"
21+
consumerProguardFiles.add(File("proguard-lib.pro"))
2022
}
2123
compileOptions {
22-
sourceCompatibility JavaVersion.VERSION_17
23-
targetCompatibility JavaVersion.VERSION_17
24+
sourceCompatibility = JavaVersion.VERSION_17
25+
targetCompatibility = JavaVersion.VERSION_17
2426
}
2527
buildTypes {
2628
release {
27-
minifyEnabled false
29+
isMinifyEnabled = false
2830
}
2931
}
3032
buildFeatures {
3133
buildConfig = true
3234
}
3335
testOptions {
34-
unitTests.returnDefaultValues = true // this prevents "not mocked" error
36+
unitTests.isReturnDefaultValues = true // this prevents "not mocked" error
3537
}
3638
}
3739

3840
dependencies {
39-
implementation "androidx.annotation:annotation:1.9.1"
40-
implementation "androidx.core:core:1.16.0"
41-
implementation "androidx.activity:activity-ktx:1.10.1"
42-
testImplementation "junit:junit:4.13.2"
41+
implementation("androidx.annotation:annotation:1.9.1")
42+
implementation("androidx.core:core:1.16.0")
43+
implementation("androidx.activity:activity-ktx:1.10.1")
44+
testImplementation("junit:junit:4.13.2")
4345
}
4446

45-
tasks.register("androidSourcesJar", Jar) {
47+
tasks.register<Jar>("androidSourcesJar") {
4648
archiveClassifier.set("sources")
47-
from android.sourceSets.main.java.srcDirs
49+
from(android.sourceSets["main"].java.srcDirs)
4850
}
4951

5052
group = "info.mxtracks"
51-
version = "${getTag()}"
52-
println "Build version $version"
53+
var versionVersion = getVersionText()
54+
println("Build version $versionVersion")
5355

5456
mavenPublishing {
5557
pom {
5658
name = "Android Chart"
57-
description = "A powerful Android chart view / graph view library, supporting line- bar- pie- radar- bubble- and candlestick charts as well as scaling, dragging and animations"
59+
description =
60+
"A powerful Android chart view/graph view library, supporting line- bar- pie- radar- bubble- and candlestick charts as well as scaling, dragging and animations"
5861
inceptionYear = "2022"
5962
url = "https://github.com/AppDevNext/AndroidChart/"
6063
licenses {
@@ -81,9 +84,9 @@ mavenPublishing {
8184
// Github packages
8285
repositories {
8386
maven {
84-
version = version + "-SNAPSHOT"
87+
version = "$versionVersion-SNAPSHOT"
8588
name = "GitHubPackages"
86-
url = "https://maven.pkg.github.com/AppDevNext/AndroidChart"
89+
url = URI("https://maven.pkg.github.com/AppDevNext/AndroidChart")
8790
credentials {
8891
username = System.getenv("GITHUBACTOR")
8992
password = System.getenv("GITHUBTOKEN")

app/build.gradle

Lines changed: 0 additions & 50 deletions
This file was deleted.

app/build.gradle.kts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import info.git.versionHelper.getGitCommitCount
2+
import info.git.versionHelper.getVersionText
3+
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
4+
5+
plugins {
6+
id("com.android.application")
7+
id("kotlin-android")
8+
}
9+
10+
android {
11+
namespace = "info.appdev.chartexample"
12+
defaultConfig {
13+
applicationId = "info.appdev.chartexample"
14+
minSdk = 21
15+
compileSdk = 35
16+
targetSdk = 35
17+
versionCode = getGitCommitCount()
18+
versionName = getVersionText()
19+
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
20+
testInstrumentationRunnerArguments.putAll(
21+
mapOf(
22+
"useTestStorageService" to "true",
23+
),
24+
)
25+
}
26+
compileOptions {
27+
sourceCompatibility = JavaVersion.VERSION_17
28+
targetCompatibility = JavaVersion.VERSION_17
29+
}
30+
kotlin {
31+
compilerOptions {
32+
jvmTarget = JvmTarget.JVM_17
33+
}
34+
}
35+
buildFeatures {
36+
viewBinding = true
37+
}
38+
buildTypes {
39+
release {
40+
isMinifyEnabled = false
41+
proguardFiles.addAll(listOf(getDefaultProguardFile("proguard-android.txt"), File("proguard-rules.pro")))
42+
}
43+
}
44+
// https://stackoverflow.com/a/67635863/1079990
45+
testOptions {
46+
animationsDisabled = true
47+
}
48+
}
49+
50+
dependencies {
51+
implementation("androidx.appcompat:appcompat:1.7.1")
52+
implementation("com.google.android.material:material:1.13.0")
53+
implementation(project(":MPChartLib"))
54+
55+
androidTestImplementation("androidx.test.ext:junit-ktx:1.3.0")
56+
androidTestImplementation("com.github.AppDevNext.Logcat:LogcatCoreLib:3.4")
57+
androidTestUtil("androidx.test.services:test-services:1.6.0")
58+
androidTestImplementation("androidx.test.espresso:espresso-core:3.7.0")
59+
androidTestImplementation("androidx.test.espresso:espresso-intents:3.7.0")
60+
}

build.gradle

Lines changed: 0 additions & 33 deletions
This file was deleted.

build.gradle.kts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
buildscript {
2+
repositories {
3+
google()
4+
mavenCentral()
5+
}
6+
dependencies {
7+
classpath("com.android.tools.build:gradle:8.13.0")
8+
classpath("com.github.dcendents:android-maven-gradle-plugin:2.1")
9+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:2.2.20")
10+
}
11+
}
12+
13+
allprojects {
14+
repositories {
15+
google()
16+
mavenCentral()
17+
maven { url = uri("https://jitpack.io") }
18+
}
19+
}

buildSrc/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.gradle
2+
build

buildSrc/build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
plugins {
2+
`kotlin-dsl`
3+
}
4+
5+
repositories {
6+
mavenCentral()
7+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package info.git.versionHelper
2+
3+
import java.io.File
4+
import java.util.concurrent.TimeUnit
5+
6+
@JvmOverloads
7+
fun String.runCommand(workingDir: File = File("./")): String {
8+
val parts = this.split("\\s".toRegex())
9+
val proc = ProcessBuilder(*parts.toTypedArray())
10+
.directory(workingDir)
11+
.redirectOutput(ProcessBuilder.Redirect.PIPE)
12+
.redirectError(ProcessBuilder.Redirect.PIPE)
13+
.start()
14+
15+
proc.waitFor(1, TimeUnit.MINUTES)
16+
return proc.inputStream.bufferedReader().readText().trim()
17+
}
18+
19+
fun getGitCommitCount(): Int {
20+
val process = "git rev-list HEAD --count".runCommand()
21+
return process.toInt() + 580
22+
}
23+
24+
fun getVersionText(): String {
25+
val processChanges = "git diff-index --name-only HEAD --".runCommand()
26+
var dirty = ""
27+
if (processChanges.trim().isNotEmpty())
28+
dirty = "-DIRTY"
29+
30+
val processDescribe = "git describe".runCommand()
31+
return processDescribe.trim() + dirty
32+
}

0 commit comments

Comments
 (0)