Skip to content
This repository was archived by the owner on Oct 18, 2024. It is now read-only.

Commit 7c7691b

Browse files
committed
fix: maven version name is configured from gradle.properties
1 parent 3ad42f9 commit 7c7691b

File tree

6 files changed

+46
-26
lines changed

6 files changed

+46
-26
lines changed

app/build.gradle

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ android {
2424

2525
defaultConfig {
2626
applicationId "com.itsaky.androidide.androidtreesitter"
27-
minSdk 21
28-
targetSdk 33
29-
versionName project.findProperty("VERSION_NAME")
30-
versionCode Integer.valueOf(project.findProperty("VERSION_CODE"))
31-
3227
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
3328
}
3429

build.gradle.kts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
import com.android.build.gradle.BaseExtension
19+
import com.itsaky.androidide.treesitter.projectVersionCode
1920
import com.vanniktech.maven.publish.AndroidSingleVariantLibrary
2021
import com.vanniktech.maven.publish.MavenPublishBaseExtension
2122
import com.vanniktech.maven.publish.SonatypeHost
@@ -26,18 +27,6 @@ plugins {
2627
id("com.vanniktech.maven.publish.base") version "0.23.0" apply false
2728
}
2829

29-
val Project.projectVersionCode by lazy {
30-
val version = rootProject.version.toString()
31-
val regex = Regex("^v\\d+\\.?\\d+\\.?\\d+")
32-
33-
return@lazy regex.find(version)?.value?.substring(1)?.replace(".", "")?.toInt()?.also {
34-
logger.warn("Version code is '$it' (from version ${rootProject.version}).")
35-
}
36-
?: throw IllegalStateException(
37-
"Invalid version string '$version'. Version names must be SEMVER with 'v' prefix"
38-
)
39-
}
40-
4130
fun Project.configureBaseExtension() {
4231
extensions.findByType(BaseExtension::class)?.run {
4332
compileSdkVersion(33)
@@ -64,11 +53,11 @@ subprojects {
6453
configure<MavenPublishBaseExtension> {
6554
group = "io.github.itsaky"
6655
var versionName = rootProject.version.toString()
67-
if (!hasProperty("publishRelease")) {
56+
if (System.getenv("PublishToMaven").isNullOrBlank()) {
6857
versionName = "$versionName-SNAPSHOT"
6958
}
70-
version = versionName
7159
pomFromGradleProperties()
60+
coordinates("io.github.itsaky", "android-tree-sitter", versionName)
7261
publishToMavenCentral(SonatypeHost.S01)
7362
signAllPublications()
7463
configure(AndroidSingleVariantLibrary(publishJavadocJar = false))

buildSrc/src/main/java/com/itsaky/androidide/treesitter/common.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package com.itsaky.androidide.treesitter
1919

2020
import org.gradle.api.GradleException
2121
import org.gradle.api.Project
22+
import org.gradle.kotlin.dsl.provideDelegate
2223

2324
/**
2425
* @author Akash Yadav
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* This file is part of android-tree-sitter.
3+
*
4+
* android-tree-sitter library is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU Lesser General Public
6+
* License as published by the Free Software Foundation; either
7+
* version 2.1 of the License, or (at your option) any later version.
8+
*
9+
* android-tree-sitter library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with android-tree-sitter. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.itsaky.androidide.treesitter
19+
20+
import org.gradle.api.Project
21+
import org.gradle.kotlin.dsl.provideDelegate
22+
23+
/**
24+
* @author Akash Yadav
25+
*/
26+
27+
private var _versionCode: Int? = null
28+
29+
val Project.projectVersionCode : Int
30+
get() = _versionCode ?: findVersionCode().also { _versionCode = it }
31+
32+
private fun Project.findVersionCode() : Int {
33+
val version = rootProject.version.toString()
34+
val regex = Regex("^v\\d+\\.?\\d+\\.?\\d+")
35+
36+
return regex.find(version)?.value?.substring(1)?.replace(".", "")?.toInt()?.also {
37+
logger.warn("Version code is '$it' (from version ${rootProject.version}).")
38+
}
39+
?: throw IllegalStateException(
40+
"Invalid version string '$version'. Version names must be SEMVER with 'v' prefix"
41+
)
42+
}

gradle.properties

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
55
SONATYPE_HOST=S01
66
RELEASE_SIGNING_ENABLED=true
77

8-
GROUP=io.github.itsaky
9-
POM_ARTIFACT_ID=android-tree-sitter
10-
VERSION_CODE=109
11-
VERSION_NAME=1.0.10
12-
138
POM_NAME=Android Tree Sitter
149
POM_DESCRIPTION=Android Java bindings for tree-sitter.
1510
POM_INCEPTION_YEAR=2022

settings.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/\>.
1616
*/
1717

18-
import com.mooltiverse.oss.nyx.gradle.NyxExtension
19-
2018
pluginManagement {
2119
repositories {
2220
gradlePluginPortal()

0 commit comments

Comments
 (0)