Skip to content
Draft
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
18 changes: 17 additions & 1 deletion .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,25 @@ Code formatting is checked via [Spotless](https://github.com/diffplug/spotless).
use the `spotlessApply` command.

```bash
./gradlew spotlessApply
./gradlew spotlessApply -Dorg.gradle.unsafe.isolated-projects=false
```

> **Note**: The `-Dorg.gradle.unsafe.isolated-projects=false` flag is required because this project
> uses Gradle's isolated projects feature, which Spotless does not yet support.
> See [diffplug/spotless#1979](https://github.com/diffplug/spotless/issues/1979) for details.

### Building the CLI

The CLI module uses KSP for `@AutoService` annotations. Since KSP does not yet support isolated
projects, you must disable it when building the CLI:

```bash
./gradlew :tools:cli:build -Dorg.gradle.unsafe.isolated-projects=false
```

Without this flag, the CLI JAR will not contain the service loader files and CLI commands will not
be discoverable at runtime.

Optionally, there are commit hooks in the repo you can enable by running the below
```bash
git config core.hooksPath config/git/hooks
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -143,4 +143,6 @@ jobs:

- name: Publish snapshot
if: github.repository == 'slackhq/foundry'
run: ./gradlew publish --quiet -PmavenCentralUsername=${{ secrets.SONATYPEUSERNAME }} -PmavenCentralPassword=${{ secrets.SONATYPEPASSWORD }}
# Disable isolated projects for publishing because the CLI module requires KSP
# to generate service loader files, and KSP doesn't support isolated projects yet
run: ./gradlew publish --quiet -Dorg.gradle.unsafe.isolated-projects=false -PmavenCentralUsername=${{ secrets.SONATYPEUSERNAME }} -PmavenCentralPassword=${{ secrets.SONATYPEPASSWORD }}
30 changes: 30 additions & 0 deletions build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (C) 2022 Slack Technologies, LLC
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: copyrights are wrong for a lot of these

*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
plugins { `kotlin-dsl` }

dependencies {
// Plugin dependencies - these become available in convention plugins
implementation(libs.gradlePlugins.spotless)
implementation(libs.gradlePlugins.kgp)
implementation(libs.gradlePlugins.detekt)
implementation(libs.gradlePlugins.sortDependencies)
// SAM with receiver plugin for Gradle plugin projects
implementation("org.jetbrains.kotlin:kotlin-sam-with-receiver:${libs.versions.kotlin.get()}")
// Note: Dokka and MavenPublish are applied via plugins block, not as dependencies

testImplementation(libs.junit)
testImplementation(libs.truth)
}
25 changes: 25 additions & 0 deletions build-logic/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (C) 2022 Slack Technologies, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
rootProject.name = "build-logic"

dependencyResolutionManagement {
versionCatalogs { create("libs") { from(files("../gradle/libs.versions.toml")) } }
repositories {
mavenCentral()
google()
gradlePluginPortal()
}
}
83 changes: 83 additions & 0 deletions build-logic/src/main/kotlin/foundry.kotlin-jvm-gradle.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright (C) 2022 Slack Technologies, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import io.gitlab.arturbosch.detekt.Detekt
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask
import org.jetbrains.kotlin.samWithReceiver.gradle.SamWithReceiverExtension

plugins {
id("org.jetbrains.kotlin.jvm")
id("org.jetbrains.kotlin.plugin.sam.with.receiver")
id("com.squareup.sort-dependencies")
}

val catalog = extensions.getByType<VersionCatalogsExtension>().named("libs")
val jvmTargetVersion = catalog.findVersion("jvmTarget").get().toString().let { JvmTarget.fromTarget(it) }
val jdkVersion = catalog.findVersion("jdk").get().toString().toInt()

extensions.configure<KotlinJvmProjectExtension> { explicitApi() }

extensions.configure<SamWithReceiverExtension> {
annotation("org.gradle.api.HasImplicitReceiver")
}

extensions.configure<JavaPluginExtension> {
toolchain { languageVersion.set(JavaLanguageVersion.of(jdkVersion)) }
}

tasks.withType<JavaCompile>().configureEach {
options.release.set(jvmTargetVersion.target.toInt())
}

tasks.withType<KotlinCompilationTask<*>>().configureEach {
compilerOptions {
languageVersion.set(KotlinVersion.KOTLIN_2_2)
apiVersion.set(KotlinVersion.KOTLIN_2_2)
// Gradle forces older Kotlin, which results in warnings
allWarningsAsErrors.set(false)

check(this is KotlinJvmCompilerOptions)
this.jvmTarget.set(jvmTargetVersion)
jvmDefault.set(org.jetbrains.kotlin.gradle.dsl.JvmDefaultMode.NO_COMPATIBILITY)
freeCompilerArgs.addAll(
// Required due to https://github.com/gradle/gradle/issues/24871
"-Xsam-conversions=class",
"-Xlambdas=class",
"-Xenhance-type-parameter-types-to-def-not-null",
"-Xjsr305=strict",
"-Xassertions=jvm",
"-Xemit-jvm-type-annotations",
"-Xtype-enhancement-improvements-strict-mode",
"-Xjspecify-annotations=strict",
"-Xannotation-default-target=param-property",
"-Xjdk-release=${jvmTargetVersion.target}",
)
optIn.addAll(
"kotlin.contracts.ExperimentalContracts",
"kotlin.experimental.ExperimentalTypeInference",
"kotlin.ExperimentalStdlibApi",
"kotlin.time.ExperimentalTime",
)
}
}

// Configure Detekt jvmTarget when Detekt plugin is applied
pluginManager.withPlugin("io.gitlab.arturbosch.detekt") {
tasks.withType<Detekt>().configureEach { jvmTarget = jvmTargetVersion.target }
}
74 changes: 74 additions & 0 deletions build-logic/src/main/kotlin/foundry.kotlin-jvm-intellij.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (C) 2022 Slack Technologies, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import io.gitlab.arturbosch.detekt.Detekt
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask

plugins {
id("org.jetbrains.kotlin.jvm")
id("com.squareup.sort-dependencies")
}

val catalog = extensions.getByType<VersionCatalogsExtension>().named("libs")
val jvmTargetVersion = catalog.findVersion("jvmTargetIdea").get().toString().let { JvmTarget.fromTarget(it) }
val jdkVersion = catalog.findVersion("jdk").get().toString().toInt()

// Note: No explicit API for IntelliJ plugins

extensions.configure<JavaPluginExtension> {
toolchain { languageVersion.set(JavaLanguageVersion.of(jdkVersion)) }
}

tasks.withType<JavaCompile>().configureEach {
options.release.set(jvmTargetVersion.target.toInt())
}

tasks.withType<KotlinCompilationTask<*>>().configureEach {
compilerOptions {
// https://plugins.jetbrains.com/docs/intellij/using-kotlin.html#kotlin-standard-library
languageVersion.set(KotlinVersion.KOTLIN_2_0)
apiVersion.set(KotlinVersion.KOTLIN_2_0)
// IntelliJ forces older Kotlin, which results in warnings
allWarningsAsErrors.set(false)

check(this is KotlinJvmCompilerOptions)
this.jvmTarget.set(jvmTargetVersion)
jvmDefault.set(org.jetbrains.kotlin.gradle.dsl.JvmDefaultMode.NO_COMPATIBILITY)
freeCompilerArgs.addAll(
"-Xenhance-type-parameter-types-to-def-not-null",
"-Xjsr305=strict",
"-Xassertions=jvm",
"-Xemit-jvm-type-annotations",
"-Xtype-enhancement-improvements-strict-mode",
"-Xjspecify-annotations=strict",
"-Xannotation-default-target=param-property",
"-Xjdk-release=${jvmTargetVersion.target}",
)
optIn.addAll(
"kotlin.contracts.ExperimentalContracts",
"kotlin.experimental.ExperimentalTypeInference",
"kotlin.ExperimentalStdlibApi",
"kotlin.time.ExperimentalTime",
)
}
}

// Configure Detekt jvmTarget when Detekt plugin is applied
pluginManager.withPlugin("io.gitlab.arturbosch.detekt") {
tasks.withType<Detekt>().configureEach { jvmTarget = jvmTargetVersion.target }
}
73 changes: 73 additions & 0 deletions build-logic/src/main/kotlin/foundry.kotlin-jvm.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (C) 2022 Slack Technologies, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import io.gitlab.arturbosch.detekt.Detekt
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask

plugins {
id("org.jetbrains.kotlin.jvm")
id("com.squareup.sort-dependencies")
}

val catalog = extensions.getByType<VersionCatalogsExtension>().named("libs")
val jvmTargetVersion = catalog.findVersion("jvmTarget").get().toString().let { JvmTarget.fromTarget(it) }
val jdkVersion = catalog.findVersion("jdk").get().toString().toInt()

extensions.configure<KotlinJvmProjectExtension> { explicitApi() }

extensions.configure<JavaPluginExtension> {
toolchain { languageVersion.set(JavaLanguageVersion.of(jdkVersion)) }
}

tasks.withType<JavaCompile>().configureEach {
options.release.set(jvmTargetVersion.target.toInt())
}

tasks.withType<KotlinCompilationTask<*>>().configureEach {
compilerOptions {
languageVersion.set(KotlinVersion.DEFAULT)
apiVersion.set(KotlinVersion.DEFAULT)
allWarningsAsErrors.set(true)

check(this is KotlinJvmCompilerOptions)
this.jvmTarget.set(jvmTargetVersion)
jvmDefault.set(org.jetbrains.kotlin.gradle.dsl.JvmDefaultMode.NO_COMPATIBILITY)
freeCompilerArgs.addAll(
"-Xenhance-type-parameter-types-to-def-not-null",
"-Xjsr305=strict",
"-Xassertions=jvm",
"-Xemit-jvm-type-annotations",
"-Xtype-enhancement-improvements-strict-mode",
"-Xjspecify-annotations=strict",
"-Xannotation-default-target=param-property",
"-Xjdk-release=${jvmTargetVersion.target}",
)
optIn.addAll(
"kotlin.contracts.ExperimentalContracts",
"kotlin.experimental.ExperimentalTypeInference",
"kotlin.ExperimentalStdlibApi",
"kotlin.time.ExperimentalTime",
)
}
}

// Configure Detekt jvmTarget when Detekt plugin is applied
pluginManager.withPlugin("io.gitlab.arturbosch.detekt") {
tasks.withType<Detekt>().configureEach { jvmTarget = jvmTargetVersion.target }
}
Loading