Skip to content

Commit

Permalink
update config
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielittner committed May 27, 2024
1 parent 362d565 commit b53b75a
Show file tree
Hide file tree
Showing 15 changed files with 78 additions and 199 deletions.
16 changes: 3 additions & 13 deletions .github/renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,16 @@
matchPackagePatterns: [
"org.jetbrains.kotlin",
"com.google.devtools.ksp",
"dev.zacsweers.kctfork",
"androidx.compose.compiler",
"org.jetbrains.compose.compiler",
],
excludePackagePatterns: [
"org.jetbrains.kotlinx",
],
groupName: "Kotlin, KSP and Compose Compiler"
groupName: "Kotlin and KSP"
},
{
matchPackagePatterns: [
"androidx.compose.runtime",
"androidx.compose.ui",
"androidx.compose.foundation",
"androidx.compose.material",
"org.jetbrains.compose$",
"org.jetbrains.compose.runtime",
"org.jetbrains.compose.ui",
"org.jetbrains.compose.foundation",
"org.jetbrains.compose.material",
"androidx.compose",
"org.jetbrains.compose",
],
groupName: "Compose"
}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ local.properties
.DS_Store
build/
kotlin-js-store/
.kotlin/

docs/index.md
docs/changelog.md
3 changes: 0 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
org.gradle.jvmargs=-Xms1g -Xmx2g -XX:MaxMetaspaceSize=1g
org.gradle.parallel=true

# Do not apply dependency analysis plugin automatically to sub-projects
systemProp.dependency.analysis.autoapply=false
# Print buildHealth result
dependency.analysis.print.build.health=true

GROUP=com.freeletics.gradle
Expand Down
7 changes: 3 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
[versions]
java-target = "17"
java-toolchain = "21"
java-toolchain = "22"

fgp = "0.12.2"

kotlin = "2.0.0"
coroutines = "1.8.1"
android-gradle = "8.4.0"
android-gradle-common = "31.3.2"
jb-compose="1.6.2"
ksp="2.0.0-1.0.21"
anvil = "2.5.0-beta09"
moshix = "0.26.0"
Expand All @@ -32,11 +31,11 @@ kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "
coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
kotlin-gradle = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
kotlin-gradle-api = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin-api", version.ref = "kotlin" }
kotlin-gradle-annotations = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin-annotations", version.ref = "kotlin" }
kotlin-native-utils = { module = "org.jetbrains.kotlin:kotlin-native-utils", version.ref = "kotlin" }

android-gradle = { module = "com.android.tools.build:gradle-api", version.ref = "android-gradle" }
compose-gradle = { module = "org.jetbrains.compose:compose-gradle-plugin", version.ref = "jb-compose" }
ksp = { module = "com.google.devtools.ksp:symbol-processing-gradle-plugin", version.ref = "ksp" }
ksp-gradle = { module = "com.google.devtools.ksp:symbol-processing-gradle-plugin", version.ref = "ksp" }
anvil-gradle = { module = "com.squareup.anvil:gradle-plugin", version.ref = "anvil" }
moshix-gradle = { module = "dev.zacsweers.moshix:moshi-gradle-plugin", version.ref = "moshix" }
paparazzi-gradle = { module = "com.freeletics.fork.paparazzi:paparazzi-gradle-plugin", version.ref = "paparazzi" }
Expand Down
60 changes: 40 additions & 20 deletions kotlinw
Original file line number Diff line number Diff line change
@@ -1,32 +1,43 @@
#!/usr/bin/env bash
#!/bin/sh
set -e

ROOT_DIR="$(dirname $0)"
ROOT_DIR="$(dirname "$0")"

JDK_VERSION="$(grep -s 'java-gradle' $ROOT_DIR/gradle/libs.versions.toml | cut -d'"' -f2)"
JDK_VERSION="$(grep -s 'java-gradle' "$ROOT_DIR/gradle/libs.versions.toml" | cut -d'"' -f2)"
if [ -z "$JDK_VERSION" ]; then
JDK_VERSION="21"
JDK_VERSION="$(grep -s 'java-target' "$ROOT_DIR/gradle/libs.versions.toml" | cut -d'"' -f2)"
fi
if [ -z "$JDK_VERSION" ]; then
JDK_VERSION="22"
fi

KOTLIN_VERSION="1.9.0"
KOTLIN_VERSION="$(grep -s -m 1 '^kotlin \?=' "$ROOT_DIR/gradle/libs.versions.toml" | cut -d'"' -f2)"
if [ -f "$ROOT_DIR/gradle/libs.versions.toml" ]; then
KOTLIN_VERSION="$(grep -m 1 '^kotlin \?=' $ROOT_DIR/gradle/libs.versions.toml | cut -d'"' -f2)"
KOTLIN_VERSION="2.0.0"
fi

INSTALLATION_DIR="${HOME}/.kotlinw/${KOTLIN_VERSION}"
BINARY_DIR="${INSTALLATION_DIR}/kotlinc/bin"
# OS specific support (must be 'true' or 'false').
case "$(uname -s)" in
Linux*) MACHINE=Linux;;
Darwin*) MACHINE=Mac;;
*) MACHINE="UNSUPPORTED"
esac

if [[ "$OSTYPE" == "linux-gnu"* ]]; then
if [ -d "/usr/lib/jvm/zulu-$JDK_VERSION-amd64" ]; then
JAVA_HOME="/usr/lib/jvm/zulu-$JDK_VERSION-amd64/"
elif [ -d "/usr/lib/jvm/zulu$JDK_VERSION-ca-amd64" ]; then
JAVA_HOME="/usr/lib/jvm/zulu$JDK_VERSION-ca-amd64/"
else
java --version
if [ "$MACHINE" = "Linux" ]; then
export JAVA_HOME="/usr/lib/jvm/zulu-$JDK_VERSION-amd64/"
if [ ! -d "$JAVA_HOME" ]; then
export JAVA_HOME="/usr/lib/jvm/zulu$JDK_VERSION-ca-amd64/"
if [ ! -d "$JAVA_HOME" ]; then
echo "Installing JDK ${JDK_VERSION} (you may be prompted for your password)..."
curl -s https://repos.azul.com/azul-repo.key | sudo gpg --batch --yes --dearmor -o /usr/share/keyrings/azul.gpg
echo "deb [signed-by=/usr/share/keyrings/azul.gpg] https://repos.azul.com/zulu/deb stable main" | sudo tee /etc/apt/sources.list.d/zulu.list
sudo apt update
sudo apt install -y "zulu$JDK_VERSION-jdk"
fi
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
JAVA_HOME="/Library/Java/JavaVirtualMachines/zulu-$JDK_VERSION.jdk/Contents/Home"
if [ ! -d "/Library/Java/JavaVirtualMachines/zulu-${JDK_VERSION}.jdk/Contents/Home" ]; then
elif [ "$MACHINE" = "Mac" ]; then
export JAVA_HOME="/Library/Java/JavaVirtualMachines/zulu-$JDK_VERSION.jdk/Contents/Home"
if [ ! -d "$JAVA_HOME" ]; then
echo "Installing JDK ${JDK_VERSION} (you may be prompted for your password)..."
brew tap mdogan/zulu
brew install --cask "zulu-jdk${JDK_VERSION}"
Expand All @@ -36,9 +47,12 @@ else
exit 1
fi

INSTALLATION_DIR="${HOME}/.kotlinw/${KOTLIN_VERSION}"
BINARY_DIR="${INSTALLATION_DIR}/kotlinc/bin"

if [ ! -f "${BINARY_DIR}/kotlin" ]; then
echo "Downloading Kotlin ${KOTLIN_VERSION}"
mkdir -p ${INSTALLATION_DIR}
mkdir -p "${INSTALLATION_DIR}"
temp_file=$(mktemp /tmp/kotlin.zip.XXXXXX)
curl -sLo "${temp_file}" "https://github.com/JetBrains/kotlin/releases/download/v${KOTLIN_VERSION}/kotlin-compiler-${KOTLIN_VERSION}.zip"
unzip -q "${temp_file}" -d "${INSTALLATION_DIR}"
Expand All @@ -48,4 +62,10 @@ fi
# this works around an issue where the Kotlin compiler used by ktlint accesses code that JDK 12+ don't allow access to
export JAVA_OPTS="--add-opens java.base/java.lang=ALL-UNNAMED"

"${BINARY_DIR}/kotlin" "$@"
SCRIPT_FILE="$1"
# will remove the first element of the $@ arguments array since we read it already above
shift
# uses kotlinc instead of kotlin because the latter doesn't allow specifying a jvm target and defaults to Java 8
# the -- between SCRIPT_FILE and the other arguments is there so that the arguments are treated as arguments to the
# script and not to kotlinc
"${BINARY_DIR}/kotlinc" "-jvm-target" "$JDK_VERSION" "-script" "$SCRIPT_FILE" "--" "${@}"
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public abstract class SettingsExtension(private val settings: Settings) {
@JvmOverloads
public fun snapshots(androidXBuildId: String? = null) {
settings.dependencyResolutionManagement { management ->
@Suppress("UnstableApiUsage")
management.repositories { handler ->
handler.maven {
it.setUrl("https://oss.sonatype.org/content/repositories/snapshots/")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.gradle.develocity.agent.gradle.DevelocityPlugin
import org.gradle.api.Plugin
import org.gradle.api.credentials.PasswordCredentials
import org.gradle.api.initialization.Settings
import org.gradle.api.initialization.resolve.RepositoriesMode
import org.gradle.caching.http.HttpBuildCache
import org.gradle.kotlin.dsl.jvm
import org.gradle.toolchains.foojay.FoojayToolchainResolver
Expand Down Expand Up @@ -103,13 +102,6 @@ public abstract class SettingsPlugin : Plugin<Settings> {
}
}

// TODO https://youtrack.jetbrains.com/issue/KT-51379
val mpp = target.booleanProperty("fgp.kotlin.multiplatformProject", false)
if (!mpp) {
@Suppress("UnstableApiUsage")
management.repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
}

val prefix = "fgp.version.override."
management.versionCatalogs {
val libs = it.maybeCreate("libs")
Expand Down
4 changes: 2 additions & 2 deletions plugins/plugins.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ dependencies {
compileOnly(libs.android.gradle)
compileOnly(libs.kotlin.gradle)
compileOnly(libs.kotlin.gradle.api)
compileOnly(libs.kotlin.gradle.annotations)
compileOnly(libs.kotlin.native.utils)
compileOnly(libs.compose.gradle)
compileOnly(libs.ksp)
compileOnly(libs.ksp.gradle)
compileOnly(libs.anvil.gradle)
compileOnly(libs.moshix.gradle)
compileOnly(libs.paparazzi.gradle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.freeletics.gradle.plugin
import com.freeletics.gradle.setup.configureDagger
import com.freeletics.gradle.setup.configureMoshi
import com.freeletics.gradle.setup.setupCompose
import com.freeletics.gradle.util.compilerOptions
import com.freeletics.gradle.util.getDependency
import com.freeletics.gradle.util.kotlin
import org.gradle.api.Project
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.freeletics.gradle.plugin

import com.freeletics.gradle.util.KotlinAndroidProjectExtensionDelegate
import com.freeletics.gradle.util.addMaybe
import com.freeletics.gradle.util.booleanProperty
import com.freeletics.gradle.util.compilerOptions
import com.freeletics.gradle.util.getBundleOrNull
import com.freeletics.gradle.util.getVersionOrNull
import com.freeletics.gradle.util.java
Expand All @@ -14,6 +14,7 @@ import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.jvm.tasks.Jar
import org.gradle.jvm.toolchain.JvmVendorSpec
import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmCompilerOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion

Expand Down Expand Up @@ -66,7 +67,7 @@ public abstract class FreeleticsBasePlugin : Plugin<Project> {
toolchain.vendor.set(JvmVendorSpec.AZUL)
}

val isAndroid = this is KotlinAndroidProjectExtensionDelegate
val isAndroid = this is KotlinAndroidProjectExtension

compilerOptions {
val version = getVersionOrNull("kotlin-language")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.freeletics.gradle.plugin

import com.freeletics.gradle.util.compilerOptions
import com.freeletics.gradle.util.kotlin
import org.gradle.api.Plugin
import org.gradle.api.Project
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.freeletics.gradle.plugin

import com.freeletics.gradle.setup.defaultTestSetup
import com.freeletics.gradle.util.compilerOptions
import com.freeletics.gradle.util.freeleticsExtension
import com.freeletics.gradle.util.kotlin
import com.freeletics.gradle.util.kotlinMultiplatform
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
package com.freeletics.gradle.setup

import com.freeletics.gradle.util.android
import com.freeletics.gradle.util.booleanProperty
import com.freeletics.gradle.util.getDependency
import com.freeletics.gradle.util.getVersion
import com.freeletics.gradle.util.compilerOptions
import com.freeletics.gradle.util.kotlin
import com.freeletics.gradle.util.stringProperty
import org.gradle.api.Project
import org.jetbrains.compose.ComposeExtension
import org.jetbrains.kotlin.gradle.plugin.KotlinBasePlugin

internal fun Project.setupCompose() {
if (kotlinGradlePluginVersion().startsWith("2.")) {
setupComposeKotlin2()
} else if ((plugins.hasPlugin("com.android.library") || plugins.hasPlugin("com.android.application")) &&
!plugins.hasPlugin("org.jetbrains.kotlin.multiplatform")
) {
setupComposeAndroid()
} else {
setupComposeJetbrains()
}
plugins.apply("org.jetbrains.kotlin.plugin.compose")

val enableMetrics = project.booleanProperty("fgp.compose.enableCompilerMetrics", false)
if (enableMetrics.get()) {
Expand Down Expand Up @@ -55,67 +42,3 @@ internal fun Project.setupCompose() {
}
}
}

private fun Project.kotlinGradlePluginVersion(): String {
val id = listOf(
"org.jetbrains.kotlin.jvm",
"org.jetbrains.kotlin.android",
"org.jetbrains.kotlin.multiplatform",
).firstOrNull { plugins.hasPlugin(it) } ?: throw IllegalStateException("No Kotlin plugin found")
return (plugins.getPlugin(id) as KotlinBasePlugin).pluginVersion
}

private fun Project.setupComposeKotlin2() {
plugins.apply("org.jetbrains.kotlin.plugin.compose")

// TODO remove after RC1
if (kotlinGradlePluginVersion() == "2.0.0-RC1") {
kotlin {
compilerOptions {
freeCompilerArgs.addAll(
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:" +
"suppressKotlinVersionCompatibilityCheck=2.0.0-RC1",
)
}
}
}
}

private fun Project.setupComposeAndroid() {
android {
buildFeatures.compose = true

composeOptions {
kotlinCompilerExtensionVersion = project.getVersion("androidx.compose.compiler")
}
}

suppressVersionInconsistency()
}

private fun Project.setupComposeJetbrains() {
plugins.apply("org.jetbrains.compose")

extensions.configure(ComposeExtension::class.java) {
val composeCompiler = getDependency("jetbrains-compose-compiler").get()
it.kotlinCompilerPlugin.set("${composeCompiler.group}:${composeCompiler.name}:${composeCompiler.version}")
}

suppressVersionInconsistency()
}

private fun Project.suppressVersionInconsistency() {
val suppressComposeCompilerCheck = stringProperty("fgp.compose.kotlinVersion").orNull
if (suppressComposeCompilerCheck != null) {
kotlin {
compilerOptions {
freeCompilerArgs.addAll(
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:" +
"suppressKotlinVersionCompatibilityCheck=$suppressComposeCompilerCheck",
)
}
}
}
}
23 changes: 20 additions & 3 deletions plugins/src/main/kotlin/com/freeletics/gradle/util/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ import com.freeletics.gradle.plugin.FreeleticsAndroidExtension
import com.freeletics.gradle.plugin.FreeleticsBaseExtension
import com.freeletics.gradle.plugin.FreeleticsJvmExtension
import com.freeletics.gradle.plugin.FreeleticsMultiplatformExtension
import com.freeletics.gradle.util.KotlinProjectExtensionDelegate.Companion.kotlinProjectExtensionDelegate
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi
import org.jetbrains.kotlin.gradle.dsl.KotlinAndroidProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinCommonCompilerOptions
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinProjectExtension

internal val Project.freeleticsExtension: FreeleticsBaseExtension
get() = extensions.getByType(FreeleticsBaseExtension::class.java)
Expand All @@ -33,8 +37,21 @@ internal fun Project.java(action: JavaPluginExtension.() -> Unit) {
}
}

internal fun Project.kotlin(action: KotlinProjectExtensionDelegate.() -> Unit) {
kotlinProjectExtensionDelegate().action()
internal fun Project.kotlin(action: KotlinProjectExtension.() -> Unit) {
(project.extensions.getByName("kotlin") as KotlinProjectExtension).action()
}

@OptIn(ExperimentalKotlinGradlePluginApi::class)
internal fun KotlinProjectExtension.compilerOptions(configure: KotlinCommonCompilerOptions.() -> Unit) {
when (this) {
is KotlinJvmProjectExtension -> compilerOptions(configure)
is KotlinAndroidProjectExtension -> compilerOptions(configure)
is KotlinMultiplatformExtension -> {
compilerOptions(configure)
targets.configureEach { compilerOptions(configure) }
}
else -> throw IllegalStateException("Unsupported kotlin extension ${this::class}")
}
}

internal fun Project.kotlinMultiplatform(action: KotlinMultiplatformExtension.() -> Unit) {
Expand Down
Loading

0 comments on commit b53b75a

Please sign in to comment.