Kapt: Fix extending configurations in Gradle, create "main" configuration if it does not exist yet. Also fix checking kapt configuration dependencies, use allDependencies instead (KT-15814)
This commit is contained in:
+10
@@ -157,6 +157,16 @@ fun getSomething() = 10
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testKaptKt15814() {
|
||||||
|
val project = Project("kaptKt15814", gradleVersion)
|
||||||
|
val options = defaultBuildOptions().copy(incremental = false)
|
||||||
|
|
||||||
|
project.build("assembleDebug", "test", options = options) {
|
||||||
|
assertSuccessful()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testAndroidIcepickProject() {
|
fun testAndroidIcepickProject() {
|
||||||
val project = Project("AndroidIcepickProject", gradleVersion)
|
val project = Project("AndroidIcepickProject", gradleVersion)
|
||||||
|
|||||||
+41
@@ -0,0 +1,41 @@
|
|||||||
|
apply plugin: 'com.android.application'
|
||||||
|
apply plugin: 'kotlin-android'
|
||||||
|
|
||||||
|
android {
|
||||||
|
compileSdkVersion 23
|
||||||
|
buildToolsVersion "23.0.1"
|
||||||
|
defaultConfig {
|
||||||
|
applicationId "com.example.genclassesnotfound"
|
||||||
|
minSdkVersion 19
|
||||||
|
targetSdkVersion 23
|
||||||
|
versionCode 1
|
||||||
|
versionName "1.0"
|
||||||
|
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||||
|
}
|
||||||
|
buildTypes {
|
||||||
|
release {
|
||||||
|
minifyEnabled false
|
||||||
|
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sourceSets {
|
||||||
|
main.java.srcDirs += 'src/main/kotlin'
|
||||||
|
test.java.srcDirs += 'src/test/kotlin'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
|
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
|
||||||
|
exclude group: 'com.android.support', module: 'support-annotations'
|
||||||
|
})
|
||||||
|
testCompile 'junit:junit:4.12'
|
||||||
|
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
||||||
|
kaptTest "com.squareup.dagger:dagger-compiler:$dagger_version"
|
||||||
|
compile "com.squareup.dagger:dagger:$dagger_version"
|
||||||
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
mavenCentral()
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
# Add project specific ProGuard rules here.
|
||||||
|
# By default, the flags in this file are appended to flags specified
|
||||||
|
# in /Users/knjohn/.android-sdk/tools/proguard/proguard-android.txt
|
||||||
|
# You can edit the include path and order by changing the proguardFiles
|
||||||
|
# directive in build.gradle.
|
||||||
|
#
|
||||||
|
# For more details, see
|
||||||
|
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||||
|
|
||||||
|
# Add any project specific keep options here:
|
||||||
|
|
||||||
|
# If your project uses WebView with JS, uncomment the following
|
||||||
|
# and specify the fully qualified class name to the JavaScript interface
|
||||||
|
# class:
|
||||||
|
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||||
|
# public *;
|
||||||
|
#}
|
||||||
|
|
||||||
|
# Uncomment this to preserve the line number information for
|
||||||
|
# debugging stack traces.
|
||||||
|
#-keepattributes SourceFile,LineNumberTable
|
||||||
|
|
||||||
|
# If you keep the line number information, uncomment this to
|
||||||
|
# hide the original source file name.
|
||||||
|
#-renamesourcefileattribute SourceFile
|
||||||
+15
@@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
package="com.example.genclassesnotfound">
|
||||||
|
|
||||||
|
<application
|
||||||
|
android:allowBackup="true"
|
||||||
|
android:label="@string/app_name">
|
||||||
|
<activity android:name=".MainActivity">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN"/>
|
||||||
|
<category android:name="android.intent.category.LAUNCHER"/>
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
</application>
|
||||||
|
</manifest>
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
package com.example.genclassesnotfound;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
public class MainActivity extends Activity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.activity_main);
|
||||||
|
}
|
||||||
|
}
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/activity_main"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
<resources>
|
||||||
|
<string name="app_name">GenClassesNotFound</string>
|
||||||
|
</resources>
|
||||||
+40
@@ -0,0 +1,40 @@
|
|||||||
|
package com.example.genclassesnotfound
|
||||||
|
|
||||||
|
import dagger.Module
|
||||||
|
import dagger.ObjectGraph
|
||||||
|
import dagger.Provides
|
||||||
|
import org.junit.Assert.assertEquals
|
||||||
|
import org.junit.Before
|
||||||
|
import org.junit.Test
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class ExampleUnitTest {
|
||||||
|
|
||||||
|
lateinit var graph: ObjectGraph
|
||||||
|
lateinit @Inject var config: Config
|
||||||
|
|
||||||
|
@Before
|
||||||
|
fun setUp() {
|
||||||
|
graph = ObjectGraph.create(TestModule())
|
||||||
|
graph.inject(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun addition_isCorrect() {
|
||||||
|
assertEquals(4 + config.magicNumber, 9)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Module(
|
||||||
|
injects = arrayOf(ExampleUnitTest::class),
|
||||||
|
complete = true,
|
||||||
|
library = true
|
||||||
|
|
||||||
|
)
|
||||||
|
class TestModule {
|
||||||
|
@Provides fun providesDependency(): Config {
|
||||||
|
return Config(5)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data class Config(val magicNumber : Int)
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||||
|
|
||||||
|
buildscript {
|
||||||
|
ext.dagger_version = '1.2.5'
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
jcenter()
|
||||||
|
}
|
||||||
|
dependencies {
|
||||||
|
classpath "com.android.tools.build:gradle:$android_tools_version"
|
||||||
|
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||||
|
classpath "com.jakewharton.sdkmanager:gradle-plugin:0.12.+"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
allprojects {
|
||||||
|
repositories {
|
||||||
|
mavenLocal()
|
||||||
|
jcenter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
task clean(type: Delete) {
|
||||||
|
delete rootProject.buildDir
|
||||||
|
}
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
org.gradle.jvmargs=-ea -XX:MaxPermSize=512m
|
||||||
+1
@@ -0,0 +1 @@
|
|||||||
|
include ':app'
|
||||||
+7
-3
@@ -124,7 +124,7 @@ internal class Kotlin2JvmSourceSetProcessor(
|
|||||||
|
|
||||||
var kotlinAfterJavaTask: KotlinCompile? = null
|
var kotlinAfterJavaTask: KotlinCompile? = null
|
||||||
|
|
||||||
if (aptConfiguration.dependencies.size > 1 && !Kapt3GradleSubplugin.isEnabled(project)) {
|
if (!Kapt3GradleSubplugin.isEnabled(project) && aptConfiguration.allDependencies.size > 1) {
|
||||||
javaTask.dependsOn(aptConfiguration.buildDependencies)
|
javaTask.dependsOn(aptConfiguration.buildDependencies)
|
||||||
|
|
||||||
val (aptOutputDir, aptWorkingDir) = project.getAptDirsForSourceSet(sourceSetName)
|
val (aptOutputDir, aptWorkingDir) = project.getAptDirsForSourceSet(sourceSetName)
|
||||||
@@ -388,7 +388,7 @@ internal open class KotlinAndroidPlugin(
|
|||||||
for (provider in variantData.sourceProviders) {
|
for (provider in variantData.sourceProviders) {
|
||||||
val aptConfiguration = aptConfigurations[(provider as AndroidSourceSet).name]
|
val aptConfiguration = aptConfigurations[(provider as AndroidSourceSet).name]
|
||||||
// Ignore if there's only an annotation processor wrapper in dependencies (added by default)
|
// Ignore if there's only an annotation processor wrapper in dependencies (added by default)
|
||||||
if (aptConfiguration != null && aptConfiguration.dependencies.size > 1) {
|
if (aptConfiguration != null && aptConfiguration.allDependencies.size > 1) {
|
||||||
javaTask.dependsOn(aptConfiguration.buildDependencies)
|
javaTask.dependsOn(aptConfiguration.buildDependencies)
|
||||||
aptFiles.addAll(aptConfiguration.resolve())
|
aptFiles.addAll(aptConfiguration.resolve())
|
||||||
}
|
}
|
||||||
@@ -609,6 +609,7 @@ private fun Project.getAptDirsForSourceSet(sourceSetName: String): Pair<File, Fi
|
|||||||
private fun Project.createAptConfiguration(sourceSetName: String, kotlinPluginVersion: String): Configuration {
|
private fun Project.createAptConfiguration(sourceSetName: String, kotlinPluginVersion: String): Configuration {
|
||||||
val aptConfigurationName = Kapt3KotlinGradleSubplugin.getKaptConfigurationName(sourceSetName)
|
val aptConfigurationName = Kapt3KotlinGradleSubplugin.getKaptConfigurationName(sourceSetName)
|
||||||
|
|
||||||
|
configurations.findByName(aptConfigurationName)?.let { return it }
|
||||||
val aptConfiguration = configurations.create(aptConfigurationName)
|
val aptConfiguration = configurations.create(aptConfigurationName)
|
||||||
|
|
||||||
// Add base kotlin-annotation-processing artifact for the main kapt configuration,
|
// Add base kotlin-annotation-processing artifact for the main kapt configuration,
|
||||||
@@ -617,7 +618,10 @@ private fun Project.createAptConfiguration(sourceSetName: String, kotlinPluginVe
|
|||||||
val kotlinAnnotationProcessingDep = "org.jetbrains.kotlin:kotlin-annotation-processing:$kotlinPluginVersion"
|
val kotlinAnnotationProcessingDep = "org.jetbrains.kotlin:kotlin-annotation-processing:$kotlinPluginVersion"
|
||||||
aptConfiguration.dependencies.add(dependencies.create(kotlinAnnotationProcessingDep))
|
aptConfiguration.dependencies.add(dependencies.create(kotlinAnnotationProcessingDep))
|
||||||
} else {
|
} else {
|
||||||
Kapt3KotlinGradleSubplugin.findMainKaptConfiguration(this)?.let { aptConfiguration.extendsFrom(it) }
|
// "main" configuration can be created after some other. We should handle this case
|
||||||
|
val mainConfiguration = Kapt3KotlinGradleSubplugin.findMainKaptConfiguration(this)
|
||||||
|
?: createAptConfiguration("main", kotlinPluginVersion)
|
||||||
|
aptConfiguration.extendsFrom(mainConfiguration)
|
||||||
}
|
}
|
||||||
|
|
||||||
return aptConfiguration
|
return aptConfiguration
|
||||||
|
|||||||
Reference in New Issue
Block a user