Set minimal supported AGP version to 3.6.4

^KT-51342 Fixed
This commit is contained in:
Yahor Berdnikau
2022-03-31 23:23:40 +02:00
committed by Space
parent 785831c82a
commit bc066e1863
21 changed files with 418 additions and 296 deletions
@@ -7,5 +7,5 @@ dependencies {
api(project(":native:kotlin-native-utils"))
api(project(":kotlin-project-model"))
implementation(project(":kotlin-tooling-core"))
compileOnly("com.android.tools.build:gradle:3.4.0")
compileOnly("com.android.tools.build:gradle:3.6.4")
}
@@ -97,7 +97,7 @@ fun Test.includeTestsWithPattern(include: Boolean, patterns: (MutableSet<String>
}
fun Test.advanceGradleVersion() {
val gradleVersionForTests = "7.0"
val gradleVersionForTests = "7.0.2"
systemProperty("kotlin.gradle.version.for.tests", gradleVersionForTests)
}
@@ -4,6 +4,7 @@ import org.gradle.api.logging.LogLevel
import org.gradle.api.logging.configuration.WarningMode
import org.gradle.util.GradleVersion
import org.jetbrains.kotlin.gradle.internal.ensureParentDirsCreated
import org.jetbrains.kotlin.gradle.testbase.TestVersions
import org.jetbrains.kotlin.gradle.tooling.BuildKotlinToolingMetadataTask
import org.jetbrains.kotlin.gradle.util.*
import org.jetbrains.kotlin.test.util.KtTestUtil
@@ -16,10 +17,160 @@ import kotlin.test.assertNotNull
import kotlin.test.assertNull
import kotlin.test.assertTrue
open class KotlinAndroid36GradleIT : KotlinAndroid34GradleIT() {
open class KotlinAndroid36GradleIT : KotlinAndroid3GradleIT() {
override val androidGradlePluginVersion: AGPVersion
get() = AGPVersion.v3_6_0
// AGP 3.+ is not working well with Gradle 7+
override val defaultGradleVersion: GradleVersionRequired
get() = GradleVersionRequired.Until(TestVersions.Gradle.G_6_9)
@Test
fun testKaptUsingApOptionProvidersAsNestedInputOutput() = with(Project("AndroidProject")) {
setupWorkingDir()
gradleBuildScript(subproject = "Android").appendText(
"""
apply plugin: 'kotlin-kapt'
class MyNested implements org.gradle.process.CommandLineArgumentProvider {
@InputFile
File inputFile = null
@Override
Iterable<String> asArguments() {
// Read the arguments from a file, because changing them in a build script is treated as an
// implementation change by Gradle:
return [new File('args.txt').text]
}
}
def nested = new MyNested()
nested.inputFile = file("${'$'}projectDir/in.txt")
android.applicationVariants.all {
it.javaCompileOptions.annotationProcessorOptions.compilerArgumentProviders.add(nested)
}
""".trimIndent()
)
File(projectDir, "Android/in.txt").appendText("1234")
File(projectDir, "args.txt").appendText("1234")
val kaptTasks = listOf(":Android:kaptFlavor1DebugKotlin")
val javacTasks = listOf(":Android:compileFlavor1DebugJavaWithJavac")
val buildTasks = (kaptTasks + javacTasks).toTypedArray()
build(*buildTasks) {
assertSuccessful()
assertTasksExecuted(kaptTasks + javacTasks)
}
File(projectDir, "Android/in.txt").appendText("5678")
build(*buildTasks) {
assertSuccessful()
assertTasksExecuted(kaptTasks)
assertTasksUpToDate(javacTasks)
}
// Changing only the annotation provider arguments should not trigger the tasks to run, as the arguments may be outputs,
// internals or neither:
File(projectDir, "args.txt").appendText("5678")
build(*buildTasks) {
assertSuccessful()
assertTasksUpToDate(javacTasks + kaptTasks)
}
}
@Test
fun testAgpNestedArgsNotEvaluatedDuringConfiguration() = with(Project("AndroidProject")) {
setupWorkingDir()
gradleBuildScript(subproject = "Android").appendText(
"""
apply plugin: 'kotlin-kapt'
class MyNested implements org.gradle.process.CommandLineArgumentProvider {
@Override
Iterable<String> asArguments() {
throw new RuntimeException("This should not be invoked during configuration.")
}
}
def nested = new MyNested()
android.applicationVariants.all {
it.javaCompileOptions.annotationProcessorOptions.compilerArgumentProviders.add(nested)
}
""".trimIndent()
)
build(":Android:kaptFlavor1DebugKotlin", "--dry-run") {
assertSuccessful()
}
build(
":Android:kaptFlavor1DebugKotlin", "--dry-run",
options = defaultBuildOptions().copy(kaptOptions = KaptOptions(verbose = false, useWorkers = false))
) {
assertSuccessful()
}
}
@Test
fun testOmittedStdlibVersion() = Project("AndroidProject").run {
setupWorkingDir()
gradleBuildScript("Lib").modify {
it.checkedReplace(
"kotlin-stdlib:\$kotlin_version",
"kotlin-stdlib"
) + "\n" +
"""
apply plugin: 'maven-publish'
android {
defaultPublishConfig 'flavor1Debug'
}
afterEvaluate {
publishing {
publications {
flavorDebug(MavenPublication) {
from components.flavor1Debug
group = 'com.example'
artifactId = 'flavor1Debug'
version = '1.0'
}
}
repositories {
maven {
url = "file://${'$'}buildDir/repo"
}
}
}
}
""".trimIndent()
}
build(":Lib:assembleFlavor1Debug", ":Lib:publish") {
assertSuccessful()
assertTasksExecuted(":Lib:compileFlavor1DebugKotlin", ":Lib:publishFlavorDebugPublicationToMavenRepository")
val pomLines = File(projectDir, "Lib/build/repo/com/example/flavor1Debug/1.0/flavor1Debug-1.0.pom").readLines()
val stdlibVersionLineNumber = pomLines.indexOfFirst { "<artifactId>kotlin-stdlib</artifactId>" in it } + 1
val versionLine = pomLines[stdlibVersionLineNumber]
assertTrue { "<version>${defaultBuildOptions().kotlinVersion}</version>" in versionLine }
}
}
@Test
fun testAndroidMppSourceSets(): Unit = with(
Project("new-mpp-android-source-sets")
@@ -473,7 +624,7 @@ open class KotlinAndroid70GradleIT : KotlinAndroid36GradleIT() {
get() = AGPVersion.v7_0_0
override val defaultGradleVersion: GradleVersionRequired
get() = GradleVersionRequired.AtLeast("7.0")
get() = GradleVersionRequired.AtLeast(TestVersions.Gradle.G_7_0)
override fun defaultBuildOptions(): BuildOptions {
val javaHome = File(System.getProperty("jdk11Home") ?: error("jdk11Home not specified"))
@@ -603,194 +754,7 @@ open class KotlinAndroid71GradleIT : KotlinAndroid70GradleIT() {
}
}
open class KotlinAndroid34GradleIT : KotlinAndroid3GradleIT() {
override val androidGradlePluginVersion: AGPVersion
get() = AGPVersion.v3_4_1
// AGP 3.4.1 is not working with Gradle 7+
override val defaultGradleVersion: GradleVersionRequired
get() = GradleVersionRequired.Until("6.8.4")
@Test
fun testKaptUsingApOptionProvidersAsNestedInputOutput() = with(Project("AndroidProject")) {
setupWorkingDir()
gradleBuildScript(subproject = "Android").appendText(
"""
apply plugin: 'kotlin-kapt'
class MyNested implements org.gradle.process.CommandLineArgumentProvider {
@InputFile
File inputFile = null
@Override
Iterable<String> asArguments() {
// Read the arguments from a file, because changing them in a build script is treated as an
// implementation change by Gradle:
return [new File('args.txt').text]
}
}
def nested = new MyNested()
nested.inputFile = file("${'$'}projectDir/in.txt")
android.applicationVariants.all {
it.javaCompileOptions.annotationProcessorOptions.compilerArgumentProviders.add(nested)
}
""".trimIndent()
)
File(projectDir, "Android/in.txt").appendText("1234")
File(projectDir, "args.txt").appendText("1234")
val kaptTasks = listOf(":Android:kaptFlavor1DebugKotlin")
val javacTasks = listOf(":Android:compileFlavor1DebugJavaWithJavac")
val buildTasks = (kaptTasks + javacTasks).toTypedArray()
build(*buildTasks) {
assertSuccessful()
assertTasksExecuted(kaptTasks + javacTasks)
}
File(projectDir, "Android/in.txt").appendText("5678")
build(*buildTasks) {
assertSuccessful()
assertTasksExecuted(kaptTasks)
assertTasksUpToDate(javacTasks)
}
// Changing only the annotation provider arguments should not trigger the tasks to run, as the arguments may be outputs,
// internals or neither:
File(projectDir, "args.txt").appendText("5678")
build(*buildTasks) {
assertSuccessful()
assertTasksUpToDate(javacTasks + kaptTasks)
}
}
@Test
fun testAgpNestedArgsNotEvaluatedDuringConfiguration() = with(Project("AndroidProject")) {
setupWorkingDir()
gradleBuildScript(subproject = "Android").appendText(
"""
apply plugin: 'kotlin-kapt'
class MyNested implements org.gradle.process.CommandLineArgumentProvider {
@Override
Iterable<String> asArguments() {
throw new RuntimeException("This should not be invoked during configuration.")
}
}
def nested = new MyNested()
android.applicationVariants.all {
it.javaCompileOptions.annotationProcessorOptions.compilerArgumentProviders.add(nested)
}
""".trimIndent()
)
build(":Android:kaptFlavor1DebugKotlin", "--dry-run") {
assertSuccessful()
}
build(
":Android:kaptFlavor1DebugKotlin", "--dry-run",
options = defaultBuildOptions().copy(kaptOptions = KaptOptions(verbose = false, useWorkers = false))
) {
assertSuccessful()
}
}
@Test
fun testOmittedStdlibVersion() = Project("AndroidProject").run {
setupWorkingDir()
gradleBuildScript("Lib").modify {
it.checkedReplace(
"kotlin-stdlib:\$kotlin_version",
"kotlin-stdlib"
) + "\n" +
"""
apply plugin: 'maven-publish'
android {
defaultPublishConfig 'flavor1Debug'
}
afterEvaluate {
publishing {
publications {
flavorDebug(MavenPublication) {
from components.flavor1Debug
group = 'com.example'
artifactId = 'flavor1Debug'
version = '1.0'
}
}
repositories {
maven {
url = "file://${'$'}buildDir/repo"
}
}
}
}
""".trimIndent()
}
build(":Lib:assembleFlavor1Debug", ":Lib:publish") {
assertSuccessful()
assertTasksExecuted(":Lib:compileFlavor1DebugKotlin", ":Lib:publishFlavorDebugPublicationToMavenRepository")
val pomLines = File(projectDir, "Lib/build/repo/com/example/flavor1Debug/1.0/flavor1Debug-1.0.pom").readLines()
val stdlibVersionLineNumber = pomLines.indexOfFirst { "<artifactId>kotlin-stdlib</artifactId>" in it } + 1
val versionLine = pomLines[stdlibVersionLineNumber]
assertTrue { "<version>${defaultBuildOptions().kotlinVersion}</version>" in versionLine }
}
}
}
abstract class KotlinAndroid3GradleIT : AbstractKotlinAndroidGradleTests() {
@Test
fun testApplyWithFeaturePlugin() {
Assume.assumeTrue(
"The com.android.feature plugin has been deprecated and removed in newer versions",
androidGradlePluginVersion < AGPVersion.v3_6_0
)
val project = Project("AndroidProject")
project.setupWorkingDir()
File(project.projectDir, "Lib/build.gradle").modify { text ->
// Change the applied plugin to com.android.feature
text.replace("com.android.library", "com.android.feature")
.replace("compileSdkVersion 22", "compileSdkVersion 26")
.apply { assert(!equals(text)) }
.plus("\nandroid { baseFeature true }")
}
// Check that Kotlin tasks were created for both lib and feature variants:
val kotlinTaskNames =
listOf("Debug").flatMap { buildType ->
listOf("Flavor1", "Flavor2").flatMap { flavor ->
listOf("", "Feature").map { isFeature -> ":Lib:compile$flavor$buildType${isFeature}Kotlin" }
}
}
project.build(":Lib:assembleDebug") {
assertSuccessful()
assertTasksExecuted(*kotlinTaskNames.toTypedArray())
}
}
@Test
fun testAfterEvaluateOrdering() = with(Project("AndroidProject")) {
setupWorkingDir()
@@ -1100,37 +1064,6 @@ fun getSomething() = 10
}
}
@Test
fun testAndroidExtensionsIncremental() {
Assume.assumeTrue(
"Ignored for newer AGP versions because of KT-38622",
androidGradlePluginVersion < AGPVersion.v3_6_0
)
val project = Project("AndroidExtensionsProject")
val options = defaultBuildOptions().copy(incremental = true)
project.build("assembleDebug", options = options) {
assertSuccessful()
val affectedSources = project.projectDir.getFilesByNames(
"MyActivity.kt", "noLayoutUsages.kt"
)
val relativePaths = project.relativize(affectedSources)
assertCompiledKotlinSources(relativePaths)
}
val activityLayout = File(project.projectDir, "app/src/main/res/layout/activity_main.xml")
activityLayout.modify { it.replace("textView", "newTextView") }
project.build("assembleDebug", options = options) {
assertFailed()
val affectedSources = project.projectDir.getFilesByNames("MyActivity.kt")
val relativePaths = project.relativize(affectedSources)
assertCompiledKotlinSources(relativePaths)
}
}
@Test
fun testAndroidExtensionsManyVariants() {
val project = Project("AndroidExtensionsManyVariants")
@@ -7,6 +7,7 @@
package org.jetbrains.kotlin.gradle
import org.jetbrains.kotlin.gradle.ResolvedVariantChecker.ResolvedVariantRequest
import org.jetbrains.kotlin.gradle.testbase.TestVersions
import org.jetbrains.kotlin.gradle.util.AGPVersion
import org.jetbrains.kotlin.gradle.util.checkedReplace
import org.jetbrains.kotlin.gradle.util.modify
@@ -22,12 +23,16 @@ import java.lang.Boolean as RefBoolean
class AndroidAndJavaConsumeMppLibBuiltByGradle69IT : AndroidAndJavaConsumeMppLibIT() {
override val producerAgpVersion: AGPVersion = AGPVersion.v4_2_0
override val producerGradleVersion: GradleVersionRequired = GradleVersionRequired.Exact("6.9")
override val producerGradleVersion: GradleVersionRequired = GradleVersionRequired.Exact(
TestVersions.Gradle.G_6_9
)
}
class AndroidAndJavaConsumeMppLibBuiltByGradle7IT : AndroidAndJavaConsumeMppLibIT() {
override val producerAgpVersion: AGPVersion = AGPVersion.v7_0_0
override val producerGradleVersion: GradleVersionRequired = GradleVersionRequired.AtLeast("7.0")
override val producerGradleVersion: GradleVersionRequired = GradleVersionRequired.AtLeast(
TestVersions.Gradle.G_7_0
)
}
@RunWith(Parameterized::class)
@@ -62,9 +67,9 @@ abstract class AndroidAndJavaConsumeMppLibIT : BaseGradleIT() {
@Parameterized.Parameters(name = "Consumer(AGP={3}, Gradle={4}), flavors={0}, debugOnly={1}, published={2}")
fun testCases(): List<Array<Any>> {
val consumers = listOf(
AGPVersion.v4_2_0 to GradleVersionRequired.Exact("6.9"),
AGPVersion.v4_2_0 to GradleVersionRequired.AtLeast("7.0"),
AGPVersion.v7_0_0 to GradleVersionRequired.AtLeast("7.0"),
AGPVersion.v4_2_0 to GradleVersionRequired.Exact(TestVersions.Gradle.G_6_9),
AGPVersion.v4_2_0 to GradleVersionRequired.AtLeast(TestVersions.Gradle.G_7_0),
AGPVersion.v7_0_0 to GradleVersionRequired.AtLeast(TestVersions.Gradle.G_7_0),
)
val buildParams = listOf(
/* useFlavors, isAndroidPublishDebugOnly, isPublishedLibrary */
@@ -2,6 +2,7 @@ package org.jetbrains.kotlin.gradle
import org.gradle.api.logging.LogLevel
import org.gradle.api.logging.configuration.WarningMode
import org.jetbrains.kotlin.gradle.testbase.TestVersions
import org.jetbrains.kotlin.gradle.util.*
import org.jetbrains.kotlin.test.util.KtTestUtil
import org.junit.Assert
@@ -10,18 +11,18 @@ import org.junit.Ignore
import org.junit.Test
import java.io.File
class Kapt3WorkersAndroid34IT : Kapt3Android34IT() {
class Kapt3WorkersAndroid36IT : Kapt3Android36IT() {
override fun kaptOptions(): KaptOptions =
super.kaptOptions().copy(useWorkers = true)
}
open class Kapt3Android34IT : Kapt3AndroidIT() {
open class Kapt3Android36IT : Kapt3AndroidIT() {
override val androidGradlePluginVersion: AGPVersion
get() = AGPVersion.v3_4_1
get() = AGPVersion.v3_6_0
// AGP 3.4 is not working with Gradle 7+
// AGP 3.+ is not working with Gradle 7+
override val defaultGradleVersion: GradleVersionRequired
get() = GradleVersionRequired.Until("6.8.4")
get() = GradleVersionRequired.Until(TestVersions.Gradle.G_6_9)
@Test
fun testAndroidxNavigationSafeArgs() = with(Project("androidx-navigation-safe-args", directoryPrefix = "kapt2")) {
@@ -77,7 +78,7 @@ class Kapt3Android70IT : Kapt3AndroidIT() {
get() = AGPVersion.v7_0_0
override val defaultGradleVersion: GradleVersionRequired
get() = GradleVersionRequired.AtLeast("7.0")
get() = GradleVersionRequired.AtLeast(TestVersions.Gradle.G_7_0)
override fun defaultBuildOptions(): BuildOptions {
val javaHome = File(System.getProperty("jdk11Home")!!)
@@ -199,7 +200,7 @@ abstract class Kapt3AndroidIT : BaseGradleIT() {
assertFileExists("app/build/generated/source/kapt/debug/org/example/kotlin/butterknife/SimpleActivity\$\$ViewBinder.java")
val butterknifeJavaClassesDir =
"app/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/org/example/kotlin/butterknife/"
"app/build/intermediates/javac/debug/classes/org/example/kotlin/butterknife/"
assertFileExists(butterknifeJavaClassesDir + "SimpleActivity\$\$ViewBinder.class")
assertFileExists("app/build/tmp/kotlin-classes/debug/org/example/kotlin/butterknife/SimpleAdapter\$ViewHolder.class")
@@ -222,7 +223,7 @@ abstract class Kapt3AndroidIT : BaseGradleIT() {
assertFileExists("app/build/generated/source/kapt/debug/com/example/dagger/kotlin/ui/HomeActivity_MembersInjector.java")
val daggerJavaClassesDir =
"app/build/intermediates/javac/debug/compileDebugJavaWithJavac/classes/com/example/dagger/kotlin/"
"app/build/intermediates/javac/debug/classes/com/example/dagger/kotlin/"
assertFileExists(daggerJavaClassesDir + "DaggerApplicationComponent.class")
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.gradle.internals.KOTLIN_12X_MPP_DEPRECATION_WARNING
import org.jetbrains.kotlin.gradle.plugin.EXPECTED_BY_CONFIG_NAME
import org.jetbrains.kotlin.gradle.plugin.IMPLEMENT_CONFIG_NAME
import org.jetbrains.kotlin.gradle.plugin.IMPLEMENT_DEPRECATION_WARNING
import org.jetbrains.kotlin.gradle.testbase.TestVersions
import org.jetbrains.kotlin.gradle.util.AGPVersion
import org.jetbrains.kotlin.gradle.util.getFileByName
import org.jetbrains.kotlin.gradle.util.modify
@@ -318,7 +319,7 @@ class MultiplatformGradleIT : BaseGradleIT() {
fun testWithJavaDuplicatedResourcesFail() = with(
Project(
projectName = "mpp-single-jvm-target",
gradleVersionRequirement = GradleVersionRequired.AtLeast("7.0"),
gradleVersionRequirement = GradleVersionRequired.AtLeast(TestVersions.Gradle.G_7_0),
minLogLevel = LogLevel.WARN
)
) {
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.gradle.plugin.mpp.UnusedSourceSetsChecker
import org.jetbrains.kotlin.gradle.plugin.sources.METADATA_CONFIGURATION_NAME_SUFFIX
import org.jetbrains.kotlin.gradle.plugin.sources.UnsatisfiedSourceSetVisibilityException
import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
import org.jetbrains.kotlin.gradle.testbase.TestVersions
import org.jetbrains.kotlin.gradle.util.*
import org.jetbrains.kotlin.konan.target.HostManager
import org.jetbrains.kotlin.library.KLIB_PROPERTY_SHORT_NAME
@@ -1926,7 +1927,7 @@ class NewMultiplatformIT : BaseGradleIT() {
"new-mpp-wasm-js",
// TODO: this test fails with deprecation error on Gradle <7.0
// Should be fixed via planned fixes in Kotlin/JS plugin: https://youtrack.jetbrains.com/issue/KFC-252
gradleVersionRequirement = GradleVersionRequired.AtLeast("7.0")
gradleVersionRequirement = GradleVersionRequired.AtLeast(TestVersions.Gradle.G_7_0)
)) {
setupWorkingDir()
gradleBuildScript().modify(::transformBuildScriptWithPluginsDsl)
@@ -11,7 +11,7 @@ interface TestVersions {
object Gradle {
const val G_6_7 = "6.7.1"
const val G_6_8 = "6.8.3"
const val G_6_9 = "6.9.1"
const val G_6_9 = "6.9.2"
const val G_7_0 = "7.0.2"
const val G_7_1 = "7.1.1"
const val G_7_2 = "7.2"
@@ -18,13 +18,12 @@ class AGPVersion private constructor(private val versionNumber: VersionNumber) {
fun fromString(versionString: String): AGPVersion =
AGPVersion(VersionNumber.parse(versionString))
val v3_4_1 = fromString("3.4.3")
val v3_6_0 = fromString("3.6.4")
val v4_1_0 = fromString("4.1.3")
val v4_2_0 = fromString("4.2.0")
val v7_0_0 = fromString("7.0.0-beta02")
val v7_1_0 = fromString("7.1.0-beta03")
val v4_2_0 = fromString("4.2.2")
val v7_0_0 = fromString("7.0.4")
val v7_1_0 = fromString("7.1.2")
val testedVersions = listOf(v3_4_1, v3_6_0, v4_1_0, v4_2_0, v7_0_0, v7_1_0)
val testedVersions = listOf(v3_6_0, v4_1_0, v4_2_0, v7_0_0, v7_1_0)
}
}
@@ -1,9 +1,8 @@
buildscript {
repositories {
mavenLocal()
maven { url 'https://maven.google.com' }
google()
mavenCentral()
maven { url = uri("https://jcenter.bintray.com/") }
}
dependencies {
@@ -19,7 +18,6 @@ apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 23
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.dagger.kotlin"
@@ -29,6 +27,12 @@ android {
versionName "1.0"
buildConfigField "long", "BUILD_TIME_MILLIS", "${System.currentTimeMillis()}L"
}
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
@@ -36,17 +40,14 @@ android {
repositories {
mavenLocal()
maven { url 'https://maven.google.com' }
google()
mavenCentral()
maven { url = uri("https://jcenter.bintray.com/") }
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:23.1.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'com.google.dagger:dagger:2.0.1'
kapt 'com.google.dagger:dagger-compiler:2.0'
implementation 'com.google.dagger:dagger:2.9'
kapt 'com.google.dagger:dagger-compiler:2.9'
compileOnly 'org.glassfish:javax.annotation:10.0-b28'
}
@@ -4,7 +4,6 @@ apply plugin: 'kotlin-kapt'
android {
compileSdkVersion 23
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "org.example.kotlin.butterknife"
@@ -32,10 +31,7 @@ android {
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:23.3.0'
implementation 'com.jakewharton:butterknife:8.0.1'
kapt 'com.jakewharton:butterknife-compiler:8.0.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
@@ -1,7 +1,7 @@
buildscript {
repositories {
mavenLocal()
maven { url 'https://maven.google.com' }
google()
mavenCentral()
}
dependencies {
@@ -13,7 +13,7 @@ buildscript {
allprojects {
repositories {
mavenLocal()
maven { url 'https://maven.google.com' }
google()
mavenCentral()
}
}
@@ -5,7 +5,6 @@ apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 23
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.dagger.kotlin"
@@ -14,6 +13,12 @@ android {
versionCode 1
versionName "1.0"
}
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
buildTypes {
release {
minifyEnabled false
@@ -28,9 +33,8 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:23.3.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'com.google.dagger:dagger:2.6.1'
kapt 'com.google.dagger:dagger-compiler:2.6.1'
implementation 'com.google.dagger:dagger:2.9'
kapt 'com.google.dagger:dagger-compiler:2.9'
compileOnly 'org.glassfish:javax.annotation:10.0-b28'
}
@@ -1,9 +1,8 @@
buildscript {
repositories {
mavenLocal()
maven { url 'https://maven.google.com' }
google()
mavenCentral()
maven { url = uri("https://jcenter.bintray.com/") }
}
dependencies {
classpath "com.android.tools.build:gradle:$android_tools_version"
@@ -14,8 +13,7 @@ buildscript {
allprojects {
repositories {
mavenLocal()
maven { url 'https://maven.google.com' }
google()
mavenCentral()
maven { url = uri("https://jcenter.bintray.com/") }
}
}
@@ -63,10 +63,10 @@ dependencies {
exclude(group = "*")
}
compileOnly("com.android.tools.build:gradle:3.4.0")
compileOnly("com.android.tools.build:gradle-api:3.4.0")
compileOnly("com.android.tools.build:builder:3.4.0")
compileOnly("com.android.tools.build:builder-model:3.4.0")
compileOnly("com.android.tools.build:gradle:3.6.4")
compileOnly("com.android.tools.build:gradle-api:3.6.4")
compileOnly("com.android.tools.build:builder:3.6.4")
compileOnly("com.android.tools.build:builder-model:3.6.4")
compileOnly("org.codehaus.groovy:groovy-all:2.4.12")
compileOnly(project(":kotlin-reflect"))
compileOnly(intellijCore())
@@ -85,11 +85,6 @@ dependencies {
embedded(commonDependency("com.google.guava:guava")) { isTransitive = false }
embedded(commonDependency("org.jetbrains.teamcity:serviceMessages")) { isTransitive = false }
// com.android.tools.build:gradle has ~50 unneeded transitive dependencies
compileOnly("com.android.tools.build:gradle:3.0.0") { isTransitive = false }
compileOnly("com.android.tools.build:gradle-core:3.0.0") { isTransitive = false }
compileOnly("com.android.tools.build:builder-model:3.0.0") { isTransitive = false }
if (!kotlinBuildProperties.isInJpsBuildIdeaSync) {
"functionalTestImplementation"("com.android.tools.build:gradle:4.0.1") {
because("Functional tests are using APIs from Android. Latest Version is used to avoid NoClassDefFoundError")
@@ -389,9 +389,9 @@ class Kapt3GradleSubplugin @Inject internal constructor(private val registry: To
val subluginOptionsFromProvidedApOptions = lazy {
val apOptionsFromProviders =
annotationProcessorProviders?.flatMap {
(it as CommandLineArgumentProvider).asArguments()
}.orEmpty()
annotationProcessorProviders
?.flatMap { it.asArguments() }
.orEmpty()
apOptionsFromProviders.map {
// Use the internal subplugin option type to exclude them from Gradle input/output checks, as their providers are already
@@ -829,14 +829,8 @@ internal fun checkAndroidAnnotationProcessorDependencyUsage(project: Project) {
private val BaseVariant.annotationProcessorOptions: Map<String, String>?
get() = javaCompileOptions.annotationProcessorOptions.arguments
private val BaseVariant.annotationProcessorOptionProviders: List<*>
get() = try {
// Public API added in Android Gradle Plugin 3.2.0-alpha15:
val apOptions = javaCompileOptions.annotationProcessorOptions
apOptions.javaClass.getMethod("getCompilerArgumentProviders").invoke(apOptions) as List<*>
} catch (e: NoSuchMethodException) {
emptyList<Any>()
}
private val BaseVariant.annotationProcessorOptionProviders: List<CommandLineArgumentProvider>
get() = javaCompileOptions.annotationProcessorOptions.compilerArgumentProviders
//TODO once the Android plugin reaches its 3.0.0 release, consider compiling against it (remove the reflective call)
private val BaseVariant.dataBindingDependencyArtifactsIfSupported: FileCollection?
@@ -741,13 +741,16 @@ internal open class KotlinAndroidPlugin(
}
companion object {
const val MINIMAL_SUPPORTED_AGP_VERSION = "3.6.4"
fun androidTargetHandler(): AbstractAndroidProjectHandler {
val tasksProvider = AndroidTasksProvider()
if (androidPluginVersion != null) {
val minimalVersion = "3.0.0"
if (compareVersionNumbers(androidPluginVersion, minimalVersion) < 0) {
throw IllegalStateException("Kotlin: Unsupported version of com.android.tools.build:gradle plugin: version $minimalVersion or higher should be used with kotlin-android plugin")
if (compareVersionNumbers(androidPluginVersion, MINIMAL_SUPPORTED_AGP_VERSION) < 0) {
throw IllegalStateException(
"Kotlin: Unsupported version of com.android.tools.build:gradle plugin: " +
"version $MINIMAL_SUPPORTED_AGP_VERSION or higher should be used with kotlin-android plugin"
)
}
}
@@ -812,7 +815,7 @@ abstract class AbstractAndroidProjectHandler(private val kotlinConfigurationTool
protected abstract fun wireKotlinTasks(
project: Project,
compilation: KotlinJvmAndroidCompilation,
androidPlugin: BasePlugin<*>,
androidPlugin: BasePlugin,
androidExt: BaseExtension,
variantData: BaseVariant,
javaTask: TaskProvider<out AbstractCompile>,
@@ -841,7 +844,7 @@ abstract class AbstractAndroidProjectHandler(private val kotlinConfigurationTool
val plugin = androidPluginIds
.asSequence()
.mapNotNull { project.plugins.findPlugin(it) as? BasePlugin<*> }
.mapNotNull { project.plugins.findPlugin(it) as? BasePlugin }
.firstOrNull()
?: throw InvalidPluginException("'kotlin-android' expects one of the Android Gradle " +
"plugins to be applied to the project:\n\t" +
@@ -1035,7 +1038,7 @@ abstract class AbstractAndroidProjectHandler(private val kotlinConfigurationTool
compilation: KotlinJvmAndroidCompilation,
project: Project,
androidExt: BaseExtension,
androidPlugin: BasePlugin<*>
androidPlugin: BasePlugin
) {
getTestedVariantData(variantData)?.let { testedVariant ->
@@ -40,7 +40,7 @@ class Android25ProjectHandler(
override fun wireKotlinTasks(
project: Project,
compilation: KotlinJvmAndroidCompilation,
androidPlugin: BasePlugin<*>,
androidPlugin: BasePlugin,
androidExt: BaseExtension,
variantData: BaseVariant,
javaTask: TaskProvider<out AbstractCompile>,
@@ -13,7 +13,7 @@ import java.lang.reflect.Method
import java.lang.reflect.Modifier
object AndroidGradleWrapper {
fun getRuntimeJars(basePlugin: BasePlugin<*>, baseExtension: BaseExtension): Any? {
fun getRuntimeJars(basePlugin: BasePlugin, baseExtension: BaseExtension): Any? {
return basePlugin("getRuntimeJarList") ?: baseExtension("getBootClasspath") ?: basePlugin("getBootClasspath")
}
}
@@ -15,7 +15,6 @@ import org.gradle.api.attributes.Attribute
import org.gradle.api.attributes.Usage.JAVA_RUNTIME_JARS
import org.jetbrains.kotlin.gradle.plugin.*
import org.jetbrains.kotlin.gradle.utils.dashSeparatedName
import org.jetbrains.kotlin.gradle.utils.listProperty
import org.jetbrains.kotlin.gradle.utils.lowerCamelCaseName
import org.jetbrains.kotlin.gradle.utils.setProperty
@@ -169,7 +168,7 @@ open class KotlinAndroidTarget(
)
} else {
nestedVariants.single()
} as KotlinTargetComponent // Type inference corner case or bug? this cast in each branch is redundant but required here
}
}.toSet()
}