Kapt3: Set correct compiler options when the annotation processing classpath is empty (KT-15146). Disable annotation processing in Javac task a bit earlier

This commit is contained in:
Yan Zhulanow
2016-12-19 19:35:16 +03:00
committed by Yan Zhulanow
parent f8edf51c1b
commit 568523b065
5 changed files with 81 additions and 11 deletions
@@ -39,7 +39,7 @@ class Kapt3IT : BaseGradleIT() {
private fun CompiledProject.assertKaptSuccessful() {
KAPT_SUCCESSFUL_REGEX.findAll(this.output).single()
KAPT_SUCCESSFUL_REGEX.findAll(this.output).count() > 0
}
@Test
@@ -151,7 +151,7 @@ class Kapt3IT : BaseGradleIT() {
val project = Project("android-dagger", GRADLE_VERSION, directoryPrefix = "kapt2")
val options = androidBuildOptions()
project.build("compileReleaseSources", options = options) {
project.build("compileReleaseSources", ":app:compileDebugUnitTestJavaWithJavac", options = options) {
assertSuccessful()
assertKaptSuccessful()
assertFileExists("app/build/generated/source/kapt/release/com/example/dagger/kotlin/DaggerApplicationComponent.java")
@@ -0,0 +1,19 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* 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.myapp
class SimpleClass
@@ -141,12 +141,15 @@ class Kapt3KotlinGradleSubplugin : KotlinGradleSubplugin<KotlinCompile> {
(variantData as BaseVariantData<*>).addJavaSourceFoldersToModel(generatedFilesDir)
}
pluginOptions += SubpluginOption("aptOnly", "true")
disableAnnotationProcessingInJavaTask()
// Skip annotation processing in kotlinc if no kapt dependencies were provided
if (kaptClasspath.isEmpty()) return emptyList()
if (kaptClasspath.isEmpty()) return pluginOptions
kaptClasspath.forEach { pluginOptions += SubpluginOption("apclasspath", it.absolutePath) }
javaCompile.source(generatedFilesDir)
disableAnnotationProcessingInJavaTask()
pluginOptions += SubpluginOption("sources", generatedFilesDir.canonicalPath)
pluginOptions += SubpluginOption("classes", kotlinCompile.destinationDir.canonicalPath)
@@ -176,7 +179,6 @@ class Kapt3KotlinGradleSubplugin : KotlinGradleSubplugin<KotlinCompile> {
project.logger.warn("'kapt.generateStubs' is not used by the 'kotlin-kapt' plugin")
}
pluginOptions += SubpluginOption("aptOnly", "true")
pluginOptions += SubpluginOption("useLightAnalysis", "${kaptExtension.useLightAnalysis}")
if (project.hasProperty(VERBOSE_OPTION_NAME) && project.property(VERBOSE_OPTION_NAME) == "true") {