Skip to content

Commit

Permalink
Merge branch 'main' into plugins-release
Browse files Browse the repository at this point in the history
plugins v0.6.0 release
  • Loading branch information
ShreckYe committed Oct 18, 2024
2 parents dab89f0 + 8905e7f commit 93ccc18
Show file tree
Hide file tree
Showing 30 changed files with 288 additions and 120 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Ignore Gradle project-specific cache directory
.gradle

.kotlin

# Ignore Gradle build output directory
build

Expand Down
10 changes: 7 additions & 3 deletions architecture-common-gradle-plugins/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ repositories {

dependencies {
implementation(project(":kotlin-common-gradle-plugins"))
implementation("org.jetbrains.kotlin:compose-compiler-gradle-plugin:${DependencyVersions.kotlin}")
// use the version in `buildSrc` so there is no need to frequently update the dependent bootstrapping `common-gradle-dependencies` version in "buildSrc"
implementation("org.jetbrains.compose:compose-gradle-plugin:${DependencyVersions.composeMultiplatform}")

//api(project(":common-gradle-dependencies"))
//implementation(project(":common-gradle-dependencies"))
/* This project depends on a specific version of the Maven dependency of "common-gradle-dependencies"
since now they are developed together in the same branch `main`,
enabling it to always depend on a release version. */

implementation(commonGradleClasspathDependencies.composeMultiplatform.gradlePlugin.pluginProject())
// implementation(commonGradleClasspathDependencies.composeMultiplatform.gradlePlugin.pluginProject()) // bootstrapping
}

gradlePlugin {
Expand Down Expand Up @@ -46,8 +50,8 @@ gradlePlugin {
"Kotlin Multiplatform app conventions with the JS browser target"
)
scriptConventionsPlugin(
"kotlin-multiplatform-jvm-and-js-browser-app-conventions",
"Kotlin Multiplatform app conventions with the JVM target and the JS browser target"
"kotlin-multiplatform-app-conventions-with-conventional-targets",
"Kotlin Multiplatform app conventions with the conventional targets JVM, JS (browser), iOS (`iosX64`, `iosArm64`, and `iosSimulatorArm64`), and Wasm JS"
)

scriptConventionsPlugin(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,66 @@ package com.huanshankeji

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.provider.ListProperty
import org.gradle.api.provider.Property
import org.gradle.api.tasks.Copy
import org.gradle.api.tasks.util.PatternFilterable
import org.gradle.kotlin.dsl.create
import org.gradle.kotlin.dsl.named
import org.gradle.kotlin.dsl.register
import org.jetbrains.kotlin.gradle.targets.js.webpack.KotlinWebpack

class GenerateKotlinJsBrowserWebrootForVertxWebPlugin : Plugin<Project> {
override fun apply(project: Project): Unit = project.run {
val extension = extensions.create<Extension>("generateKotlinJsResources")

afterEvaluate {
val frontendProject = project(extension.webFrontendProjectPath.get())
val jsBrowserDistributionTask = frontendProject.tasks.named("jsBrowserDistribution")
/*val jsBrowserWebpack by lazy {
tasks.getByPath(
extension.webFrontendProjectPath.get() +
if (extension.production.get()) ":jsBrowserProductionWebpack" else ":jsBrowserDevelopmentWebpack"
) as KotlinWebpack
}*/
val copyJsBrowserDistributionToResourcesWebroot = "copyJsBrowserDistributionToResourcesWebroot"
val browserDistributionResourcesDirectory = layout.buildDirectory.get().dir("browserDistributionResources")

// see: https://play.kotlinlang.org/hands-on/Full%20Stack%20Web%20App%20with%20Kotlin%20Multiplatform/04_Frontend_Setup
tasks.register<Copy>(copyJsBrowserDistributionToResourcesWebroot) {
dependsOn(jsBrowserDistributionTask)
// TODO I didn't find a way to get this path using the DSL, so there may be a bug if this path is customized.
from(frontendProject.layout.buildDirectory.get().dir("dist/js/productionExecutable"))
//if (extension.production.get())
extension.includes.getOrNull()?.let { include(it) }
into(browserDistributionResourcesDirectory.dir(extension.webRoot.getOrElse("webroot")))
}

val jsBrowserDistributionTask by lazy {
tasks.getByPath(extension.webFrontendProjectPath.get() + ":jsBrowserDistribution")
}
val jsBrowserWebpack by lazy {
tasks.getByPath(
extension.webFrontendProjectPath.get() +
if (extension.production.get()) ":jsBrowserProductionWebpack" else ":jsBrowserDevelopmentWebpack"
) as KotlinWebpack
}
val copyJsBrowserDistributionToResourcesWebroot = "copyJsBrowserDistributionToResourcesWebroot"
val browserDistributionResourcesDirectory = buildDir.resolve("browserDistributionResources")

tasks.register<Copy>(copyJsBrowserDistributionToResourcesWebroot) {
dependsOn(jsBrowserWebpack)
dependsOn(jsBrowserDistributionTask) // needed for Gradle 8.0.1 whenever `production` is `true` or `false` // TODO: this may be a bug.
from(jsBrowserWebpack.destinationDirectory)
if (extension.production.get())
include("*.html", "*.css", "*.js")
into(browserDistributionResourcesDirectory.resolve("webroot"))
}
tasks.named<Copy>("processResources") {
dependsOn(copyJsBrowserDistributionToResourcesWebroot)
}
/*
When running a Maven publish task, the error occurs if this line is not added:
> Task '...:sourcesJar' uses this output of task '...:copyJsBrowserDistributionToResourcesWebroot' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed.
tasks.named<Copy>("processResources") {
dependsOn(copyJsBrowserDistributionToResourcesWebroot)
}
TODO This is probably a bug. remove this line when it's fixed.
*/
tasks.named("sourcesJar") { dependsOn("copyJsBrowserDistributionToResourcesWebroot") }

sourceSets.main { resources.srcDir(browserDistributionResourcesDirectory) }
sourceSets.main { resources.srcDir(browserDistributionResourcesDirectory) }
}
}

interface Extension {
val webFrontendProjectPath: Property<String>
val production: Property<Boolean>

//val production: Property<Boolean>
/**
* Patterns of distribution files to include.
* Defaults to including all files.
*
* @see PatternFilterable.include
*/
val includes: ListProperty<String>

val webRoot: Property<String>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.huanshankeji

plugins {
id("com.huanshankeji.kotlin-multiplatform-js-browser-app-conventions")
kotlin("plugin.compose")
id("org.jetbrains.compose")
}

Expand All @@ -18,7 +19,7 @@ repositories {
}

kotlin {
js(IR) {
js {
browser {
commonWebpackConfig {
outputFileName = "app.js"
Expand All @@ -36,7 +37,7 @@ kotlin {
sourceSets {
jsMain {
dependencies {
implementation(compose.web.core)
implementation(compose.html.core)
implementation(compose.runtime)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.huanshankeji.jvm.native.osandarch


object DefaultSupported {
object ArchsByOs {
val linux = listOf(CpuArchitecture.X8664, CpuArchitecture.Aarch64)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.huanshankeji

plugins {
id("com.huanshankeji.kotlin-jvm-common-conventions")
kotlin("jvm")
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package com.huanshankeji

plugins {
id("com.huanshankeji.kotlin-multiplatform-app-conventions")
id("com.huanshankeji.kotlin-multiplatform-jvm-and-js-browser-conventions")
id("com.huanshankeji.kotlin-multiplatform-conventional-targets")
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.huanshankeji

plugins {
id("com.huanshankeji.kotlin-multiplatform-conventions")
kotlin("multiplatform")
}

kotlin {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.huanshankeji.spark

// copied and adapted from https://stackoverflow.com/a/76805763/5082913
val sparkJava17CompatibleJvmArgs = listOf(
"--add-opens=java.base/java.lang=ALL-UNNAMED",
"--add-opens=java.base/java.lang.invoke=ALL-UNNAMED",
"--add-opens=java.base/java.lang.reflect=ALL-UNNAMED",
"--add-opens=java.base/java.io=ALL-UNNAMED",
"--add-opens=java.base/java.net=ALL-UNNAMED",
"--add-opens=java.base/java.nio=ALL-UNNAMED",
"--add-opens=java.base/java.util=ALL-UNNAMED",
"--add-opens=java.base/java.util.concurrent=ALL-UNNAMED",
"--add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED",
"--add-opens=java.base/sun.nio.ch=ALL-UNNAMED",
"--add-opens=java.base/sun.nio.cs=ALL-UNNAMED",
"--add-opens=java.base/sun.security.action=ALL-UNNAMED",
"--add-opens=java.base/sun.util.calendar=ALL-UNNAMED",
"--add-opens=java.security.jgss/sun.security.krb5=ALL-UNNAMED",
)
14 changes: 9 additions & 5 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
`kotlin-dsl`
// Gradle 8.1.1's dependent Kotlin version is 1.8.10.
//kotlin("jvm") version "1.8.10"
// Gradle 8.10's embedded Kotlin version is 1.9.24.
//kotlin("jvm") version "2.0.10"
}

repositories {
Expand All @@ -24,14 +24,18 @@ dependencies {
implementation("org.jetbrains.kotlin:kotlin-sam-with-receiver:1.8.0")
}
*/
// for `KotlinCompilationTask` and the version is for Compose 1.6.1
implementation(kotlin("gradle-plugin", "1.9.23"))
implementation("org.gradle.kotlin:gradle-kotlin-dsl-plugins:4.2.1") // This version has to be used for Gradle 8.6.
// for `KotlinCompilationTask` and the version is compatible with Compose 1.6.11
// With Kotlin 2.0.20, a "Could not parse POM" build error occurs in the JVM projects of some dependent projects.
implementation(kotlin("gradle-plugin", "2.0.10"))
implementation("org.gradle.kotlin:gradle-kotlin-dsl-plugins:4.5.0") // This version has to be used for Gradle 8.10.

implementation("com.gradle.publish:plugin-publish-plugin:1.2.1")

// This is a bootstrapping dependency (cross-version self-dependency). Try not to update its version unless necessary.
implementation("com.huanshankeji.team:gradle-plugins:0.3.0") { exclude("org.jetbrains.kotlin") }
// This approach complicates the project is temporarily given up and commented out. Maybe readopt this when `common-gradle-dependencies` is moved to a separate project.
/*
// This is also a bootstrapping dependency.
implementation("com.huanshankeji:common-gradle-dependencies:0.7.1-20240314-boostrap") { exclude("org.jetbrains.kotlin") }
*/
}
19 changes: 12 additions & 7 deletions buildSrc/src/main/kotlin/VersionsAndDependencies.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
import com.huanshankeji.CommonGradleClasspathDependencies
import com.huanshankeji.CommonVersions

/*
// Bootstrapping from "common-gradle-dependencies"
val commonVersions = CommonVersions()
val commonGradleClasspathDependencies = CommonGradleClasspathDependencies(commonVersions)
*/


val kotlinVersion = "1.9.23" // for Compose 1.6.1
object DependencyVersions {
val kotlin = "2.0.10" // compatible with the compose version below
val composeMultiplatform = "1.7.0"
val kotlinxBenchmark = "0.4.11"
}

val alignedPluginVersion = "0.5.1"
val alignedPluginVersion = "0.6.0"

// "x.y.z" indicates the version of the way of organizing the code,
// and the date indicates the version when the dependency versions are updated.
val commonGradleDependenciesVersion = "0.7.1-20240314-boostrap-SNAPSHOT"
val commonGradleDependenciesVersion = "0.8.0-20241016-SNAPSHOT"

// This is the source dependency version. There is another build source dependency in "buildSrc/build.gradle.kts".
val pluginProjectSourceDependentStableCommonGradleDependenciesVersion = "0.7.1-20240314-boostrap".apply {
val pluginProjectSourceDependentStableCommonGradleDependenciesVersion = "0.8.0-20241016".apply {
require(!endsWith("SNAPSHOT"))
}
8 changes: 6 additions & 2 deletions buildSrc/src/main/kotlin/conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,16 @@ plugins {
}

repositories {
mavenLocal() // TODO comment out when not needed
gradlePluginPortal()
}

dependencies {
// Not specifying version can cause build issues when added to a project's buildscript dependencies.
implementation(kotlin("gradle-plugin", kotlinVersion))
// Not specifying version can cause build issues when added to a project's buildscript dependencies if the version in the "buildSrc" build script is different.
implementation(kotlin("gradle-plugin"))
// These 2 dependencies are implicitly added with the Gradle's embedded Kotlin version if not added explicitly.
implementation(kotlin("stdlib"))
implementation(kotlin("reflect"))
}

kotlin.jvmToolchain(8)
Expand Down
22 changes: 20 additions & 2 deletions common-gradle-dependencies/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
import com.huanshankeji.generateKotlinVersion
import com.huanshankeji.SourceFile
import com.huanshankeji.generateKotlinSources
import kotlin.reflect.full.memberProperties

plugins {
conventions
}

version = commonGradleDependenciesVersion

generateKotlinVersion(kotlinVersion)
generateKotlinSources(
sourceFiles = listOf(
SourceFile(
"GeneratedKotlinVersion.kt",
"""
internal object GeneratedVersions {
${
DependencyVersions::class.memberProperties.joinToString("\n") {
" internal const val ${it.name} = \"${it(DependencyVersions)}\""
}
}
}
""".drop(1)
)
)
)


gradlePlugin {
plugins {
Expand Down
Loading

0 comments on commit 93ccc18

Please sign in to comment.