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

Port over kotlin-cli-util to :tools:cli #998

Merged
merged 6 commits into from
Oct 1, 2024
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
82 changes: 58 additions & 24 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import org.jetbrains.intellij.platform.gradle.extensions.IntelliJPlatformExtensi
import org.jetbrains.intellij.platform.gradle.tasks.BuildPluginTask
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion.Companion.DEFAULT
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_1_9
import org.jetbrains.kotlin.gradle.plugin.KotlinBasePlugin
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
Expand All @@ -54,6 +55,25 @@ plugins {
alias(libs.plugins.buildConfig) apply false
alias(libs.plugins.lint) apply false
alias(libs.plugins.wire) apply false
alias(libs.plugins.binaryCompatibilityValidator)
}

apiValidation {
// only :tools:cli is tracking this right now
// Annoyingly this only uses simple names
// https://github.com/Kotlin/binary-compatibility-validator/issues/16
ignoredProjects +=
listOf(
"agp-handler-api",
"foundry-gradle-plugin",
"artifactory-authenticator",
"compose",
"playground",
"skate",
"foundry-common",
"skippy",
"tracing",
)
}

configure<DetektExtension> {
Expand Down Expand Up @@ -196,7 +216,10 @@ subprojects {
tasks.withType<JavaCompile>().configureEach { options.release.set(17) }
}

val isForIntelliJPlugin = project.hasProperty("INTELLIJ_PLUGIN")
val isForIntelliJPlugin =
project.hasProperty("INTELLIJ_PLUGIN") || project.path.startsWith(":platforms:intellij")
val isForGradle =
project.hasProperty("GRADLE_PLUGIN") || project.path.startsWith(":platforms:gradle")
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
extensions.configure<KotlinJvmProjectExtension> {
if (!isForIntelliJPlugin) {
Expand All @@ -205,7 +228,7 @@ subprojects {
}

// Reimplement kotlin-dsl's application of this function for nice DSLs
if (!isForIntelliJPlugin) {
if (isForGradle) {
apply(plugin = "kotlin-sam-with-receiver")
configure<SamWithReceiverExtension> { annotation("org.gradle.api.HasImplicitReceiver") }
}
Expand All @@ -219,21 +242,26 @@ subprojects {
val kotlinVersion =
if (isForIntelliJPlugin) {
KOTLIN_1_9
} else {
} else if (isForGradle) {
KOTLIN_1_9
} else {
DEFAULT
}
languageVersion.set(kotlinVersion)
apiVersion.set(kotlinVersion)

if (!isForIntelliJPlugin) {
// Gradle forces a lower version of kotlin, which results in warnings that prevent use of
// this sometimes. https://github.com/gradle/gradle/issues/16345
if (kotlinVersion != DEFAULT) {
// Gradle/IntelliJ forces a lower version of kotlin, which results in warnings that
// prevent use of this sometimes.
// https://github.com/gradle/gradle/issues/16345
allWarningsAsErrors.set(false)
// TODO required due to https://github.com/gradle/gradle/issues/24871
freeCompilerArgs.add("-Xsam-conversions=class")
} else {
allWarningsAsErrors.set(true)
}
if (isForGradle) {
// TODO required due to https://github.com/gradle/gradle/issues/24871
freeCompilerArgs.add("-Xsam-conversions=class")
}
this.jvmTarget.set(jvmTargetVersion)
freeCompilerArgs.addAll(
// Enhance not null annotated type parameter's types to definitely not null types
Expand Down Expand Up @@ -289,22 +317,28 @@ subprojects {
includes.from(readMeProvider)
}
skipDeprecated.set(true)
// Gradle docs
externalDocumentationLink {
url.set(URI("https://docs.gradle.org/${gradle.gradleVersion}/javadoc/index.html").toURL())
}
// AGP docs
externalDocumentationLink {
val agpVersionNumber = VersionNumber.parse(libs.versions.agp.get()).baseVersion
val simpleApi = "${agpVersionNumber.major}.${agpVersionNumber.minor}"
packageListUrl.set(
URI("https://developer.android.com/reference/tools/gradle-api/$simpleApi/package-list")
.toURL()
)
url.set(
URI("https://developer.android.com/reference/tools/gradle-api/$simpleApi/classes")
.toURL()
)
if (isForGradle) {
// Gradle docs
externalDocumentationLink {
url.set(
URI("https://docs.gradle.org/${gradle.gradleVersion}/javadoc/index.html").toURL()
)
}
// AGP docs
externalDocumentationLink {
val agpVersionNumber = VersionNumber.parse(libs.versions.agp.get()).baseVersion
val simpleApi = "${agpVersionNumber.major}.${agpVersionNumber.minor}"
packageListUrl.set(
URI(
"https://developer.android.com/reference/tools/gradle-api/$simpleApi/package-list"
)
.toURL()
)
url.set(
URI("https://developer.android.com/reference/tools/gradle-api/$simpleApi/classes")
.toURL()
)
}
}
sourceLink {
localDirectory.set(layout.projectDirectory.dir("src").asFile)
Expand Down
15 changes: 12 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencyAnalysisPlugin = "1.33.0"
detekt = "1.23.7"
dokka = "1.9.20"
errorproneGradle = "3.1.0"
gradle-retry = "1.6.0"
intellij-platform = "2.0.1"
jdk = "22"
jvmTarget = "17"
Expand All @@ -36,9 +37,11 @@ spotless = "7.0.0.BETA2"
sqldelight = "2.0.2"
versionsPlugin = "0.47.0"
wire = "5.1.0"
xmlutil = "0.90.1"

[plugins]
bestPracticesPlugin = { id = "com.autonomousapps.plugin-best-practices-plugin", version = "0.10" }
binaryCompatibilityValidator = { id = "org.jetbrains.kotlinx.binary-compatibility-validator", version = "0.16.3" }
buildConfig = { id = "com.github.gmazzo.buildconfig", version = "5.5.0" }
compose = { id = "org.jetbrains.compose", version.ref = "compose-jb" }
dependencyAnalysis = { id = "com.autonomousapps.dependency-analysis", version.ref = "dependencyAnalysisPlugin" }
Expand All @@ -57,6 +60,7 @@ mavenPublish = { id = "com.vanniktech.maven.publish", version.ref = "mavenPublis
moshiGradlePlugin = { id = "dev.zacsweers.moshix", version.ref = "moshix" }
moshix = { id = "dev.zacsweers.moshix", version.ref = "moshix" }
pluginUploader = { id = "dev.bmac.intellij.plugin-uploader", version = "1.3.5" }
retry = { id = "org.gradle.test-retry", version.ref = "gradle-retry" }
spotless = { id = "com.diffplug.spotless", version.ref = "spotless" }
sortDependencies = { id = "com.squareup.sort-dependencies", version.ref = "sortDependencies" }
versionsPlugin = { id = "com.github.ben-manes.versions", version.ref = "versionsPlugin" }
Expand Down Expand Up @@ -95,19 +99,19 @@ gradlePlugins-ksp = { module = "com.google.devtools.ksp:symbol-processing-gradle
gradlePlugins-moshix = { module = "dev.zacsweers.moshix:moshi-gradle-plugin", version.ref = "moshix" }
gradlePlugins-nullaway = { module = "net.ltgt.gradle:gradle-nullaway-plugin", version.ref = "nullawayGradle" }
gradlePlugins-redacted = "dev.zacsweers.redacted:redacted-compiler-plugin-gradle:1.10.0"
gradlePlugins-retry = "org.gradle:test-retry-gradle-plugin:1.6.0"
gradlePlugins-retry = { module = "org.gradle:test-retry-gradle-plugin", version.ref = "gradle-retry" }
gradlePlugins-sortDependencies = { module = "com.squareup:sort-dependencies-gradle-plugin", version.ref = "sortDependencies" }
gradlePlugins-spotless = { module = "com.diffplug.spotless:spotless-plugin-gradle", version.ref = "spotless" }
gradlePlugins-sqldelight = { module = "app.cash.sqldelight:gradle-plugin", version.ref = "sqldelight" }
gradlePlugins-versions = { module = "com.github.ben-manes:gradle-versions-plugin", version.ref = "versionsPlugin" }
gradlePlugins-wire = { module = "com.squareup.wire:wire-gradle-plugin", version.ref = "wire" }
guava = "com.google.guava:guava:33.3.1-jre"
kaml = { module = "com.charleskorn.kaml:kaml", version.ref = "kaml" }
kotlinCliUtil = "com.slack.cli:kotlin-cli-util:3.0.1"
kotlin-bom = { module = "org.jetbrains.kotlin:kotlin-bom", version.ref = "kotlin" }
kotlin-poet = { module = "com.squareup:kotlinpoet", version.ref = "kotlinPoet" }
kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" }
kotlinx-serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core", version.ref = "kotlinx-serialization" }
kotlinShell = "eu.jrie.jetbrains:kotlin-shell-core:0.2.1"
ktfmt = { module = "com.facebook:ktfmt", version.ref = "ktfmt" }
jewel-bridge = { module = "org.jetbrains.jewel:jewel-ide-laf-bridge-241", version.ref = "jewel" }
jewel-standalone = { module = "org.jetbrains.jewel:jewel-int-ui-standalone-241", version.ref = "jewel" }
Expand All @@ -126,6 +130,11 @@ oshi = "com.github.oshi:oshi-core:6.6.5"
retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit" }
retrofit-converters-wire = { module = "com.squareup.retrofit2:converter-wire", version.ref = "retrofit" }
rxjava = "io.reactivex.rxjava3:rxjava:3.1.9"
sarif4k = "io.github.detekt.sarif4k:sarif4k:0.6.0"
slackLints-checks = { module = "com.slack.lint:slack-lint-checks", version.ref = "slack-lint" }
slackLints-annotations = { module = "com.slack.lint:slack-lint-annotations", version.ref = "slack-lint" }
truth = "com.google.truth:truth:1.4.4"
slf4jNop = "org.slf4j:slf4j-nop:2.0.16"
tikxml-htmlEscape = { module = "com.tickaroo.tikxml:converter-htmlescape", version = "0.8.15" }
truth = "com.google.truth:truth:1.4.4"
xmlutil-core = { module = "io.github.pdvrieze.xmlutil:core", version.ref = "xmlutil" }
xmlutil-serialization = { module = "io.github.pdvrieze.xmlutil:serialization", version.ref = "xmlutil" }
2 changes: 1 addition & 1 deletion platforms/gradle/foundry-gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ dependencies {
implementation(libs.jgrapht)
implementation(libs.jna)
implementation(libs.jna.platform)
implementation(libs.kotlinCliUtil)
implementation(libs.moshi)
implementation(libs.oshi) { because("To read hardware information") }
implementation(libs.rxjava)
implementation(projects.tools.cli)
implementation(projects.tools.foundryCommon)
implementation(projects.tools.skippy)

Expand Down
2 changes: 1 addition & 1 deletion platforms/gradle/foundry-gradle-plugin/lint-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@
errorLine2="~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~">
<location
file="src/main/kotlin/foundry/gradle/FoundryTools.kt"
line="52"
line="53"
column="1"/>
</issue>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.autonomousapps.DependencyAnalysisExtension
import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
import com.osacky.doctor.DoctorExtension
import com.squareup.moshi.adapter
import foundry.cli.AppleSiliconCompat
import foundry.gradle.agp.VersionNumber
import foundry.gradle.avoidance.ComputeAffectedProjectsTask
import foundry.gradle.avoidance.GenerateAndroidTestProjectPathsTask
Expand Down Expand Up @@ -56,7 +57,6 @@ import org.gradle.api.logging.Logging
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.Delete
import org.gradle.jvm.toolchain.JvmVendorSpec
import slack.cli.AppleSiliconCompat

/**
* A common entry point for Foundry project configuration. This should only be applied once and on
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import com.google.common.collect.Sets
import com.squareup.moshi.JsonWriter
import com.squareup.moshi.Moshi
import com.squareup.moshi.adapter
import foundry.cli.AppleSiliconCompat
import foundry.gradle.FoundryTools.Companion.SERVICE_NAME
import foundry.gradle.FoundryTools.Parameters
import foundry.gradle.agp.AgpHandler
Expand Down Expand Up @@ -50,7 +51,6 @@ import org.gradle.api.services.BuildService
import org.gradle.api.services.BuildServiceParameters
import org.gradle.api.services.BuildServiceRegistration
import org.gradle.internal.os.OperatingSystem
import slack.cli.AppleSiliconCompat

/** Misc tools for Foundry Gradle projects, usable in tasks as a [BuildService] too. */
public abstract class FoundryTools : BuildService<Parameters>, AutoCloseable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package foundry.gradle.tasks

import foundry.cli.AppleSiliconCompat
import foundry.cli.AppleSiliconCompat.isMacOS
import foundry.gradle.FoundryProperties
import foundry.gradle.isCi
import foundry.gradle.isRootProject
Expand Down Expand Up @@ -62,8 +64,6 @@ import org.gradle.jvm.toolchain.JavaLauncher
import org.gradle.jvm.toolchain.JavaToolchainService
import org.gradle.jvm.toolchain.JvmVendorSpec
import oshi.SystemInfo
import slack.cli.AppleSiliconCompat
import slack.cli.AppleSiliconCompat.isMacOS

/**
* Other bootstrap tasks can be finalized by this and/or depend on its outputs by implementing this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import com.squareup.moshi.JsonClass
import com.sun.jna.Library
import com.sun.jna.Native
import dev.zacsweers.moshix.sealed.annotations.TypeLabel
import foundry.cli.AppleSiliconCompat.Arch
import foundry.cli.AppleSiliconCompat.Arch.ARM64
import foundry.cli.AppleSiliconCompat.Arch.X86_64
import foundry.gradle.util.AppleSiliconThermals.ThermalState.CRITICAL
import foundry.gradle.util.AppleSiliconThermals.ThermalState.FAIR
import foundry.gradle.util.AppleSiliconThermals.ThermalState.NOMINAL
Expand All @@ -39,9 +42,6 @@ import java.util.concurrent.TimeUnit.SECONDS
import java.util.concurrent.atomic.AtomicBoolean
import kotlin.jvm.Throws
import org.gradle.api.logging.Logger
import slack.cli.AppleSiliconCompat.Arch
import slack.cli.AppleSiliconCompat.Arch.ARM64
import slack.cli.AppleSiliconCompat.Arch.X86_64

/**
* Simple interface for recording thermals data during the course of a build. The watcher should be
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ include(
":platforms:intellij:compose",
":platforms:intellij:compose:playground",
":platforms:intellij:skate",
":tools:cli",
":tools:foundry-common",
":tools:skippy",
":tools:tracing",
Expand Down
Loading