Kapt: Forbid using the deprecated (original) kapt
This commit is contained in:
+15
@@ -29,6 +29,21 @@ abstract class BaseGradleIT {
|
|||||||
workingDir.deleteRecursively()
|
workingDir.deleteRecursively()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Project.allowOriginalKapt() {
|
||||||
|
if (!projectDir.exists()) {
|
||||||
|
setupWorkingDir()
|
||||||
|
}
|
||||||
|
|
||||||
|
val allowOriginalKaptOption = "allow.original.kapt = true"
|
||||||
|
|
||||||
|
val gradleProperties = File(projectDir, "gradle.properties")
|
||||||
|
if (gradleProperties.exists()) {
|
||||||
|
gradleProperties.appendText("\n$allowOriginalKaptOption")
|
||||||
|
} else {
|
||||||
|
gradleProperties.writeText(allowOriginalKaptOption)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// https://developer.android.com/studio/intro/update.html#download-with-gradle
|
// https://developer.android.com/studio/intro/update.html#download-with-gradle
|
||||||
fun acceptAndroidSdkLicenses() = defaultBuildOptions().androidHome?.let {
|
fun acceptAndroidSdkLicenses() = defaultBuildOptions().androidHome?.let {
|
||||||
val sdkLicenses = File(it, "licenses")
|
val sdkLicenses = File(it, "licenses")
|
||||||
|
|||||||
+21
-4
@@ -15,6 +15,7 @@ class KaptIT: BaseGradleIT() {
|
|||||||
@Test
|
@Test
|
||||||
fun testSimple() {
|
fun testSimple() {
|
||||||
val project = Project("kaptSimple", GRADLE_VERSION)
|
val project = Project("kaptSimple", GRADLE_VERSION)
|
||||||
|
project.allowOriginalKapt()
|
||||||
|
|
||||||
project.build("build") {
|
project.build("build") {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
@@ -43,6 +44,7 @@ class KaptIT: BaseGradleIT() {
|
|||||||
@Test
|
@Test
|
||||||
fun testEnumConstructor() {
|
fun testEnumConstructor() {
|
||||||
val project = Project("kaptEnumConstructor", GRADLE_VERSION)
|
val project = Project("kaptEnumConstructor", GRADLE_VERSION)
|
||||||
|
project.allowOriginalKapt()
|
||||||
|
|
||||||
project.build("build") {
|
project.build("build") {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
@@ -59,6 +61,7 @@ class KaptIT: BaseGradleIT() {
|
|||||||
@Test
|
@Test
|
||||||
fun testStubs() {
|
fun testStubs() {
|
||||||
val project = Project("kaptStubs", GRADLE_VERSION)
|
val project = Project("kaptStubs", GRADLE_VERSION)
|
||||||
|
project.allowOriginalKapt()
|
||||||
|
|
||||||
project.build("build") {
|
project.build("build") {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
@@ -84,7 +87,7 @@ class KaptIT: BaseGradleIT() {
|
|||||||
@Test
|
@Test
|
||||||
fun testStubsWithoutJava() {
|
fun testStubsWithoutJava() {
|
||||||
val project = Project("kaptStubs", GRADLE_VERSION)
|
val project = Project("kaptStubs", GRADLE_VERSION)
|
||||||
project.setupWorkingDir()
|
project.allowOriginalKapt()
|
||||||
project.projectDir.allJavaFiles().forEach { it.delete() }
|
project.projectDir.allJavaFiles().forEach { it.delete() }
|
||||||
|
|
||||||
project.build("build") {
|
project.build("build") {
|
||||||
@@ -110,6 +113,7 @@ class KaptIT: BaseGradleIT() {
|
|||||||
private fun doTestIncrementalBuild(projectName: String, compileTasks: Array<String>) {
|
private fun doTestIncrementalBuild(projectName: String, compileTasks: Array<String>) {
|
||||||
val compileTasksUpToDate = compileTasks.map { it + " UP-TO-DATE" }.toTypedArray()
|
val compileTasksUpToDate = compileTasks.map { it + " UP-TO-DATE" }.toTypedArray()
|
||||||
val project = Project(projectName, "2.10")
|
val project = Project(projectName, "2.10")
|
||||||
|
project.allowOriginalKapt()
|
||||||
|
|
||||||
project.build("build") {
|
project.build("build") {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
@@ -145,7 +149,10 @@ class KaptIT: BaseGradleIT() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testArguments() {
|
fun testArguments() {
|
||||||
Project("kaptArguments", GRADLE_VERSION).build("build") {
|
val project = Project("kaptArguments", GRADLE_VERSION)
|
||||||
|
project.allowOriginalKapt()
|
||||||
|
|
||||||
|
project.build("build") {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
assertContains("kapt: Using class file stubs")
|
assertContains("kapt: Using class file stubs")
|
||||||
assertContains(":compileKotlin")
|
assertContains(":compileKotlin")
|
||||||
@@ -159,7 +166,10 @@ class KaptIT: BaseGradleIT() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testInheritedAnnotations() {
|
fun testInheritedAnnotations() {
|
||||||
Project("kaptInheritedAnnotations", GRADLE_VERSION).build("build") {
|
val project = Project("kaptInheritedAnnotations", GRADLE_VERSION)
|
||||||
|
project.allowOriginalKapt()
|
||||||
|
|
||||||
|
project.build("build") {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
assertFileExists("build/generated/source/kapt/main/example/TestClassGenerated.java")
|
assertFileExists("build/generated/source/kapt/main/example/TestClassGenerated.java")
|
||||||
assertFileExists("build/generated/source/kapt/main/example/AncestorClassGenerated.java")
|
assertFileExists("build/generated/source/kapt/main/example/AncestorClassGenerated.java")
|
||||||
@@ -170,7 +180,10 @@ class KaptIT: BaseGradleIT() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testOutputKotlinCode() {
|
fun testOutputKotlinCode() {
|
||||||
Project("kaptOutputKotlinCode", GRADLE_VERSION).build("build") {
|
val project = Project("kaptOutputKotlinCode", GRADLE_VERSION)
|
||||||
|
project.allowOriginalKapt()
|
||||||
|
|
||||||
|
project.build("build") {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
assertContains("kapt: Using class file stubs")
|
assertContains("kapt: Using class file stubs")
|
||||||
assertContains(":compileKotlin")
|
assertContains(":compileKotlin")
|
||||||
@@ -186,7 +199,9 @@ class KaptIT: BaseGradleIT() {
|
|||||||
@Test
|
@Test
|
||||||
fun testInternalUserIsModifiedStubsIC() {
|
fun testInternalUserIsModifiedStubsIC() {
|
||||||
val options = defaultBuildOptions().copy(incremental = true)
|
val options = defaultBuildOptions().copy(incremental = true)
|
||||||
|
|
||||||
val project = Project("kaptStubs", GRADLE_VERSION)
|
val project = Project("kaptStubs", GRADLE_VERSION)
|
||||||
|
project.allowOriginalKapt()
|
||||||
|
|
||||||
project.build("build", options = options) {
|
project.build("build", options = options) {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
@@ -206,7 +221,9 @@ class KaptIT: BaseGradleIT() {
|
|||||||
@Test
|
@Test
|
||||||
fun testKotlinCompilerNotCalledStubsIC() {
|
fun testKotlinCompilerNotCalledStubsIC() {
|
||||||
val options = defaultBuildOptions().copy(incremental = true)
|
val options = defaultBuildOptions().copy(incremental = true)
|
||||||
|
|
||||||
val project = Project("kaptStubs", GRADLE_VERSION)
|
val project = Project("kaptStubs", GRADLE_VERSION)
|
||||||
|
project.allowOriginalKapt()
|
||||||
|
|
||||||
project.build("build", options = options) {
|
project.build("build", options = options) {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
|
|||||||
+1
@@ -37,6 +37,7 @@ abstract class KaptIncrementalBaseIT(val shouldUseStubs: Boolean, val useKapt3:
|
|||||||
|
|
||||||
if (useKapt3) {
|
if (useKapt3) {
|
||||||
buildGradle.modify { it.replace(APPLY_KAPT3_PLUGIN_PLACEHOLDER, APPLY_KAPT3_PLUGIN) }
|
buildGradle.modify { it.replace(APPLY_KAPT3_PLUGIN_PLACEHOLDER, APPLY_KAPT3_PLUGIN) }
|
||||||
|
allowOriginalKapt()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-4
@@ -13,6 +13,7 @@ buildscript {
|
|||||||
|
|
||||||
apply plugin: 'com.android.application'
|
apply plugin: 'com.android.application'
|
||||||
apply plugin: 'kotlin-android'
|
apply plugin: 'kotlin-android'
|
||||||
|
apply plugin: 'kotlin-kapt'
|
||||||
apply plugin: 'kotlin-android-extensions'
|
apply plugin: 'kotlin-android-extensions'
|
||||||
|
|
||||||
android {
|
android {
|
||||||
@@ -48,10 +49,6 @@ dependencies {
|
|||||||
provided 'org.glassfish:javax.annotation:10.0-b28'
|
provided 'org.glassfish:javax.annotation:10.0-b28'
|
||||||
}
|
}
|
||||||
|
|
||||||
kapt {
|
|
||||||
generateStubs = true
|
|
||||||
}
|
|
||||||
|
|
||||||
androidExtensions {
|
androidExtensions {
|
||||||
experimental = true
|
experimental = true
|
||||||
}
|
}
|
||||||
+1
-4
@@ -1,5 +1,6 @@
|
|||||||
apply plugin: 'com.android.application'
|
apply plugin: 'com.android.application'
|
||||||
apply plugin: 'kotlin-android'
|
apply plugin: 'kotlin-android'
|
||||||
|
apply plugin: 'kotlin-kapt'
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
compile "frankiesardo:icepick:3.2.0"
|
compile "frankiesardo:icepick:3.2.0"
|
||||||
@@ -38,8 +39,4 @@ repositories {
|
|||||||
}
|
}
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
maven { url 'https://maven.google.com' }
|
maven { url 'https://maven.google.com' }
|
||||||
}
|
|
||||||
|
|
||||||
kapt {
|
|
||||||
generateStubs = true
|
|
||||||
}
|
}
|
||||||
-4
@@ -21,8 +21,4 @@ dependencies {
|
|||||||
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
compile "org.jetbrains.kotlin:annotation-processor-example:$kotlin_version"
|
compile "org.jetbrains.kotlin:annotation-processor-example:$kotlin_version"
|
||||||
kapt "org.jetbrains.kotlin:annotation-processor-example:$kotlin_version"
|
kapt "org.jetbrains.kotlin:annotation-processor-example:$kotlin_version"
|
||||||
}
|
|
||||||
|
|
||||||
kapt {
|
|
||||||
generateStubs = true
|
|
||||||
}
|
}
|
||||||
-1
@@ -23,7 +23,6 @@ dependencies {
|
|||||||
}
|
}
|
||||||
|
|
||||||
kapt {
|
kapt {
|
||||||
generateStubs = true
|
|
||||||
arguments {
|
arguments {
|
||||||
arg("suffix", "Customized")
|
arg("suffix", "Customized")
|
||||||
arg("generate.kotlin.code", "true")
|
arg("generate.kotlin.code", "true")
|
||||||
|
|||||||
+14
-2
@@ -17,6 +17,7 @@
|
|||||||
package org.jetbrains.kotlin.gradle.internal
|
package org.jetbrains.kotlin.gradle.internal
|
||||||
|
|
||||||
import com.android.build.gradle.BaseExtension
|
import com.android.build.gradle.BaseExtension
|
||||||
|
import org.gradle.api.GradleException
|
||||||
import org.gradle.api.Project
|
import org.gradle.api.Project
|
||||||
import org.gradle.api.UnknownDomainObjectException
|
import org.gradle.api.UnknownDomainObjectException
|
||||||
import org.gradle.api.file.FileCollection
|
import org.gradle.api.file.FileCollection
|
||||||
@@ -172,13 +173,24 @@ class AnnotationProcessingManager(
|
|||||||
|
|
||||||
val kaptProcessorPath get() = setOf(wrappersDirectory) + aptFiles + javaTask.classpath
|
val kaptProcessorPath get() = setOf(wrappersDirectory) + aptFiles + javaTask.classpath
|
||||||
|
|
||||||
|
private fun allowToUseOriginalKapt(): Boolean {
|
||||||
|
return project.hasProperty("allow.original.kapt")
|
||||||
|
&& project.property("allow.original.kapt").toString().toBoolean()
|
||||||
|
}
|
||||||
|
|
||||||
fun setupKapt() {
|
fun setupKapt() {
|
||||||
originalJavaCompilerArgs = javaTask.options.compilerArgs
|
originalJavaCompilerArgs = javaTask.options.compilerArgs
|
||||||
|
|
||||||
if (aptFiles.isEmpty()) return
|
if (aptFiles.isEmpty()) return
|
||||||
|
|
||||||
project.logger.warn("${project.name}: " +
|
val deprecationMessage = "${project.name}: " +
|
||||||
"Original kapt is deprecated. Please add \"apply plugin: 'kotlin-kapt'\" to your build.gradle.")
|
"Original kapt is deprecated. Please add \"apply plugin: 'kotlin-kapt'\" to your build.gradle."
|
||||||
|
|
||||||
|
if (allowToUseOriginalKapt()) {
|
||||||
|
project.logger.warn(deprecationMessage)
|
||||||
|
} else {
|
||||||
|
throw GradleException(deprecationMessage)
|
||||||
|
}
|
||||||
|
|
||||||
if (project.plugins.findPlugin(ANDROID_APT_PLUGIN_ID) != null) {
|
if (project.plugins.findPlugin(ANDROID_APT_PLUGIN_ID) != null) {
|
||||||
project.logger.warn("Please do not use `$ANDROID_APT_PLUGIN_ID` with kapt.")
|
project.logger.warn("Please do not use `$ANDROID_APT_PLUGIN_ID` with kapt.")
|
||||||
|
|||||||
Reference in New Issue
Block a user