Go to file
2024-11-12 03:05:18 +03:00
embed Fix of plugin dependencies 2024-11-09 16:58:37 +03:00
impl Function to fix miscellaneous shit in kotlin compiler 2024-11-12 03:05:18 +03:00
test Small fixes and v0.2 2024-11-09 16:33:43 +03:00
.gitignore Removing 'embed' version, united versions file 2024-11-05 14:08:07 +03:00
README.md Fix of plugin dependencies 2024-11-09 16:58:37 +03:00
settings.gradle.kts Gradle plugin with 1-line initialization of all buildscript dependencies and plugins 2024-11-09 00:42:17 +03:00
versions.properties Small fixes and v0.2 2024-11-09 16:33:43 +03:00

Gradle buildscript utilities for Kotlin/Multiplatform

Getting

As library

import ru.landgrafhomyak.kotlin.kmp_gradle_build_helper.*

buildscript {
	repositories {
		mavenCentral()
		maven("https://maven.landgrafhomyak.ru/")
	}

	dependencies {
		classpath("ru.landgrafhomyak.kotlin:kotlin-mpp-gradle-build-helper:v0.2k2.0.20")
	}
}

plugins {
	kotlin("multiplatform") version "2.0.20" // version of kotlin must be the same as in this library
}

repositories {
	mavenCentral()
}

kotlin {
	optInContracts()

	// ...

	defineAllMultiplatformTargets()

	sourceSets {
		// ...
	}
}

As plugin (custom repository)

import ru.landgrafhomyak.kotlin.kmp_gradle_build_helper.*
import ru.landgrafhomyak.kotlin.kmp_gradle_build_helper.plugin.xomrk

buildscript {
	repositories {
		mavenCentral()
		maven("https://maven.landgrafhomyak.ru/")
	}

	dependencies {
		classpath("ru.landgrafhomyak.kotlin:kotlin-mpp-gradle-build:v0.2k2.0.20")
	}
}

plugins {
	// kotlin/multiplatorm and other plugins will be lazily enabled by dsl
}

repositories {
	mavenCentral()
}

xomrk {
	// lazily enables kotlin if not yet
	kotlin {
		// same as with original kotlin plugin
	}
	
	// lazily enables `maven-publish` if not yet
	publishing {
		// same as with original kotlin plugin
	}
}

As plugin (gradle portal)

This library officially isn't published, so this way wouldn't work

import ru.landgrafhomyak.kotlin.kmp_gradle_build_helper.*

plugins {
	id("ru.landgrafhomyak.kotlin.original-multiplatform-ext") version "v0.2k2.0.20"
}

repositories {
	mavenCentral()
}

xomrk {
	// lazily enables kotlin if not yet
	kotlin {
		// same as with original kotlin plugin
	}

	// lazily enables `maven-publish` if not yet
	publishing {
		// same as with original kotlin plugin
	}
}

Functionality

import ru.landgrafhomyak.kotlin.kmp_gradle_build_helper.*

// ...

kotlin {
	// Configures compilations of all targets
	configureAllCompilations { }

	// Configures compiler for all targets
	configureAllCompilersOptions { }

	// Removes warning "expect/actual mechanism is experimental"
	noWarnExpectActual()

	warningsAsErrors()

	// Opt-ins specified annotation to all targets
	optIn("org.example.OptIn")

	// optIn("kotlin.contracts.ExperimentalContracts")
	optInContracts()

	// sets kotlin compatibility (both api and language) for all targets
	setCompatibilityWithKotlin(org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_0)

	// defines all possible targets, useful for 'algorithm' libraries that are not depends on platform
	defineAllMultiplatformTargets()
}

publishing {
	// useful for single-platform (e.g. JVM-only) libraries 
	forceSetAllMavenArtifactsId(project.name)

	// safe replacing for libraries with many targets
	replaceAllMavenArtifactsIdPrefixes(project.name, "custom-name")

	// replacing of platform id (but better to do it in kotlin {...} block)
	replaceAllMavenArtifactsIdSuffixes("js", "frontend")
}