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

Cherry-pick #2069 manually #2121

Merged
merged 1 commit into from
Sep 28, 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
14 changes: 2 additions & 12 deletions .github/workflows/auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,10 @@ jobs:
echo Picking $TO_PICK
if [ -n "$TO_PICK" ]; then git cherry-pick -x $TO_PICK; fi

- name: Setup Java 9
- name: Setup Java 17
uses: actions/setup-java@v1.4.3
with:
java-version: '9'
java-package: jdk
architecture: x64
- name: set JDK_9 environment variable for kotlin compiler
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
run: echo ::set-env name=JDK_9::$(echo $JAVA_HOME)
- name: Setup Java 11
uses: actions/setup-java@v1.4.3
with:
java-version: '11'
java-version: '17'
java-package: jdk
architecture: x64

Expand Down
15 changes: 2 additions & 13 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,10 @@ jobs:
minimum-size: 8
maximum-size: 16
disk-root: "D:"
- name: Setup Java 9
- name: Setup Java 17
uses: actions/setup-java@v1.4.3
with:
java-version: '9'
java-package: jdk
architecture: x64
- name: set JDK_9 environment variable for kotlin compiler
shell: bash
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
run: echo ::set-env name=JDK_9::$(echo $JAVA_HOME)
- name: Setup Java 11
uses: actions/setup-java@v1.4.3
with:
java-version: '11'
java-version: '17'
java-package: jdk
architecture: x64

Expand Down
14 changes: 2 additions & 12 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Setup Java 9
- name: Setup Java 17
uses: actions/setup-java@v1.4.3
with:
java-version: '9'
java-package: jdk
architecture: x64
- name: set JDK_9 environment variable for kotlin compiler
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
run: echo ::set-env name=JDK_9::$(echo $JAVA_HOME)
- name: Setup Java 11
uses: actions/setup-java@v1.4.3
with:
java-version: '11'
java-version: '17'
java-package: jdk
architecture: x64

Expand Down
6 changes: 3 additions & 3 deletions benchmark/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ dependencies {
application {
applicationName = "BenchRunner"
group = "com.google.devtools.ksp"
mainClassName = "com.google.devtools.ksp.BenchRunner"
mainClass = "com.google.devtools.ksp.BenchRunner"
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
compilerOptions.jvmTarget = "1.8"
}
tasks.withType<Jar> {
manifest {
attributes(mapOf("Main-Class" to application.mainClassName))
attributes(mapOf("Main-Class" to application.mainClass.get()))
}
}
45 changes: 20 additions & 25 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import com.google.devtools.ksp.configureKtlint
import com.google.devtools.ksp.configureKtlintApplyToIdea
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion

val sonatypeUserName: String? by project
val sonatypePassword: String? by project
Expand All @@ -25,7 +28,7 @@ plugins {

// Adding plugins used in multiple places to the classpath for centralized version control
id("com.github.johnrengelman.shadow") version "7.1.2" apply false
id("org.jetbrains.dokka") version "1.8.10" apply false
id("org.jetbrains.dokka") version "1.9.20" apply false
}

nexusPublishing {
Expand Down Expand Up @@ -64,7 +67,7 @@ subprojects {
}
maven {
name = "test"
url = uri("${rootProject.buildDir}/repos/test")
url = uri("${rootProject.layout.buildDirectory.get().asFile}/repos/test")
}
}
publishExtension.publications.whenObjectAdded {
Expand Down Expand Up @@ -94,32 +97,24 @@ subprojects {
}
}

tasks.withType<JavaCompile>().configureEach {
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
targetCompatibility = JavaVersion.VERSION_1_8.toString()
javaCompiler.set(
javaToolchains.compilerFor {
languageVersion.set(JavaLanguageVersion.of(17))
}
)
}
val compileJavaVersion = JavaLanguageVersion.of(17)

tasks.withType<Test>().configureEach {
// Java 11 is required to run tests
javaLauncher.set(
javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(11))
pluginManager.withPlugin("org.jetbrains.kotlin.jvm") {
configure<JavaPluginExtension> {
toolchain.languageVersion.set(compileJavaVersion)
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
configure<KotlinJvmProjectExtension> {
compilerOptions {
jvmTarget = JvmTarget.JVM_11
languageVersion.set(KotlinVersion.KOTLIN_1_9)
apiVersion.set(languageVersion)
}
)
}

tasks.withType<JavaExec>().configureEach {
// Java 11 is required to run
javaLauncher.set(
javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(17))
jvmToolchain {
languageVersion = compileJavaVersion
}
)
}
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
Expand Down
14 changes: 2 additions & 12 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm") version "1.9.0"
kotlin("jvm") version embeddedKotlinVersion
}

kotlin {
jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(11))
languageVersion.set(JavaLanguageVersion.of(17))
}
}

repositories {
mavenCentral()
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap/")
}

// As per https://docs.gradle.org/7.2/userguide/validation_problems.html#implementation_unknown
tasks.withType<KotlinCompile>().configureEach {
kotlinOptions {
apiVersion = "1.4"
languageVersion = "1.4"
}
}
4 changes: 3 additions & 1 deletion buildSrc/src/main/kotlin/com/google/devtools/ksp/Ktlint.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ private fun JavaExec.configureCommonKtlintParams(
it.exclude("**/.*/**")
it.exclude("**/resources/**")
}
val outputFile = project.buildDir.resolve("reports/ktlint/ktlint-checkstyle-report.xml").toRelativeString(project.projectDir)
val outputFile = project.layout.buildDirectory.file("reports/ktlint/ktlint-checkstyle-report.xml")
.map{ it.asFile.toRelativeString(project.layout.projectDirectory.asFile) }
.get()
inputs.files(ktlintInputFiles).withPropertyName("ktlintInputFiles").withPathSensitivity(PathSensitivity.RELATIVE)
classpath = project.getKtlintConfiguration()
mainClass.set("com.pinterest.ktlint.Main")
Expand Down
35 changes: 15 additions & 20 deletions compiler-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import com.google.devtools.ksp.RelativizingPathProvider
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

evaluationDependsOn(":common-util")
Expand All @@ -10,8 +11,8 @@ val kotlinBaseVersion: String by project
val junitVersion: String by project
val junit5Version: String by project
val junitPlatformVersion: String by project
val libsForTesting by configurations.creating
val libsForTestingCommon by configurations.creating
val libsForTesting: Configuration by configurations.creating
val libsForTestingCommon: Configuration by configurations.creating

tasks.withType<KotlinCompile> {
compilerOptions.freeCompilerArgs.add("-Xjvm-default=all-compatibility")
Expand Down Expand Up @@ -81,23 +82,23 @@ val dokkaJavadocJar by tasks.register<Jar>("dokkaJavadocJar") {
archiveClassifier.set("javadoc")
}

tasks.register<Copy>("CopyLibsForTesting") {
from(configurations.get("libsForTesting"))
val copyLibsForTesting by tasks.registering(Copy::class) {
from(configurations["libsForTesting"])
into("dist/kotlinc/lib")
val escaped = Regex.escape(kotlinBaseVersion)
rename("(.+)-$escaped\\.jar", "$1.jar")
}

tasks.register<Copy>("CopyLibsForTestingCommon") {
from(configurations.get("libsForTestingCommon"))
val copyLibsForTestingCommon by tasks.registering(Copy::class) {
from(configurations["libsForTestingCommon"])
into("dist/common")
val escaped = Regex.escape(kotlinBaseVersion)
rename("(.+)-$escaped\\.jar", "$1.jar")
}

tasks.test {
dependsOn("CopyLibsForTesting")
dependsOn("CopyLibsForTestingCommon")
dependsOn(copyLibsForTesting)
dependsOn(copyLibsForTestingCommon)
maxHeapSize = "2g"

useJUnitPlatform()
Expand All @@ -110,16 +111,10 @@ tasks.test {
events("passed", "skipped", "failed")
}

lateinit var tempTestDir: File
doFirst {
val ideaHomeDir = buildDir.resolve("tmp/ideaHome").takeIf { it.exists() || it.mkdirs() }!!
jvmArgumentProviders.add(com.google.devtools.ksp.RelativizingPathProvider("idea.home.path", ideaHomeDir))

tempTestDir = createTempDir()
jvmArgumentProviders.add(com.google.devtools.ksp.RelativizingPathProvider("java.io.tmpdir", tempTestDir))
}

doLast {
delete(tempTestDir)
}
val ideaHomeDir = layout.buildDirectory.dir("tmp/ideaHome")
.get()
.asFile
.apply { if (!exists()) mkdirs() }
jvmArgumentProviders.add(RelativizingPathProvider("idea.home.path", ideaHomeDir))
jvmArgumentProviders.add(RelativizingPathProvider("java.io.tmpdir", temporaryDir))
}
46 changes: 22 additions & 24 deletions gradle-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,13 @@ signing {
* Create a properties file with that can be read from the gradle-plugin tests to setup test
* projects.
*/
val testPropsOutDir = project.layout.buildDirectory.dir("test-config")
val testPropsOutDir = layout.buildDirectory.dir("test-config")
val writeTestPropsTask = tasks.register<WriteProperties>("prepareTestConfiguration") {
description = "Generates a properties file with the current environment for gradle integration tests"
this.setOutputFile(
testPropsOutDir.map {
it.file("testprops.properties")
}
)
destinationFile = testPropsOutDir.map { it.file("testprops.properties") }
property("kspVersion", version)
property("mavenRepoDir", File(rootProject.buildDir, "repos/test").absolutePath)
property("kspProjectRootDir", rootProject.projectDir.absolutePath)
property("mavenRepoDir", rootProject.layout.buildDirectory.dir("repos/test").get().asFile.absolutePath)
property("kspProjectRootDir", rootDir.absolutePath)
property("processorClasspath", project.tasks["compileTestKotlin"].outputs.files.asPath)
}

Expand Down Expand Up @@ -147,35 +143,37 @@ tasks.named<Test>("test").configure {
dependsOn(":symbol-processing-aa-embeddable:publishAllPublicationsToTestRepository")
}

abstract class WriteVersionSrcTask @Inject constructor(
@get:Input val kspVersion: String,
@get:Input val kotlinVersion: String,
@get:org.gradle.api.tasks.OutputDirectory val outputSrcDir: File
) : DefaultTask() {
abstract class WriteVersionSrcTask : DefaultTask() {
@get:Input
abstract val kspVersion: Property<String>
@get:Input
abstract val kotlinVersion: Property<String>

@get:OutputDirectory
abstract val outputSrcDir: DirectoryProperty

@TaskAction
fun generate() {
File(outputSrcDir, "KSPVersions.kt").writeText(
outputSrcDir.file("KSPVersions.kt").get().asFile.writeText(
"""
package com.google.devtools.ksp.gradle
val KSP_KOTLIN_BASE_VERSION = "$kotlinVersion"
val KSP_VERSION = "$kspVersion"
val KSP_KOTLIN_BASE_VERSION = "${kotlinVersion.get()}"
val KSP_VERSION = "${kspVersion.get()}"
""".trimIndent()
)
}
}

val kspVersionDir = File(project.buildDir, "generated/ksp-versions")
val writeVersionSrcTask = tasks.register<WriteVersionSrcTask>(
"generateKSPVersions",
version.toString(),
kotlinBaseVersion,
kspVersionDir
)
val writeVersionSrcTask = tasks.register<WriteVersionSrcTask>("generateKSPVersions") {
kspVersion = version.toString()
kotlinVersion = kotlinBaseVersion
outputSrcDir = layout.buildDirectory.dir("generated/ksp-versions")
}

kotlin {
sourceSets {
main {
kotlin.srcDir(writeVersionSrcTask.map { it.outputSrcDir })
kotlin.srcDir(writeVersionSrcTask)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ abstract class KspAATask @Inject constructor(
}
}
)
val logLevel = LogLevel.values().first {
val logLevel = LogLevel.entries.first {
project.logger.isEnabled(it)
}
cfg.logLevel.value(logLevel)
Expand All @@ -252,17 +252,13 @@ abstract class KspAATask @Inject constructor(
// TODO: set proper jdk home
cfg.jdkHome.value(File(System.getProperty("java.home")))

val jvmDefaultMode = project.provider {
compilerOptions.freeCompilerArgs.get().lastOrNull {
it.startsWith("-Xjvm-default=")
}?.substringAfter("=") ?: "disable"
}
val jvmDefaultMode = compilerOptions.freeCompilerArgs
.map { args -> args.filter { it.startsWith("-Xjvm-default=") } }
.map { it.lastOrNull()?.substringAfter("=") ?: "disable" }

cfg.jvmDefaultMode.value(jvmDefaultMode)

val jvmTarget = project.provider {
compilerOptions.jvmTarget.get().target
}
cfg.jvmTarget.value(jvmTarget)
cfg.jvmTarget.value(compilerOptions.jvmTarget.map { it.target })
}

cfg.platformType.value(kotlinCompilation.platformType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ abstract class KspExtension @Inject constructor(project: Project) {
// Instruct KSP to pickup sources from compile tasks, instead of source sets.
// Note that it depends on behaviors of other Gradle plugins, that may bring surprises and can be hard to debug.
// Use your discretion.
@Deprecated("This feature is broken in recent versions of Gradle and is no longer supported in KSP2.")
open var allowSourcesFromOtherPlugins: Boolean = false

// Treat all warning as errors.
Expand Down
Loading
Loading