This commit is contained in:
InsanusMokrassar 2022-11-10 23:48:59 +06:00
parent 26a5d20e26
commit 283bc5acb4
12 changed files with 71 additions and 98 deletions

View File

@ -7,10 +7,9 @@ buildscript {
} }
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:7.0.4' classpath 'com.android.tools.build:gradle:7.2.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version" classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version"
classpath "com.getkeepsafe.dexcount:dexcount-gradle-plugin:$dexcount_version"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version" classpath "org.jetbrains.dokka:dokka-gradle-plugin:$dokka_version"
} }
} }

View File

@ -1,7 +1,6 @@
plugins { plugins {
id "org.jetbrains.kotlin.multiplatform" id "org.jetbrains.kotlin.multiplatform"
id "org.jetbrains.kotlin.plugin.serialization" id "org.jetbrains.kotlin.plugin.serialization"
id "com.android.library"
} }
apply from: "$mppProjectWithSerializationPresetPath" apply from: "$mppProjectWithSerializationPresetPath"

View File

@ -4,6 +4,7 @@ import dev.inmo.kmppscriptbuilder.core.utils.serialFormat
import io.ktor.client.HttpClient import io.ktor.client.HttpClient
import io.ktor.client.request.get import io.ktor.client.request.get
import io.ktor.client.request.url import io.ktor.client.request.url
import io.ktor.client.statement.bodyAsText
import kotlinx.serialization.Serializable import kotlinx.serialization.Serializable
import kotlinx.serialization.builtins.MapSerializer import kotlinx.serialization.builtins.MapSerializer
import kotlinx.serialization.builtins.serializer import kotlinx.serialization.builtins.serializer
@ -20,9 +21,9 @@ private val commonLicensesListDeserializer = MapSerializer(String.serializer(),
private var licenses: Map<String, License>? = null private var licenses: Map<String, License>? = null
suspend fun HttpClient.getLicenses(): Map<String, License> { suspend fun HttpClient.getLicenses(): Map<String, License> {
val answer = get<String> { val answer = get {
url("https://licenses.opendefinition.org/licenses/groups/all.json") url("https://licenses.opendefinition.org/licenses/groups/all.json")
} }.bodyAsText()
return serialFormat.decodeFromString(commonLicensesListDeserializer, answer).also { gotLicenses -> return serialFormat.decodeFromString(commonLicensesListDeserializer, answer).also { gotLicenses ->
licenses = gotLicenses licenses = gotLicenses
} }

View File

@ -31,23 +31,67 @@ data class MavenConfig(
@Serializable @Serializable
data class MavenPublishingRepository( data class MavenPublishingRepository(
val name: String, val name: String,
val url: String val url: String,
val credsType: CredentialsType = CredentialsType.UsernameAndPassword(
"${name.uppercase()}_USER",
"${name.uppercase()}_PASSWORD"
)
) { ) {
private val nameCapitalized by lazy { val defaultUsernameProperty = "${name.uppercase()}_USER"
name.toUpperCase() val defaultPasswordProperty = "${name.uppercase()}_PASSWORD"
} val defaultHeaderValueProperty = "${name.uppercase()}_TOKEN"
fun build(indent: String): String { @Serializable
val usernameProperty = "${nameCapitalized}_USER" sealed interface CredentialsType {
val passwordProperty = "${nameCapitalized}_PASSWORD" @Serializable
return """if ((project.hasProperty('${usernameProperty}') || System.getenv('${usernameProperty}') != null) && (project.hasProperty('${passwordProperty}') || System.getenv('${passwordProperty}') != null)) { object Nothing: CredentialsType {
maven { override fun buildCheckPart(): String = "true"
name = "$name" override fun buildCredsPart(): String = ""
url = uri("$url") }
@Serializable
data class UsernameAndPassword(
val usernameProperty: String,
val passwordProperty: String
): CredentialsType {
override fun buildCheckPart(): String = "(project.hasProperty('${usernameProperty}') || System.getenv('${usernameProperty}') != null) && (project.hasProperty('${passwordProperty}') || System.getenv('${passwordProperty}') != null)"
override fun buildCredsPart(): String {
return """
credentials { credentials {
username = project.hasProperty('${usernameProperty}') ? project.property('${usernameProperty}') : System.getenv('${usernameProperty}') username = project.hasProperty('${usernameProperty}') ? project.property('${usernameProperty}') : System.getenv('${usernameProperty}')
password = project.hasProperty('${passwordProperty}') ? project.property('${passwordProperty}') : System.getenv('${passwordProperty}') password = project.hasProperty('${passwordProperty}') ? project.property('${passwordProperty}') : System.getenv('${passwordProperty}')
} }
"""
}
}
@Serializable
data class HttpHeaderCredentials(
val headerName: String,
val headerValueProperty: String
): CredentialsType {
override fun buildCheckPart(): String = "project.hasProperty('${headerValueProperty}') || System.getenv('${headerValueProperty}') != null"
override fun buildCredsPart(): String {
return """
credentials(HttpHeaderCredentials) {
name = "$headerName"
value = project.hasProperty('${headerValueProperty}') ? project.property('${headerValueProperty}') : System.getenv('${headerValueProperty}')
}
"""
}
}
fun buildCheckPart(): String
fun buildCredsPart(): String
}
private val nameCapitalized by lazy {
name.uppercase()
}
fun build(indent: String): String {
return """if (${credsType.buildCheckPart()}) {
maven {
name = "$name"
url = uri("$url")
${credsType.buildCredsPart()}
} }
}""".replace("\n", "\n$indent") }""".replace("\n", "\n$indent")
} }

View File

@ -1 +0,0 @@
<manifest package="dev.inmo.KotlinPublicationScriptsBuilder.core"/>

View File

@ -1,40 +0,0 @@
apply plugin: 'com.getkeepsafe.dexcount'
android {
compileSdkVersion "$android_compileSdkVersion".toInteger()
buildToolsVersion "$android_buildToolsVersion"
defaultConfig {
minSdkVersion "$android_minSdkVersion".toInteger()
targetSdkVersion "$android_compileSdkVersion".toInteger()
versionCode "${android_code_version}".toInteger()
versionName "$version"
}
buildTypes {
release {
minifyEnabled false
}
debug {
debuggable true
}
}
packagingOptions {
exclude 'META-INF/kotlinx-serialization-runtime.kotlin_module'
exclude 'META-INF/kotlinx-serialization-cbor.kotlin_module'
exclude 'META-INF/kotlinx-serialization-properties.kotlin_module'
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}

View File

@ -16,7 +16,6 @@ allprojects {
mppProjectWithSerializationPresetPath = "${rootProject.projectDir.absolutePath}/mppProjectWithSerialization.gradle" mppProjectWithSerializationPresetPath = "${rootProject.projectDir.absolutePath}/mppProjectWithSerialization.gradle"
mppJavaProjectPresetPath = "${rootProject.projectDir.absolutePath}/mppJavaProject.gradle" mppJavaProjectPresetPath = "${rootProject.projectDir.absolutePath}/mppJavaProject.gradle"
mppJsProjectPresetPath = "${rootProject.projectDir.absolutePath}/mppJsProject.gradle" mppJsProjectPresetPath = "${rootProject.projectDir.absolutePath}/mppJsProject.gradle"
mppAndroidProjectPresetPath = "${rootProject.projectDir.absolutePath}/mppAndroidProject.gradle"
defaultAndroidSettingsPresetPath = "${rootProject.projectDir.absolutePath}/defaultAndroidSettings.gradle" defaultAndroidSettingsPresetPath = "${rootProject.projectDir.absolutePath}/defaultAndroidSettings.gradle"

View File

@ -6,27 +6,17 @@ kotlin.incremental.js=true
android.useAndroidX=true android.useAndroidX=true
android.enableJetifier=true android.enableJetifier=true
kotlin_version=1.6.10 kotlin_version=1.7.20
kotlin_coroutines_version=1.6.0 kotlin_coroutines_version=1.6.4
kotlin_serialisation_core_version=1.3.2 kotlin_serialisation_core_version=1.4.1
ktor_version=1.6.7 ktor_version=2.1.3
micro_utils_version=0.9.0 micro_utils_version=0.14.1
compose_version=1.0.1 compose_version=1.2.1
# ANDROID
android_minSdkVersion=21
android_compileSdkVersion=32
android_buildToolsVersion=32.0.0
dexcount_version=3.0.1
junit_version=4.12
test_ext_junit_version=1.1.2
espresso_core=3.3.0
# Dokka # Dokka
dokka_version=1.6.0 dokka_version=1.7.20
# Project data # Project data

View File

@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip

View File

@ -4,9 +4,7 @@ project.group = "$group"
// apply from: "$publishGradlePath" // apply from: "$publishGradlePath"
kotlin { kotlin {
jvm { jvm()
compilations.main.kotlinOptions.useIR = true
}
sourceSets { sourceSets {
commonMain { commonMain {

View File

@ -5,11 +5,9 @@ project.group = "$group"
kotlin { kotlin {
js (IR) { js (IR) {
browser { browser()
binaries.executable() binaries.executable()
} }
nodejs()
}
sourceSets { sourceSets {
commonMain { commonMain {

View File

@ -4,16 +4,11 @@ project.group = "$group"
// apply from: "$publishGradlePath" // apply from: "$publishGradlePath"
kotlin { kotlin {
jvm { jvm()
compilations.main.kotlinOptions.useIR = true
}
js (IR) { js (IR) {
browser() browser()
nodejs() nodejs()
} }
android {
publishAllLibraryVariants()
}
sourceSets { sourceSets {
commonMain { commonMain {
@ -39,14 +34,5 @@ kotlin {
implementation kotlin('test-junit') implementation kotlin('test-junit')
} }
} }
androidTest {
dependencies {
implementation kotlin('test-junit')
implementation "androidx.test.ext:junit:$test_ext_junit_version"
implementation "androidx.test.espresso:espresso-core:$espresso_core"
}
}
} }
} }
apply from: "$defaultAndroidSettingsPresetPath"