Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor project layout and build script patterns #28

Merged
merged 3 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
221 changes: 152 additions & 69 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
@file:Suppress("SuspiciousCollectionReassignment")

import io.kotest.framework.multiplatform.gradle.KotestMultiplatformCompilerGradlePlugin
import org.jetbrains.dokka.gradle.DokkaPlugin
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.dsl.*
import org.jetbrains.kotlin.gradle.dsl.ExplicitApiMode.Warning
import org.jetbrains.kotlin.gradle.plugin.KotlinMultiplatformPluginWrapper
import org.jetbrains.kotlin.gradle.plugin.KotlinPluginWrapper


@Suppress("DSL_SCOPE_VIOLATION")
plugins {
with(libs.plugins) {
alias(kotlin.multiplatform) apply false
alias(kotest.multiplatform) apply false
alias(kover)
alias(dokka)
}
}
Expand All @@ -23,98 +25,179 @@ allprojects {
// maven("https://oss.sonatype.org/content/repositories/snapshots")
}

if (name.startsWith("kone-", ignoreCase = true) || name in listOf("mapUtil")) {
apply<DokkaPlugin>()
dependencies {
dokkaPlugin(rootProject.libs.dokka.mathjax)
}

afterEvaluate {
tasks.withType<DokkaTask> {
// TODO
}
task<Jar>("dokkaJar") {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = "Assembles Kotlin docs with Dokka"
archiveClassifier.set("javadoc")
val dokkaHtml by tasks.getting
dependsOn(dokkaHtml)
from(dokkaHtml)
}
}
}

group = "com.lounres.kone"
version = "0.0.0-dev-1"
}

subprojects {
if (name.startsWith("kone-", ignoreCase = true) || name in listOf("testUtil")) {
apply(plugin = rootProject.libs.plugins.kotlin.multiplatform.get().pluginId)
apply(plugin = rootProject.libs.plugins.kotest.multiplatform.get().pluginId)
configure<KotlinMultiplatformExtension> {
explicitApi = Warning
val jvmTargetApi = properties["jvmTarget"] as String

fun PluginManager.withPlugin(pluginDep: PluginDependency, block: AppliedPlugin.() -> Unit) = withPlugin(pluginDep.pluginId, block)
fun PluginManager.withPlugin(pluginDepProvider: Provider<PluginDependency>, block: AppliedPlugin.() -> Unit) = withPlugin(pluginDepProvider.get().pluginId, block)

jvm {
compilations.all {
featuresManagement {
features {
on("kotlin jvm") {
apply<KotlinPluginWrapper>()
configure<KotlinJvmProjectExtension> {
target.compilations.all {
kotlinOptions {
jvmTarget = properties["jvmTarget"] as String
jvmTarget = jvmTargetApi
}
compileKotlinTask.apply {
kotlinOptions {
jvmTarget = jvmTargetApi
}
}
}
testRuns.all {
executionTask {
useJUnitPlatform()

@Suppress("UNUSED_VARIABLE")
sourceSets {
val test by getting {
dependencies {
implementation(kotlin("test"))
}
}
}
}
}
on("kotlin multiplatform") {
apply<KotlinMultiplatformPluginWrapper>()
configure<KotlinMultiplatformExtension> {
// explicitApi = Warning

js(IR) {
browser()
nodejs()
}
jvm {
compilations.all {
kotlinOptions {
jvmTarget = jvmTargetApi
}
compileKotlinTask.apply {
kotlinOptions {
jvmTarget = jvmTargetApi
}
}
}
testRuns.all {
executionTask {
useJUnitPlatform()
}
}
}

linuxX64()
mingwX64()
macosX64()
js(IR) {
browser()
nodejs()
}

@Suppress("UNUSED_VARIABLE")
sourceSets {
all {
languageSettings {
progressiveMode = true
optIn("kotlin.contracts.ExperimentalContracts")
}
if (name.endsWith("test", ignoreCase = true)) {
linuxX64()
mingwX64()
macosX64()

@Suppress("UNUSED_VARIABLE")
sourceSets {
val commonTest by getting {
dependencies {
with(rootProject.libs.kotest) {
implementation(framework.engine)
implementation(framework.datatest)
implementation(assertions.core)
implementation(property)
}
implementation(kotlin("test"))
}
}
}
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
on("kotlin common settings") {
configure<KotlinProjectExtension> {
explicitApi = Warning

sourceSets {
all {
languageSettings {
progressiveMode = true
optIn("kotlin.contracts.ExperimentalContracts")
}
}
}
val jvmTest by getting {
dependencies {
implementation(rootProject.libs.kotest.runner.junit5)
}
pluginManager.withPlugin("org.gradle.java") {
configure<JavaPluginExtension> {
targetCompatibility = JavaVersion.toVersion(jvmTargetApi)
}
tasks.withType<Test> {
useJUnitPlatform()
}
}
}
on("kotest") {
pluginManager.withPlugin(rootProject.libs.plugins.kotlin.jvm) {
configure<KotlinJvmProjectExtension> {
@Suppress("UNUSED_VARIABLE")
sourceSets {
val test by getting {
dependencies {
with(rootProject.libs.kotest) {
implementation(framework.engine)
implementation(framework.datatest)
implementation(assertions.core)
implementation(property)
implementation(runner.junit5)
}
}
}
}
}
}
pluginManager.withPlugin(rootProject.libs.plugins.kotlin.multiplatform) {
apply<KotestMultiplatformCompilerGradlePlugin>()
configure<KotlinMultiplatformExtension> {
@Suppress("UNUSED_VARIABLE")
sourceSets {
all {
if (name.endsWith("test", ignoreCase = true)) {
dependencies {
with(rootProject.libs.kotest) {
implementation(framework.engine)
implementation(framework.datatest)
implementation(assertions.core)
implementation(property)
}
}
}
}
val jvmTest by getting {
dependencies {
implementation(rootProject.libs.kotest.runner.junit5)
}
}
}
}
}
}
}
if (name.startsWith("kone-", ignoreCase = true) || name in listOf("mapUtil")) {
apply<MavenPublishPlugin>()
on("dokka") {
apply<DokkaPlugin>()
dependencies {
dokkaPlugin(rootProject.libs.dokka.mathjax)
}

afterEvaluate {
configure<PublishingExtension> {
publications.withType<MavenPublication> {
artifact(tasks.named<Jar>("dokkaJar"))
task<Jar>("dokkaJar") {
group = JavaBasePlugin.DOCUMENTATION_GROUP
description = "Assembles Kotlin docs with Dokka"
archiveClassifier.set("javadoc")
afterEvaluate {
val dokkaHtml by tasks.getting
dependsOn(dokkaHtml)
from(dokkaHtml)
}
}

afterEvaluate {
tasks.withType<DokkaTask> {
// TODO
}
}
}
on("publishing") {
apply<MavenPublishPlugin>()
afterEvaluate {
configure<PublishingExtension> {
publications.withType<MavenPublication> {
artifact(tasks.named<Jar>("dokkaJar"))
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ jvmTarget=11

#org.gradle.configureondemand=true
org.gradle.parallel=true
org.gradle.jvmargs=-XX:MaxMetaspaceSize=1G
org.gradle.jvmargs=-XX:MaxMetaspaceSize=2G
16 changes: 0 additions & 16 deletions kone-numberTheory/build.gradle.kts

This file was deleted.

20 changes: 0 additions & 20 deletions kone-planimetricsCalculation/build.gradle.kts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation(projects.koneCore)
implementation(projects.kone.core)
}
}
val commonTest by getting {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ kotlin {
sourceSets {
val commonMain by getting {
dependencies {

implementation(projects.kone.core)
api(projects.kone.algebraic)
}
}
val commonTest by getting {
dependencies {

implementation(projects.utils.kotest)
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions kone/misc/planimetricsCalculation/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
kotlin {
@Suppress("UNUSED_VARIABLE")
sourceSets {
val commonMain by getting {
dependencies {
implementation(projects.kone.core)
api(projects.kone.algebraic)
api(projects.kone.numberTheory)
api(projects.kone.polynomial)
api(projects.kone.linearAlgebra)
implementation(projects.utils.mapOperations)
}
}
val commonTest by getting {
dependencies {
implementation(projects.utils.kotest)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation(projects.koneCore)
api(projects.koneAlgebraic)
implementation(projects.kone.core)
api(projects.kone.algebraic)
}
}
val commonTest by getting {
dependencies {
implementation(projects.testUtil)
implementation(projects.utils.kotest)
}
}
}
Expand Down
Loading