diff --git a/android-junit5/src/main/groovy/de/mannodermaus/gradle/anj5/AndroidJUnitPlatformPlugin.groovy b/android-junit5/src/main/groovy/de/mannodermaus/gradle/anj5/AndroidJUnitPlatformPlugin.groovy index 1bd2b2d2..0b49c8b1 100644 --- a/android-junit5/src/main/groovy/de/mannodermaus/gradle/anj5/AndroidJUnitPlatformPlugin.groovy +++ b/android-junit5/src/main/groovy/de/mannodermaus/gradle/anj5/AndroidJUnitPlatformPlugin.groovy @@ -172,6 +172,10 @@ class AndroidJUnitPlatformPlugin extends JUnitPlatformPlugin { String nameSuffix = map.getOrDefault("nameSuffix", "") def dependentTasks = map.dependentTasks + project.logger.info("$LOG_TAG Creating JUnit 5 Task for variant '$nameSuffix'...") + project.logger.info("$LOG_TAG Test Root Dirs: $testRootDirs") + project.logger.info("$LOG_TAG Classpath: $classpath.asPath") + project.task( TASK_NAME + nameSuffix, type: JavaExec, diff --git a/android-junit5/src/test/groovy/de/mannodermaus/gradle/anj5/AndroidJUnitPlatformSpec.groovy b/android-junit5/src/test/groovy/de/mannodermaus/gradle/anj5/AndroidJUnitPlatformSpec.groovy index 2a8a506a..be1f7cbe 100644 --- a/android-junit5/src/test/groovy/de/mannodermaus/gradle/anj5/AndroidJUnitPlatformSpec.groovy +++ b/android-junit5/src/test/groovy/de/mannodermaus/gradle/anj5/AndroidJUnitPlatformSpec.groovy @@ -2,6 +2,7 @@ package de.mannodermaus.gradle.anj5 import org.gradle.api.Project import org.gradle.api.internal.plugins.PluginApplicationException +import org.gradle.internal.resolve.ModuleVersionNotFoundException import org.gradle.testfixtures.ProjectBuilder import spock.lang.Specification @@ -176,10 +177,10 @@ abstract class AndroidJUnitPlatformSpec extends Specification { p.tasks.getByName("junitPlatformTestRelease")].forEach { task -> def classpath = task.classpath.collect { it.absolutePath } -// println "---- $task.name" -// classpath.each { -// println " > $it" -// } + println "---- $task.name" + classpath.each { + println " > $it" + } // Source set's outputs assert classpath.find { it.contains("test/build/intermediates/classes/") } != null @@ -284,4 +285,61 @@ abstract class AndroidJUnitPlatformSpec extends Specification { // (Project.logging listeners don't seem to work) assert true == true } + + def "custom junit jupiter version"() { + when: + def nonExistentVersion = "0.0.0" + + Project p = ProjectBuilder.builder().withParent(testRoot).build() + p.file(".").mkdir() + p.file("src/main").mkdirs() + p.file("src/main/AndroidManifest.xml").withWriter { it.write(ANDROID_MANIFEST) } + + p.apply plugin: 'com.android.application' + p.apply plugin: 'de.mannodermaus.android-junit5' + p.android { + compileSdkVersion COMPILE_SDK + buildToolsVersion BUILD_TOOLS + + defaultConfig { + applicationId APPLICATION_ID + minSdkVersion MIN_SDK + targetSdkVersion TARGET_SDK + versionCode VERSION_CODE + versionName VERSION_NAME + } + } + p.junitPlatform { + // Some arbitrary non-existent version + jupiterVersion nonExistentVersion + } + p.repositories { + jcenter() + } + p.dependencies { + // "testCompile" or "testApi" + invokeMethod(testCompileDependency(), junitJupiter()) + } + + then: + // AGP 2.x throws a ModuleVersionNotFoundException here + try { + p.evaluate() + throw new AssertionError("Expected ${ModuleVersionNotFoundException.class.name}, but wasn't thrown") + + } catch (Throwable expected) { + while (expected != null) { + if (expected instanceof ModuleVersionNotFoundException) { + assert expected.message.contains("Could not find org.junit.jupiter") + assert expected.message.contains("$nonExistentVersion") + break + } + expected = expected.cause + } + + if (expected == null) { + throw new AssertionError("Expected ${ModuleVersionNotFoundException.class.name}, but wasn't thrown") + } + } + } } diff --git a/android-junit5/src/testAgp2x/groovy/de/mannodermaus/gradle/anj5/AndroidJUnitPlatformAgp2xSpec.groovy b/android-junit5/src/testAgp2x/groovy/de/mannodermaus/gradle/anj5/AndroidJUnitPlatformAgp2xSpec.groovy index 961d8a3d..ed7ae34b 100644 --- a/android-junit5/src/testAgp2x/groovy/de/mannodermaus/gradle/anj5/AndroidJUnitPlatformAgp2xSpec.groovy +++ b/android-junit5/src/testAgp2x/groovy/de/mannodermaus/gradle/anj5/AndroidJUnitPlatformAgp2xSpec.groovy @@ -19,61 +19,4 @@ class AndroidJUnitPlatformAgp2xSpec extends AndroidJUnitPlatformSpec { protected String testRuntimeDependency() { return "testApk" } - - def "custom junit jupiter version"() { - when: - def nonExistentVersion = "0.0.0" - - Project p = ProjectBuilder.builder().withParent(testRoot).build() - p.file(".").mkdir() - p.file("src/main").mkdirs() - p.file("src/main/AndroidManifest.xml").withWriter { it.write(ANDROID_MANIFEST) } - - p.apply plugin: 'com.android.application' - p.apply plugin: 'de.mannodermaus.android-junit5' - p.android { - compileSdkVersion COMPILE_SDK - buildToolsVersion BUILD_TOOLS - - defaultConfig { - applicationId APPLICATION_ID - minSdkVersion MIN_SDK - targetSdkVersion TARGET_SDK - versionCode VERSION_CODE - versionName VERSION_NAME - } - } - p.junitPlatform { - // Some arbitrary non-existent version - jupiterVersion nonExistentVersion - } - p.repositories { - jcenter() - } - p.dependencies { - // "testCompile" or "testApi" - invokeMethod(testCompileDependency(), junitJupiter()) - } - - then: - // AGP 2.x throws a ModuleVersionNotFoundException here - try { - p.evaluate() - throw new AssertionError("Expected ${ModuleVersionNotFoundException.class.name}, but wasn't thrown") - - } catch (Throwable expected) { - while (expected != null) { - if (expected instanceof ModuleVersionNotFoundException) { - assert expected.message.contains("Could not find org.junit.jupiter") - assert expected.message.contains("$nonExistentVersion") - break - } - expected = expected.cause - } - - if (expected == null) { - throw new AssertionError("Expected ${ModuleVersionNotFoundException.class.name}, but wasn't thrown") - } - } - } } diff --git a/android-junit5/src/testAgp3x/groovy/de/mannodermaus/gradle/anj5/AndroidJUnitPlatformAgp3xSpec.groovy b/android-junit5/src/testAgp3x/groovy/de/mannodermaus/gradle/anj5/AndroidJUnitPlatformAgp3xSpec.groovy index 7b7aa962..17009b6a 100644 --- a/android-junit5/src/testAgp3x/groovy/de/mannodermaus/gradle/anj5/AndroidJUnitPlatformAgp3xSpec.groovy +++ b/android-junit5/src/testAgp3x/groovy/de/mannodermaus/gradle/anj5/AndroidJUnitPlatformAgp3xSpec.groovy @@ -1,6 +1,8 @@ package de.mannodermaus.gradle.anj5 import org.gradle.api.Project +import org.gradle.internal.resolve.ArtifactResolveException +import org.gradle.internal.resolve.ModuleVersionNotFoundException import org.gradle.testfixtures.ProjectBuilder class AndroidJUnitPlatformAgp3xSpec extends AndroidJUnitPlatformSpec { @@ -14,49 +16,4 @@ class AndroidJUnitPlatformAgp3xSpec extends AndroidJUnitPlatformSpec { protected String testRuntimeDependency() { return "testRuntimeOnly" } - - def "custom junit jupiter version"() { - when: - def nonExistentVersion = "0.0.0" - - Project p = ProjectBuilder.builder().withParent(testRoot).build() - p.file(".").mkdir() - p.file("src/main").mkdirs() - p.file("src/main/AndroidManifest.xml").withWriter { it.write(ANDROID_MANIFEST) } - - p.apply plugin: 'com.android.application' - p.apply plugin: 'de.mannodermaus.android-junit5' - p.android { - compileSdkVersion COMPILE_SDK - buildToolsVersion BUILD_TOOLS - - defaultConfig { - applicationId APPLICATION_ID - minSdkVersion MIN_SDK - targetSdkVersion TARGET_SDK - versionCode VERSION_CODE - versionName VERSION_NAME - } - } - p.junitPlatform { - // Some arbitrary non-existent version - jupiterVersion nonExistentVersion - } - p.dependencies { - // "testCompile" or "testApi" - invokeMethod(testCompileDependency(), junitJupiter()) - } - - then: - p.evaluate() - - def testApiDeps = p.configurations.getByName("testApi").dependencies - assert testApiDeps.find { - it.group == "org.junit.jupiter" && it.name == "junit-jupiter-api" && it.version == nonExistentVersion - } != null - - assert testApiDeps.find { - it.group == "junit" && it.name == "junit" && it.version == "4.12" - } != null - } }