-
Notifications
You must be signed in to change notification settings - Fork 28
[PT-495] Support android kotlin projects #48
Changes from 4 commits
4292d6b
0f36aa9
a8a3f52
f717db0
72bd9fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package com.novoda.test | ||
|
||
class TestAndroidKotlinProject extends TestProject<TestAndroidKotlinProject> { | ||
private static final Closure<String> TEMPLATE = { TestAndroidKotlinProject project -> | ||
""" | ||
buildscript { | ||
repositories { | ||
google() | ||
jcenter() | ||
} | ||
dependencies { | ||
classpath 'com.android.tools.build:gradle:3.0.1' | ||
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.20' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has been added There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👁🗨 |
||
} | ||
} | ||
plugins { | ||
${formatPlugins(project)} | ||
} | ||
repositories { | ||
google() | ||
jcenter() | ||
} | ||
apply plugin: 'com.android.library' | ||
apply plugin: 'kotlin-android' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has been added There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to be honest you can also use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I actually tried that for the kotlin plugin, but it didn't work. I got this error |
||
|
||
android { | ||
compileSdkVersion 27 | ||
buildToolsVersion '27.0.0' | ||
|
||
defaultConfig { | ||
minSdkVersion 16 | ||
targetSdkVersion 27 | ||
versionCode 1 | ||
versionName '1.0' | ||
} | ||
sourceSets { | ||
${formatSourceSets(project)} | ||
} | ||
${project.additionalAndroidConfig} | ||
} | ||
${formatExtension(project)} | ||
""" | ||
} | ||
|
||
private String additionalAndroidConfig = '' | ||
|
||
TestAndroidKotlinProject() { | ||
super(TEMPLATE) | ||
File localProperties = Fixtures.LOCAL_PROPERTIES | ||
if (localProperties.exists()) { | ||
withFile(localProperties, 'local.properties') | ||
} | ||
} | ||
|
||
private static String formatSourceSets(TestProject project) { | ||
project.sourceSets | ||
.entrySet() | ||
.collect { Map.Entry<String, List<String>> entry -> | ||
"""$entry.key { | ||
manifest.srcFile '${Fixtures.ANDROID_MANIFEST}' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe use double quotes just so there's more consistency? you can also just use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is printing the entire config. In the generated one we want single quotes if possible. |
||
kotlin { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has been changed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. well, if you add your sources to |
||
${entry.value.collect { "srcDir '$it'" }.join('\n\t\t\t\t')} | ||
} | ||
}""" | ||
} | ||
.join('\n\t\t') | ||
} | ||
|
||
@Override | ||
List<String> defaultArguments() { | ||
['-x', 'lint'] + super.defaultArguments() | ||
} | ||
|
||
TestAndroidKotlinProject withAdditionalAndroidConfig(String additionalAndroidConfig) { | ||
this.additionalAndroidConfig = additionalAndroidConfig | ||
return this | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is basically a copy of
TestAndroidProject
. Changes are marked.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not too important but with the comments I put below, it is possible that these can be 1 single class with different plugin configuration.
Then you can have
TestKotlinProject.forAndroid()
to configure the android plugins.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried that first but failed (see my comment below). Any help is appreciated since I also would like to get rid of this duplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just merged it. On a second thought, I don't think it is worth. Because that way, it will be more complicated.