At my project, at shared -> gradle.properties I defined Ktor version as:
#ktor
ktorVersion=2.0.3
And at shared -> build.gradle.kts I'm calling it as:
val ktorVersion: String by project
plugins {
kotlin("multiplatform")
id("com.android.library")
}
val commonMain by getting {
dependencies {
implementation("io.ktor:ktor-client-core:$ktorVersion")
implementation("io.ktor:ktor-client-curl:$ktorVersion")
}
}
But got the below arror:
Failed building KotlinMPPGradleModel
org.gradle.internal.resolve.ArtifactNotFoundException: Could not find ktor-client-curl-2.0.3-samplessources.jar (io.ktor:ktor-client-curl:2.0.3).
Searched in the following locations:
https://repo.maven.apache.org/maven2/io/ktor/ktor-client-curl/2.0.3/ktor-client-curl-2.0.3-samplessources.jar
at org.gradle.internal.resolve.result.DefaultBuildableArtifactResolveResult.notFound(DefaultBuildableArtifactResolveResult.java:28)
at org.gradle.api.internal.artifacts.repositories.resolver.ExternalResourceResolver$RemoteRepositoryAccess.resolveArtifact(ExternalResourceResolver.java:509)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.CachingModuleComponentRepository$ResolveAndCacheRepositoryAccess.resolveArtifact(CachingModuleComponentRepository.java:469)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ErrorHandlingModuleComponentRepository$ErrorHandlingModuleComponentRepositoryAccess.lambda$resolveArtifact$15(ErrorHandlingModuleComponentRepository.java:181)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ErrorHandlingModuleComponentRepository$ErrorHandlingModuleComponentRepositoryAccess.tryResolveAndMaybeBlacklist(ErrorHandlingModuleComponentRepository.java:237)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ErrorHandlingModuleComponentRepository$ErrorHandlingModuleComponentRepositoryAccess.performOperationWithRetries(ErrorHandlingModuleComponentRepository.java:203)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ErrorHandlingModuleComponentRepository$ErrorHandlingModuleComponentRepositoryAccess.resolveArtifact(ErrorHandlingModuleComponentRepository.java:179)
at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.RepositoryChainArtifactResolver.resolveArtifact(RepositoryChainArtifactResolver.java:102)
at org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.DefaultArtifactSet$LazyArtifactSupplier.calculateValue(DefaultArtifactSet.java:284)
at org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.DefaultArtifactSet$LazyArtifactSupplier.calculateValue(DefaultArtifactSet.java:255)
at org.gradle.internal.model.CalculatedValueContainer$CalculationState.lambda$attachValue$0(CalculatedValueContainer.java:218)
at org.gradle.internal.Try.ofFailable(Try.java:41)
at org.gradle.internal.model.CalculatedValueContainer$CalculationState.attachValue(CalculatedValueContainer.java:213)
at org.gradle.internal.model.CalculatedValueContainer.finalizeIfNotAlready(CalculatedValueContainer.java:186)
at org.gradle.internal.model.CalculatedValueContainer.finalizeIfNotAlready(CalculatedValueContainer.java:177)
at org.gradle.api.internal.artifacts.ivyservice.resolveengine.artifact.ArtifactBackedResolvedVariant$DownloadArtifactFile.run(ArtifactBackedResolvedVariant.java:182)
at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:66)
at org.gradle.internal.operations.DefaultBuildOperationRunner$2.execute(DefaultBuildOperationRunner.java:59)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:157)
at org.gradle.internal.operations.DefaultBuildOperationRunner.execute(DefaultBuildOperationRunner.java:59)
at org.gradle.internal.operations.DefaultBuildOperationExecutor$QueueWorker.execute(DefaultBuildOperationExecutor.java:238)
at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.runOperation(DefaultBuildOperationQueue.java:266)
at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.doRunBatch(DefaultBuildOperationQueue.java:247)
at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.lambda$runBatch$0(DefaultBuildOperationQueue.java:237)
at org.gradle.internal.resources.AbstractResourceLockRegistry.whileDisallowingLockChanges(AbstractResourceLockRegistry.java:69)
at org.gradle.internal.work.DefaultWorkerLeaseService.whileDisallowingProjectLockChanges(DefaultWorkerLeaseService.java:242)
at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.lambda$runBatch$1(DefaultBuildOperationQueue.java:237)
at org.gradle.internal.work.DefaultWorkerLeaseService.withLocks(DefaultWorkerLeaseService.java:270)
at org.gradle.internal.work.DefaultWorkerLeaseService.runAsWorkerThread(DefaultWorkerLeaseService.java:119)
at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.runBatch(DefaultBuildOperationQueue.java:223)
at org.gradle.internal.operations.DefaultBuildOperationQueue$WorkerRunnable.run(DefaultBuildOperationQueue.java:191)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:64)
at org.gradle.internal.concurrent.ManagedExecutorImpl$1.run(ManagedExecutorImpl.java:48)
at java.base#11.0.13/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base#11.0.13/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base#11.0.13/java.lang.Thread.run(Thread.java:829)
Related
I developed a simple project using ktor
here is my Application.kt
fun main() {
embeddedServer(
factory = CIO, port = 8080, host = "0.0.0.0"
) {
configDependencyInjection()
configSerialization()
configJwtAuthentication()
configStatusPages()
configRequestValidation()
configUserRouting()
Database.connect(
url = "jdbc:postgresql://localhost:5432/coffeehouse",
driver = "org.postgresql.Driver",
user = "postgres",
password = "74279744fz"
)
transaction {
SchemaUtils.drop(Users, CoffeeHouses)
SchemaUtils.create(Users, CoffeeHouses)
}
}.start(wait = true)
}
and here is my build.gradle.kts
val ktorVersion: String by project
val kotlinVersion: String by project
val logbackVersion: String by project
val exposedVersion: String by project
val koinVersion: String by project
val postgresVersion: String by project
plugins {
application
kotlin("jvm") version "1.7.20"
id("io.ktor.plugin") version "2.1.2"
id("org.jetbrains.kotlin.plugin.serialization") version "1.7.20"
}
group = "ir.coffee"
version = "0.0.1"
application {
mainClass.set("ir.coffee.ApplicationKt")
val isDevelopment: Boolean = project.ext.has("development")
applicationDefaultJvmArgs = listOf("-Dio.ktor.development=$isDevelopment")
}
repositories {
mavenCentral()
}
tasks.withType<Jar> {
manifest {
attributes["Main-class"] = application.mainClass
}
}
dependencies {
implementation("io.ktor:ktor-server-content-negotiation-jvm:$ktorVersion")
implementation("io.ktor:ktor-server-core-jvm:$ktorVersion")
implementation("io.ktor:ktor-serialization-kotlinx-json-jvm:$ktorVersion")
implementation("io.ktor:ktor-server-cio-jvm:$ktorVersion")
implementation("io.ktor:ktor-server-auth:$ktorVersion")
implementation("io.ktor:ktor-server-auth-jwt:$ktorVersion")
implementation("io.ktor:ktor-server-request-validation:$ktorVersion")
implementation("io.ktor:ktor-server-status-pages:$ktorVersion")
implementation("ch.qos.logback:logback-classic:$logbackVersion")
implementation("org.jetbrains.exposed:exposed-core:$exposedVersion")
implementation("org.jetbrains.exposed:exposed-dao:$exposedVersion")
implementation("org.jetbrains.exposed:exposed-jdbc:$exposedVersion")
implementation("org.postgresql:postgresql:$postgresVersion")
implementation("io.insert-koin:koin-ktor:$koinVersion")
implementation("io.insert-koin:koin-logger-slf4j:$koinVersion")
testImplementation("io.ktor:ktor-server-tests-jvm:$ktorVersion")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion")
}
when I run the project, it works fine and i can make a jar file with
./gradlew installDist command.
but when I try to run the jar file with java -jar ir.coffee-0.0.1.jar command
i get this error:
Exception in thread "main" java.lang.NoClassDefFoundError: io/ktor/server/cio/CIO
at ir.coffee.ApplicationKt.main(Application.kt:16)
at ir.coffee.ApplicationKt.main(Application.kt)
Caused by: java.lang.ClassNotFoundException: io.ktor.server.cio.CIO at
java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
... 2 more
any suggestion how can I fix this?
The installDist task packs the project's class files in a JAR without dependencies. So to solve your problem you can either specify paths to the dependencies via the -classpath flag while executing java or pack all dependencies in a JAR (Gradle Shadow plugin).
I want my project to perform ktlintCheck on all kotlin file, but it only check on build.gradle.kts file.
build.gradle.kts file as below
ktlint {
version.set("9.4.0")
debug.set(true)
verbose.set(true)
android.set(false)
outputToConsole.set(true)
reporters {
reporter(ReporterType.PLAIN)
reporter(ReporterType.CHECKSTYLE)
}
ignoreFailures.set(false)
kotlinScriptAdditionalPaths {
include(fileTree("src/"))
}
filter {
exclude("**/generated/**")
include("**/kotlin/**")
}
}
subprojects {
apply(plugin = "org.jlleitschuh.gradle.ktlint")
ktlint {
debug.set(true)
}
}
When I run gradlew ktlintCheck, the Terminal output as below:
gradlew ktlintCheck
> Task :ktlintKotlinScriptCheck
[DEBUG] Discovered ruleset with " standard" id.
[DEBUG] Discovered reporter with "checkstyle" id.
[DEBUG] Discovered reporter with "json" id.
[DEBUG] Discovered reporter with "html" id.
[DEBUG] Discovered reporter with "plain" id.
[DEBUG] Initializing "plain" reporter with {verbose=true, color=true, color_name=DARK_GRAY}
[DEBUG] Initializing "plain" reporter with {verbose=true, color=true, color_name=DARK_GRAY}, output=C:\Code\XXXX\build\reports\ktlint\ktlintKotlinScriptCheck\ktlintKotlinScriptCheck.txt
[DEBUG] Initializing "checkstyle" reporter with {verbose=true, color=true, color_name=DARK_GRAY}, output=C:\Code\XXXX\build\reports\ktlint\ktlintKotlinScriptCheck\ktlintKotlinScriptCheck.xml
[DEBUG] Checking C:\Code\XXXX\build.gradle.kts
Resolving .editorconfig files for C:\Code\XXXX\build.gradle.kts file path
[DEBUG] 809ms / 1 file(s) / 0 error(s)
To begin there is an error in the configuration of your build.gradle file, in the block Ktlint settings, the line where it appears "version.set (" 9.4.0 ")" is incorrect as well as unnecessary. In any case, if you still decide to use this setting, it should be, for example, version.set ("0.37.2") , since it refers to the Ktlint version and not the jlleitschuh / ktlint-gradle plugin
To solve the problem make the following modifications to the build.gradle.kts file (I use Gradle 6.6.1 with Kotlin DSL in Intellij IDEA community Edition)
Please replace the plugin with the previous version (9.3.0):
build.gradle.kts file in root project
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import org.jlleitschuh.gradle.ktlint.reporter.ReporterType // for Ktlint reports
plugins {
kotlin("jvm") version "1.4.10" // Kotlin Compiler
id("org.jetbrains.dokka") version "1.4.10" // Documentation Engine For Kotlin
id("org.jlleitschuh.gradle.ktlint") version "9.3.0" // Kotlin Linter
}
group = "my group" // Replace with your group
version = "1.0-SNAPSHOT"
repositories {
mavenCentral()
jcenter()
}
dependencies {
implementation("org.junit.jupiter:junit-jupiter:5.4.2")
testImplementation(kotlin("test-junit5"))
implementation(kotlin("stdlib-jdk8"))
}
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
tasks.test {
useJUnitPlatform()
}
val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions {
jvmTarget = "1.8"
}
val compileTestKotlin: KotlinCompile by tasks
compileTestKotlin.kotlinOptions {
jvmTarget = "1.8"
}
ktlint {
// THIS LINE IS NOT necessary and is incorrect -> version.set("9.4.0")
verbose.set(true)
outputToConsole.set(true)
coloredOutput.set(true)
debug.set(false) // in your configuration this option must be set to true
android.set(false)
outputColorName.set("RED")
ignoreFailures.set(false)
enableExperimentalRules.set(false)
reporters {
reporter(ReporterType.CHECKSTYLE)
reporter(ReporterType.JSON)
reporter(ReporterType.HTML)
}
filter {
exclude("**/style-violations.kt")
exclude("**/generated/**")
include("**/kotlin/**")
}
}
I am trying to create a test class (JUnit 5) using Intellij Idea but I get the bellow error. When I created the test class it did NOT show the fix button so I am pretty sure the library is in class path.
Exception in thread "main" java.lang.NoClassDefFoundError: org/junit/platform/launcher/TestExecutionListener
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1016)
at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:151)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:802)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:700)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:623)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at com.intellij.junit5.JUnit5IdeaTestRunner.createListeners(JUnit5IdeaTestRunner.java:39)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:45)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
Caused by: java.lang.ClassNotFoundException: org.junit.platform.launcher.TestExecutionListener
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 13 more
My build.gradle looks as below:
plugins {
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.7'
}
group 'ict221'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.11
mainClassName = 'boardgame.gui.RunGame'
repositories {
mavenCentral()
}
test {
useJUnitPlatform()
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.3.1'
}
javafx {
modules = [ 'javafx.controls', 'javafx.fxml' ]
version = "11.0.2"
}
Any help is much appreciate it.
As mentionned by #CrazyCode in comments, with Intellij you need to specify the version of JUnit (because Intellij is bundled with old version of JUnit)
Add this :
dependencies {
...
testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.6.1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.6.1")
testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.6.1")
}
try entering these depencies for junit5 in a gradle project
testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.0")
testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.7.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.7.2")
testRuntimeOnly("org.junit.vintage:junit-vintage-engine:5.7.2")
Below is an example of a build.gradle for a simple application with JDK 17, Gradle 7.5.1 and JUnit Jupiter 5.9.0, which causes IntelliJ IDEA to correctly run unit tests with JUnit.
Notice that there is no need to add test dependencies as it is done automatically by configuring testing section.
build.gradle
plugins {
id 'application'
}
group = 'your.app'
version = '0.0.1'
sourceCompatibility = '17'
repositories {
mavenCentral()
}
dependencies {
}
testing {
suites {
test {
useJUnitJupiter('5.9.0')
}
}
}
application {
mainClass = 'your.app.App'
}
src/main/test/your/app/AppTest.java
package your.app;
import org.junit.jupiter.api.Test;
class AppTest {
#Test
void testFeature() {
}
}
My Android Espresso test:
package com.example.testproject;
import android.content.Context;
import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.assertion.ViewAssertions.matches;
import static android.support.test.espresso.matcher.ViewMatchers.withId;
import static android.support.test.espresso.matcher.ViewMatchers.withText;
import static org.hamcrest.core.IsNot.not;
#RunWith(AndroidJUnit4.class)
public class MainActivityTest {
private static String TAG;
private Context context;
#Rule
public ActivityTestRule<MainActivity_> mActivityRule = new ActivityTestRule<>(MainActivity_.class);
#Before
public void init() {
TAG = MainActivity.class.getName();
context = mActivityRule.getActivity();
}
#Test
public void checkClick() {
onView(withId(R.id.myButton)).perform(click());
onView(withId(R.id.myTextView)).check(matches(withText(R.string.you_click)));
}
}
My build.gradle:
apply plugin: 'com.android.application'
android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
defaultConfig {
applicationId "com.example.testproject"
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
// Enabling Multidex support for 'androidTest' builds because of large dependencies
// need for androidTest
multiDexEnabled = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
exclude 'mockito-extensions/org.mockito.plugins.MockMaker'
}
}
def AAVersion = '4.3.0'
dependencies {
annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
compile 'com.android.support.constraint:constraint-layout:1.0.1'
compile 'us.feras.mdv:markdownview:1.1.0'
compile 'com.github.mukeshsolanki:MarkdownView-Android:1.0.3'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.2.0'
compile group: 'commons-io', name: 'commons-io', version: '2.4'
androidTestCompile 'junit:junit:4.12'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2') {
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'com.google.guava', module: 'guava'
exclude group: 'junit', module: 'junit'
}
}
I run Espresso test by gradle from command line:
gradlew connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.example.testproject.MainActivityTest#checkClick
and Espresso test success run and execute. OK!
Now I want to use lib WireMock to test http request/response.
So I change my dependencies in build.gradle:
dependencies {
annotationProcessor "org.androidannotations:androidannotations:$AAVersion"
compile "org.androidannotations:androidannotations-api:$AAVersion"
compile 'com.android.support.constraint:constraint-layout:1.0.1'
compile 'us.feras.mdv:markdownview:1.1.0'
compile 'com.github.mukeshsolanki:MarkdownView-Android:1.0.3'
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:25.2.0'
compile group: 'commons-io', name: 'commons-io', version: '2.4'
androidTestCompile 'junit:junit:4.12'
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2') {
exclude group: 'com.android.support', module: 'support-annotations'
exclude group: 'com.google.guava', module: 'guava'
exclude group: 'junit', module: 'junit'
}
//WireMock
androidTestCompile("com.github.tomakehurst:wiremock:2.5.0") {
//Using Android Version Instead
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
//Version conflict with our app's slf4j version
exclude group: 'org.slf4j', module: 'slf4j-api'
//Was getting a classpath conflict for org.objectweb.asm.AnnotationVisitor which is a part of 'net.minidev:asm'
exclude group: 'org.ow2.asm', module: 'asm'
//Was getting this warning, so decided to ignore this version included by WireMock.
//Warning:Dependency org.json:json:20090211 is ignored as it may be conflicting with the internal version provided by Android.
//In case of problem, please repackage with jarjar to change the class packages
exclude group: 'org.json', module: 'json'
}
androidTestCompile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
androidTestCompile 'commons-io:commons-io:2.4'
}
And now when I run same Espresso test I get error:
gradlew connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.example.testproject.MainActivityTest#checkClick --debug --stacktrace
...
:app:assembleDebugAndroidTest UP-TO-DATE
:app:connectedDebugAndroidTest
Starting 0 tests on Galaxy Nexus - 4.3
Tests on Galaxy Nexus - 4.3 failed: Instrumentation run failed due to 'java.lang.NoClassDefFoundError'
com.android.builder.testing.ConnectedDevice > No tests found.[Galaxy Nexus - 4.3] FAILED
No tests found. This usually means that your test classes are not in the form that your test runner expects (e.g. don't inherit from TestCase or lack #Test annotations).
:app:connectedDebugAndroidTest FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:connectedDebugAndroidTest'.
> There were failing tests. See the report at: file:///D:/dev/mobile/TestProject/app/build/reports/androidTests/connected/index.html
* Try:
Run with --info or --debug option to get more log output.
* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:connectedDebugAndroidTest'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:84)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:55)
at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:62)
at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:88)
at org.gradle.api.internal.tasks.execution.ResolveTaskArtifactStateTaskExecuter.execute(ResolveTaskArtifactStateTaskExecuter.java:46)
at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:51)
at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:54)
at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
at org.gradle.api.internal.tasks.execution.CatchExceptionTaskExecuter.execute(CatchExceptionTaskExecuter.java:34)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:236)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker$1.execute(DefaultTaskGraphExecuter.java:228)
at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:61)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:228)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTaskWorker.execute(DefaultTaskGraphExecuter.java:215)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:77)
at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:58)
at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:32)
at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:113)
at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:37)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExecuter.java:23)
at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecuter.java:43)
at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:37)
at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:30)
at org.gradle.initialization.DefaultGradleLauncher$3.execute(DefaultGradleLauncher.java:196)
at org.gradle.initialization.DefaultGradleLauncher$3.execute(DefaultGradleLauncher.java:193)
at org.gradle.internal.Transformers$4.transform(Transformers.java:169)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:106)
at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(DefaultBuildOperationExecutor.java:56)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:193)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:119)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:102)
at org.gradle.launcher.exec.GradleBuildController.run(GradleBuildController.java:71)
at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:41)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:75)
at org.gradle.tooling.internal.provider.ContinuousBuildActionExecuter.execute(ContinuousBuildActionExecuter.java:49)
at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:44)
at org.gradle.tooling.internal.provider.ServicesSetupBuildActionExecuter.execute(ServicesSetupBuildActionExecuter.java:29)
at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:67)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:47)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:26)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.RequestStopIfSingleUsedDaemon.execute(RequestStopIfSingleUsedDaemon.java:34)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:74)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:72)
at org.gradle.util.Swapper.swap(Swapper.java:38)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:72)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.LogAndCheckHealth.execute(LogAndCheckHealth.java:55)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:72)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:36)
at org.gradle.launcher.daemon.server.api.DaemonCommandExecution.proceed(DaemonCommandExecution.java:120)
at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:50)
at org.gradle.launcher.daemon.server.DaemonStateCoordinator$1.run(DaemonStateCoordinator.java:297)
at org.gradle.internal.concurrent.ExecutorPolicy$CatchAndRecordFailures.onExecute(ExecutorPolicy.java:54)
at org.gradle.internal.concurrent.StoppableExecutorImpl$1.run(StoppableExecutorImpl.java:40)
Caused by: org.gradle.api.GradleException: There were failing tests. See the report at: file:///D:/dev/mobile/TestProject/app/build/reports/androidTests/connected/index.html
at com.android.build.gradle.internal.tasks.DeviceProviderInstrumentTestTask.runTests(DeviceProviderInstrumentTestTask.java:160)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:73)
at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.doExecute(DefaultTaskClassInfoStore.java:141)
at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:134)
at org.gradle.api.internal.project.taskfactory.DefaultTaskClassInfoStore$StandardTaskAction.execute(DefaultTaskClassInfoStore.java:123)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:632)
at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:615)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:95)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:76)
... 70 more
BUILD FAILED
Total time: 18.614 secs
I found solutions of problem:
If you use Android 5.0- (e.g. Android 4.3) then you MUST use Wiremock version 2.0.8-beta
androidTestCompile 'com.github.tomakehurst:wiremock:2.0.8-beta'
If you use Android 5.0+ you can you use any Wiremock version (e.g. 2.5.0)
androidTestCompile 'com.github.tomakehurst:wiremock:2.6.0'
P.S. Maybe this is a Multidex issues.
After including com.google.android.gms:play-services:4.4.52 dependency (for Google+-Login within the Android app) I have a problem running the test cases with Robotium and JUnit on Jenkins. It seems that no matter which test case, the test fails with VerifyError (I've also already observed ClassNotFound- and NoClassDefFoundError's afterwards).
Stacktraces:
VerifyError:
java.lang.VerifyError: org/catrobat/catroid/uitest/content/brick/SetSizeToBrickTest
at java.lang.Class.getDeclaredConstructors(Native Method)
at java.lang.Class.getConstructors(Class.java:508)
at android.test.suitebuilder.TestGrouping$TestCasePredicate.hasValidConstructor(TestGrouping.java:228)
at android.test.suitebuilder.TestGrouping$TestCasePredicate.apply(TestGrouping.java:217)
at android.test.suitebuilder.TestGrouping$TestCasePredicate.apply(TestGrouping.java:213)
at android.test.suitebuilder.TestGrouping.select(TestGrouping.java:172)
at android.test.suitebuilder.TestGrouping.selectTestClasses(TestGrouping.java:162)
at android.test.suitebuilder.TestGrouping.testCaseClassesInPackage(TestGrouping.java:156)
at android.test.suitebuilder.TestGrouping.addPackagesRecursive(TestGrouping.java:117)
at android.test.suitebuilder.TestSuiteBuilder.includePackages(TestSuiteBuilder.java:102)
at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:358)
at pl.polidea.instrumentation.PolideaInstrumentationTestRunner.onCreate(PolideaInstrumentationTestRunner.java:432)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4335)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
ClassNotFoundException:
java.lang.ClassNotFoundException: org.catrobat.catroid.test.utils.SimulatedSensorManager
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:251)
at android.test.ClassPathPackageInfoSource.createPackageInfo(ClassPathPackageInfoSource.java:88)
at android.test.ClassPathPackageInfoSource.access$000(ClassPathPackageInfoSource.java:39)
at android.test.ClassPathPackageInfoSource$1.load(ClassPathPackageInfoSource.java:50)
at android.test.ClassPathPackageInfoSource$1.load(ClassPathPackageInfoSource.java:47)
at android.test.SimpleCache.get(SimpleCache.java:31)
at android.test.ClassPathPackageInfoSource.getPackageInfo(ClassPathPackageInfoSource.java:72)
at android.test.ClassPathPackageInfo.getSubpackages(ClassPathPackageInfo.java:48)
at android.test.ClassPathPackageInfo.addTopLevelClassesTo(ClassPathPackageInfo.java:61)
at android.test.ClassPathPackageInfo.getTopLevelClassesRecursive(ClassPathPackageInfo.java:55)
at android.test.suitebuilder.TestGrouping.testCaseClassesInPackage(TestGrouping.java:156)
at android.test.suitebuilder.TestGrouping.addPackagesRecursive(TestGrouping.java:117)
at android.test.suitebuilder.TestSuiteBuilder.includePackages(TestSuiteBuilder.java:102)
at android.test.InstrumentationTestRunner.onCreate(InstrumentationTestRunner.java:358)
at pl.polidea.instrumentation.PolideaInstrumentationTestRunner.onCreate(PolideaInstrumentationTestRunner.java:432)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4335)
at android.app.ActivityThread.access$1500(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NoClassDefFoundError: org/catrobat/catroid/test/utils/SimulatedSensorManager
... 27 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "org.catrobat.catroid.test.utils.SimulatedSensorManager" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/data/app/org.catrobat.catroid.test-1.apk", zip file "/data/app/org.catrobat.catroid-1.apk"],nativeLibraryDirectories=[/data/app-lib/org.catrobat.catroid.test-1, /data/app-lib/org.catrobat.catroid-1, /vendor/lib, /system/lib]]
The (relevant part of) build.gradle file:
buildscript {
repositories {
mavenCentral()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.0.1'
classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.+'
// classpath 'com.google.gms:google-services:1.3.0-beta1'
}
}
repositories {
mavenCentral()
}
apply plugin: 'android-sdk-manager'
apply plugin: 'com.android.application'
apply plugin: 'checkstyle'
apply plugin: 'pmd'
apply from: 'gradle/adb_tasks.gradle'
apply from: 'gradle/code_quality_tasks.gradle'
apply from: 'gradle/intellij_config_tasks.gradle'
//apply plugin: 'com.google.gms.google-services'
check.dependsOn 'checkstyle'
check.dependsOn 'pmd'
android {
compileSdkVersion 23
buildToolsVersion '23.0.0'
defaultConfig {
minSdkVersion 16
targetSdkVersion 23
applicationId 'org.catrobat.catroid'
testApplicationId "org.catrobat.catroid.test"
testInstrumentationRunner 'pl.polidea.instrumentation.PolideaInstrumentationTestRunner'
versionCode 24
println "VersionCode is " + versionCode
versionName "0.9.17"
println "VersionName is " + versionName
buildConfigField "String", "GIT_DESCRIBE", "\"${versionName}\""
buildConfigField "String", "GIT_CURRENT_BRANCH", "\"${getCurrentGitBranch()}\""
}
defaultConfig {
multiDexEnabled = true
}
}
ext {
projectVersion = "0.9"
}
configurations {
compile.exclude group: 'xpp3' //compile problem with xstream
natives
}
dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0#aar'
compile 'com.android.support:support-v4:19.1.0'
compile 'com.android.support:multidex:1.0.1'
compile 'com.google.guava:guava:18.0'
compile ('com.squareup.okhttp:okhttp:2.3.0') {
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.google.android.gms'
}
compile ( 'com.google.code.gson:gson:2.3.1') {
exclude group: 'com.android.support', module: 'support-v4'
exclude group: 'com.google.android.gms'
}
compile 'com.github.johnpersano:supertoasts:1.3.4#aar'
compile 'com.thoughtworks.xstream:xstream:1.4.7'
def gdxVersion = '1.6.2'
compile 'com.badlogicgames.gdx:gdx:' + gdxVersion
compile 'com.badlogicgames.gdx:gdx-backend-android:' + gdxVersion
natives 'com.badlogicgames.gdx:gdx-platform:' + gdxVersion + ':natives-x86'
natives 'com.badlogicgames.gdx:gdx-platform:' + gdxVersion + ':natives-armeabi'
natives 'com.badlogicgames.gdx:gdx-platform:' + gdxVersion + ':natives-armeabi-v7a'
compile 'com.facebook.android:facebook-android-sdk:4.4.0'
compile 'com.google.android.gms:play-services:4.4.52'
//compile 'com.google.android.gms:play-services-plus:7.8.0'
//compile 'com.google.android.gms:play-services:7.8.0'
compile fileTree(include: '*.jar', dir: 'catroid/libs')
compile fileTree(include: '*.jar', dir: 'catroid/libs-natives')
androidTestCompile fileTree(include: '*.jar', dir: 'catroidTest/libs')
androidTestCompile 'com.jayway.android.robotium:robotium-solo:5.2.1'
androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'
androidTestCompile 'org.mockito:mockito-core:1.10.19'
pmd 'net.sourceforge.pmd:pmd:5.1.1'
checkstyle 'com.puppycrawl.tools:checkstyle:6.7'
}
task copyAndroidNatives() {
file("catroid/jniLibs/armeabi/").mkdirs();
file("catroid/jniLibs/armeabi-v7a/").mkdirs();
file("catroid/jniLibs/x86/").mkdirs();
configurations.natives.files.each { jar ->
def outputDir = null
if(jar.name.endsWith("natives-armeabi-v7a.jar")) outputDir = file("catroid/jniLibs/armeabi-v7a")
if(jar.name.endsWith("natives-armeabi.jar")) outputDir = file("catroid/jniLibs/armeabi")
if(jar.name.endsWith("natives-x86.jar")) outputDir = file("catroid/jniLibs/x86")
if(outputDir != null) {
copy {
from zipTree(jar)
into outputDir
include "*.so"
}
}
}
}
if (project.hasProperty('jenkins')) {
project.android.dexOptions.preDexLibraries = false
project.android.dexOptions.javaMaxHeapSize = "2048M"
}
On my device (Nexus 4 with Lollipop) The app itself is running without any problems when signing in to Google+. Also within Android Studio tests seem to run without these exceptions. I've already tried to disable bytecode verification during testing like:
tasks.withType(Test) {
scanForTestClasses = false
include "**/*Test.class"
test {
// set JVM arguments for the test JVM(s)
jvmArgs '-XX:-UseSplitVerifier'
}
}
but I still had the same errors.
Also to note, I haven't compiled the current version 'com.google.android.gms:play-services:7.8.0' or 'com.google.android.gms:play-services-plus:7.8.0', respectively, because we first need to replace ActionBarSherlock with AppCompat (otherwise it won't compile). I'm also not sure whether I need to apply the 'com.google.gms.google-services' plugin (seems to work without the plugin) - I haven't included it yet because it changes the task structure, where our automated Jenkins test system depends on.
Even after hours of searching I don't really understand why this happens.