Skip to content

Commit

Permalink
Add support for Gradle 5 (#153)
Browse files Browse the repository at this point in the history
* Add support for Gradle 5

* Correctly set file collections to avoid StackOverflowError

* Remove unused imports
  • Loading branch information
henriquenfaria authored and vanniktech committed Apr 26, 2019
1 parent 78597ea commit 25a9460
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 35 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ before_install:
# Download SDK
- yes | sdkmanager "tools" &>/dev/null
- yes | sdkmanager "platform-tools" &>/dev/null
- yes | sdkmanager "build-tools;27.0.3" &>/dev/null
- yes | sdkmanager "platforms;android-27" &>/dev/null
- yes | sdkmanager "build-tools;28.0.3" &>/dev/null
- yes | sdkmanager "platforms;android-28" &>/dev/null
# Update remaining dependencies and accept licenses
- yes | sdkmanager --update &>/dev/null
- yes | sdkmanager --licenses &>/dev/null
Expand Down
12 changes: 6 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ dependencies {
api gradleApi()
api localGroovy()

compileOnly 'com.android.tools.build:gradle:3.1.2'
compileOnly 'com.android.tools.build:gradle:3.4.0'

testCompile 'com.android.tools.build:gradle:3.1.2'
testCompile 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.11'
testCompile 'com.android.tools.build:gradle:3.4.0'
testCompile 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.30'
testCompile 'junit:junit:4.12'
testCompile 'org.spockframework:spock-core:1.1-groovy-2.4', { exclude module: "groovy-all" } // Use localGroovy()
}
Expand All @@ -63,7 +63,7 @@ pluginBundle {
}
}

task wrapper(type: Wrapper) {
gradleVersion = '4.8'
wrapper {
gradleVersion = '5.1.1'
distributionType = Wrapper.DistributionType.ALL
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.8-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class GenerationPlugin implements Plugin<Project> {
executionData = subProject.files("${subProject.buildDir}/jacoco/test.exec")

if (mergeTask != null) {
mergeTask.executionData += executionData
mergeTask.executionData.setFrom(executionData.files + mergeTask.executionData.files)
}
if (mergedReportTask != null) {
mergedReportTask.classDirectories.setFrom(classDirectories.files + mergedReportTask.classDirectories.files)
Expand Down Expand Up @@ -159,7 +159,7 @@ class GenerationPlugin implements Plugin<Project> {
JacocoMerge mergeTask, JacocoReport mergedReportTask, final String taskName,
final String jvmTestTaskName, final String instrumentationTestTaskName, final String sourceName,
final String sourcePath, final String productFlavorName, final String buildTypeName) {
final def destinationDir
def destinationDir
if (combined) {
destinationDir = "${subProject.buildDir}/reports/jacocoCombined"
} else {
Expand Down Expand Up @@ -236,16 +236,17 @@ class GenerationPlugin implements Plugin<Project> {

if (combined) {
// add instrumentation coverage execution data
executionData += subProject.fileTree("${subProject.buildDir}/outputs/code_coverage").matching {
def codeCoverageDirs = subProject.fileTree("${subProject.buildDir}/outputs/code_coverage").matching {
include "**/*.ec"
}
executionData.setFrom(codeCoverageDirs.files + executionData.files)
}

// add if true in extension or for the unit test Jacoco task
def addToMergeTask = !combined || extension.includeInstrumentationCoverageInMergedReport

if (mergeTask != null && addToMergeTask) {
mergeTask.executionData += executionData
mergeTask.executionData.setFrom(executionData.files + mergeTask.executionData.files)
}
if (mergedReportTask != null && addToMergeTask) {
mergedReportTask.classDirectories.setFrom(classDirectories.files + mergedReportTask.classDirectories.files)
Expand Down Expand Up @@ -277,7 +278,7 @@ class GenerationPlugin implements Plugin<Project> {

executionData.each {
if (it.exists()) {
realExecutionData += project.files(it)
realExecutionData.setFrom(project.files(it) + realExecutionData.files)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import spock.lang.Unroll

final class GenerationPluginSpec extends Specification {
final static ANDROID_PLUGINS = ["com.android.application", "com.android.library", "com.android.test", "com.android.feature"]
final static COMPILE_SDK_VERSION = 27
final static BUILD_TOOLS_VERSION = "27.0.1"
final static COMPILE_SDK_VERSION = 28
final static BUILD_TOOLS_VERSION = "28.0.3"
final static APPLICATION_ID = "com.example"

def project
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,14 @@ class GenerationTest {
assert reports.html.enabled
assert reports.html.destination.toPath() == Paths.get(project.buildDir.absolutePath, "/reports/jacoco/${flavor}${buildType.capitalize()}")

assert classDirectories.dir == project.file("build/")
assert contentEquals(classDirectories.includes, ["**/intermediates/classes/${flavor}/${buildType}/**".toString(), "**/intermediates/javac/${flavor}${buildType.capitalize()}/*/classes/**".toString()])
assert classDirectories.getFrom().first().dir == project.file("build/")
assert contentEquals(classDirectories.getFrom().first().includes, ["**/intermediates/classes/${flavor}/${buildType}/**".toString(), "**/intermediates/javac/${flavor}${buildType.capitalize()}/*/classes/**".toString()])

if (hasKotlin(project)) {
assert contentEquals(classDirectories.includes, ["**/intermediates/classes/${flavor}/${buildType}/**".toString(), "**/intermediates/javac/${flavor}${buildType.capitalize()}/*/classes/**".toString(),
assert contentEquals(classDirectories.getFrom().first().includes, ["**/intermediates/classes/${flavor}/${buildType}/**".toString(), "**/intermediates/javac/${flavor}${buildType.capitalize()}/*/classes/**".toString(),
"**/tmp/kotlin-classes/${buildType}/**".toString(), "**/tmp/kotlin-classes/${flavor}${buildType.capitalize()}/**".toString()])
} else {
assert contentEquals(classDirectories.includes, ["**/intermediates/classes/${flavor}/${buildType}/**".toString(), "**/intermediates/javac/${flavor}${buildType.capitalize()}/*/classes/**".toString()])
assert contentEquals(classDirectories.getFrom().first().includes, ["**/intermediates/classes/${flavor}/${buildType}/**".toString(), "**/intermediates/javac/${flavor}${buildType.capitalize()}/*/classes/**".toString()])
}

assert taskDependsOn(task, "test${flavor.capitalize()}${buildType.capitalize()}UnitTest")
Expand Down Expand Up @@ -326,11 +326,11 @@ class GenerationTest {
assert reports.html.enabled
assert reports.html.destination.toPath() == Paths.get(project.buildDir.absolutePath, "/reports/jacoco/debug")

assert classDirectories.dir == project.file("build/")
assert classDirectories.getFrom().first().dir == project.file("build/")
if (hasKotlin(project)) {
assert contentEquals(classDirectories.includes, ['**/intermediates/classes/debug/**', '**/intermediates/javac/debug/*/classes/**', '**/tmp/kotlin-classes/debug/**'])
assert contentEquals(classDirectories.getFrom().first().includes, ['**/intermediates/classes/debug/**', '**/intermediates/javac/debug/*/classes/**', '**/tmp/kotlin-classes/debug/**'])
} else {
assert contentEquals(classDirectories.includes, ['**/intermediates/classes/debug/**', '**/intermediates/javac/debug/*/classes/**'])
assert contentEquals(classDirectories.getFrom().first().includes, ['**/intermediates/classes/debug/**', '**/intermediates/javac/debug/*/classes/**'])
}

assert taskDependsOn(debugTask, 'testDebugUnitTest')
Expand Down Expand Up @@ -366,11 +366,11 @@ class GenerationTest {
assert reports.html.enabled
assert reports.html.destination.toPath() == Paths.get(project.buildDir.absolutePath, '/reports/jacocoCombined/debug')

assert classDirectories.dir == project.file("build/")
assert classDirectories.getFrom().first().dir == project.file("build/")
if (hasKotlin(project)) {
assert contentEquals(classDirectories.includes, ['**/intermediates/classes/debug/**', '**/intermediates/javac/debug/*/classes/**', '**/tmp/kotlin-classes/debug/**'])
assert contentEquals(classDirectories.getFrom().first().includes, ['**/intermediates/classes/debug/**', '**/intermediates/javac/debug/*/classes/**', '**/tmp/kotlin-classes/debug/**'])
} else {
assert contentEquals(classDirectories.includes, ['**/intermediates/classes/debug/**', '**/intermediates/javac/debug/*/classes/**'])
assert contentEquals(classDirectories.getFrom().first().includes, ['**/intermediates/classes/debug/**', '**/intermediates/javac/debug/*/classes/**'])
}

assert taskDependsOn(debugTaskCombined, 'testDebugUnitTest')
Expand Down Expand Up @@ -410,11 +410,11 @@ class GenerationTest {
assert reports.html.enabled
assert reports.html.destination.toPath() == Paths.get(project.buildDir.absolutePath, '/reports/jacoco/release')

assert classDirectories.dir == project.file("build/")
assert classDirectories.getFrom().first().dir == project.file("build/")
if (hasKotlin(project)) {
assert contentEquals(classDirectories.includes, ['**/intermediates/classes/release/**', '**/intermediates/javac/release/*/classes/**', '**/tmp/kotlin-classes/release/**'])
assert contentEquals(classDirectories.getFrom().first().includes, ['**/intermediates/classes/release/**', '**/intermediates/javac/release/*/classes/**', '**/tmp/kotlin-classes/release/**'])
} else {
assert contentEquals(classDirectories.includes, ['**/intermediates/classes/release/**', '**/intermediates/javac/release/*/classes/**'])
assert contentEquals(classDirectories.getFrom().first().includes, ['**/intermediates/classes/release/**', '**/intermediates/javac/release/*/classes/**'])
}

assert taskDependsOn(releaseTask, 'testReleaseUnitTest')
Expand Down Expand Up @@ -451,14 +451,14 @@ class GenerationTest {
assert reports.html.enabled
assert reports.html.destination.toPath() == Paths.get(project.buildDir.absolutePath, '/reports/jacocoCombined/release')

assert classDirectories.dir == project.file("build/")
assert classDirectories.getFrom().first().dir == project.file("build/")
if (hasKotlin(project)) {
assert contentEquals(classDirectories.includes, ['**/intermediates/classes/release/**', '**/intermediates/javac/release/*/classes/**', '**/tmp/kotlin-classes/release/**'])
assert contentEquals(classDirectories.getFrom().first().includes, ['**/intermediates/classes/release/**', '**/intermediates/javac/release/*/classes/**', '**/tmp/kotlin-classes/release/**'])
} else {
assert contentEquals(classDirectories.includes, ['**/intermediates/classes/release/**', '**/intermediates/javac/release/*/classes/**'])
assert contentEquals(classDirectories.getFrom().first().includes, ['**/intermediates/classes/release/**', '**/intermediates/javac/release/*/classes/**'])
}

assert taskDependsOn(releaseTaskCombined, 'testReleaseUnitTest')
assert taskDependsOn(releaseTaskCombined, 'testReleaseUnitTest')
assert taskDependsOn(releaseTaskCombined, 'createReleaseCoverageReport')
assert taskDependsOn(project.tasks.findByName('check'), 'combinedTestReportRelease')
}
Expand Down Expand Up @@ -492,8 +492,8 @@ class GenerationTest {
assert sourceDirectories.contains(project.file("src/main/$it"))
}

assert classDirectories.dir == project.file('build/')
assert contentEquals(classDirectories.includes, ['**/classes/**/main/**'])
assert classDirectories.getFrom().first().dir == project.file("build/")
assert contentEquals(classDirectories.getFrom().first().includes, ['**/classes/**/main/**'])

assert reports.xml.enabled
assert reports.csv.enabled
Expand Down

0 comments on commit 25a9460

Please sign in to comment.