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

Defer resolution of processor classpath #1312

Merged
merged 1 commit into from
Feb 10, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import org.gradle.api.Action
import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.api.UnknownTaskException
import org.gradle.api.artifacts.Configuration
import org.gradle.api.attributes.Attribute
import org.gradle.api.file.ConfigurableFileCollection
import org.gradle.api.file.FileCollection
Expand Down Expand Up @@ -112,7 +111,6 @@ class KspGradleSubplugin @Inject internal constructor(private val registry: Tool
private fun getSubpluginOptions(
project: Project,
kspExtension: KspExtension,
classpath: Configuration,
sourceSetName: String,
target: String,
isIncremental: Boolean,
Expand Down Expand Up @@ -140,7 +138,6 @@ class KspGradleSubplugin @Inject internal constructor(private val registry: Tool
)
options += InternalSubpluginOption("projectBaseDir", project.project.projectDir.canonicalPath)
options += SubpluginOption("allWarningsAsErrors", allWarningsAsErrors.toString())
options += FilesSubpluginOption("apclasspath", classpath.toList())
// Turn this on by default to work KT-30172 around. It is off by default in the compiler plugin.
options += SubpluginOption(
"returnOkOnError",
Expand Down Expand Up @@ -303,7 +300,6 @@ class KspGradleSubplugin @Inject internal constructor(private val registry: Tool
getSubpluginOptions(
project,
kspExtension,
processorClasspath,
sourceSetName,
target,
isIncremental,
Expand Down Expand Up @@ -460,7 +456,7 @@ class KspGradleSubplugin @Inject internal constructor(private val registry: Tool
getKspCachesDir(project, sourceSetName, target),
project.provider { project.files() },
project.provider { project.files() },
project.provider { project.files() },
project.provider { processorClasspath }
)
)
}
Expand All @@ -483,7 +479,7 @@ class KspGradleSubplugin @Inject internal constructor(private val registry: Tool
getKspCachesDir(project, sourceSetName, target),
project.provider { project.files() },
project.provider { project.files() },
project.provider { project.files() },
project.provider { processorClasspath }
)
)
}
Expand Down Expand Up @@ -512,6 +508,7 @@ class KspGradleSubplugin @Inject internal constructor(private val registry: Tool
kspTask.compilerPluginOptions.addPluginArgument(kotlinCompileTask.compilerPluginOptions)
}
kspTask.commonSources.from(kotlinCompileTask.commonSources)
kspTask.options.add(FilesSubpluginOption("apclasspath", processorClasspath.files.toList()))
val kspOptions = kspTask.options.get().flatMap { listOf("-P", it.toArg()) }
kspTask.compilerOptions.freeCompilerArgs.value(
kspOptions + kotlinCompileTask.compilerOptions.freeCompilerArgs.get()
Expand Down Expand Up @@ -726,6 +723,7 @@ internal fun createIncrementalChangesTransformer(
processorCP: Provider<FileCollection>,
): (ChangedFiles) -> List<SubpluginOption> = { changedFiles ->
val options = mutableListOf<SubpluginOption>()
val apClasspath = processorCP.get().files.toList()
if (isKspIncremental) {
if (isIntermoduleIncremental) {
// findClasspathChanges may clear caches, if there are
Expand All @@ -736,7 +734,7 @@ internal fun createIncrementalChangesTransformer(
cacheDir,
classpathStructure.get().files,
libraries.get().files.toList(),
processorCP.get().files.toList()
apClasspath
)
options += classpathChanges.toSubpluginOptions()
} else {
Expand All @@ -749,5 +747,7 @@ internal fun createIncrementalChangesTransformer(
}
options += changedFiles.toSubpluginOptions()

options += FilesSubpluginOption("apclasspath", apClasspath)

options
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2020 Google LLC
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
*
* 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
*
* http://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.
*/

package com.google.devtools.ksp.test

import org.gradle.testkit.runner.GradleRunner
import org.junit.Assert
import org.junit.Rule
import org.junit.Test
import java.io.File

class AGP741IT {
@Rule
@JvmField
val project: TemporaryTestProject = TemporaryTestProject("playground-android-multi", "playground")

@Test
fun testDependencyResolutionCheck() {
val gradleRunner = GradleRunner.create().withProjectDir(project.root).withGradleVersion("7.6")

File(project.root, "gradle.properties").appendText("\nagpVersion=7.4.1")
gradleRunner.withArguments(":workload:compileDebugKotlin").build().let { result ->
Assert.assertFalse(result.output.contains("was resolved during configuration time."))
}
}
}