running geb test with gradle 2.3 - HashMap$Entry exception - groovy

I am trying to run geb tests through gradle. I've these installed
java version "1.8.0_31"
Groovy Version: 2.4.0
Gradle 2.3
But i am getting this error when running the test.
Exception in thread "main" java.lang.NoClassDefFoundError: java/util/HashMap$Ent
ry
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2693)
Running a simple groovy script with above setup and the below Build.gradle is fine.
Build.gradle looks like this:
buildscript {
repositories {
jcenter()
}
}
apply plugin: 'java'
apply plugin: 'groovy'
repositories {
jcenter()
mavenCentral()
}
dependencies {
def seleniumVersion = "2.45.0"
def phantomJsVersion = '1.1.0'
// selenium drivers
compile "org.seleniumhq.selenium:selenium-firefox-driver:$seleniumVersion"
compile "org.seleniumhq.selenium:selenium-support:$seleniumVersion"
compile("com.github.detro.ghostdriver:phantomjsdriver:$phantomJsVersion") {
transitive = false
}
// geb
compile 'org.codehaus.geb:geb-core:0.7.2'
compile 'org.codehaus.geb:geb-spock:0.7.2'
// spock
compile 'org.spockframework:spock-core:0.6-groovy-1.8'
//junit
testCompile group: 'junit', name: 'junit', version: '4.7'
}
task runGebScript (dependsOn: 'classes', type: JavaExec) {
main = 'test'
classpath = sourceSets.main.runtimeClasspath
}
Can someone please help.

According to Gradle dependency report for the build you included, the Groovy version used for testCompile configuration is 1.8.5. Only groovy 2.x is JDK8 compatible. I would do as ataylor suggests and bump Spock version. If you use 1.0-groovy-2.4 then you'll be using Groovy 2.4.1. Also, I would suggest updating version of Geb while you're at it - the latest is 0.10.0. Your dependency versions are way out of date.

Something is trying to use the inner class HashMap.Entry, which no longer exists in Java 8. It's difficult to tell where without a complete stack trace.
However, you're using this version of spock: org.spockframework:spock-core:0.6-groovy-1.8. That version is not compatible with groovy 2.0+. Try updating the dependency to org.spockframework:spock-core:1.0-groovy-2.4.

Related

Hilt Unsupported metadata version in Kotlin

I was tried to run my code in Kotlin 1.5.10
With plugin as
plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
and dependencies as below
dependencies {
...
//Dagger - Hilt
implementation "com.google.dagger:hilt-android:2.33-beta"
kapt "com.google.dagger:hilt-android-compiler:2.33-beta"
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
kapt "androidx.hilt:hilt-compiler:1.0.0-beta01"
implementation 'androidx.hilt:hilt-navigation-compose:1.0.0-alpha01'
implementation 'com.android.support:palette-v7:28.0.0'
When I migrate to kotlin_version = "1.5.10", it just errors out stating
error: [Hilt]
Unsupported metadata version. Check that your Kotlin version is >= 1.0: java.lang.IllegalStateException: Unsupported metadata version. Check that your Kotlin version is >= 1.0
at dagger.internal.codegen.kotlin.KotlinMetadata.metadataOf(KotlinMetadata.java:206)
at dagger.internal.codegen.kotlin.KotlinMetadata.from(KotlinMetadata.java:186)
at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1133)
...
Can anyone help me? I spent a lot of time on it, your answer will help me a lot
Go to https://dagger.dev/hilt/gradle-setup check Hilt currently version
Update: For now, you can use the newest version.
Kotlin:1.7.0 with Hilt:2.42
Update: kotlin:1.6.0 is compatible with hilt:2.40.5, thanks #Nazanin Nasab
Currently, Kotlin 1.5.21 is compatible with Hilt 2.38.
dependencies {
...
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.42"
}
I got the same error. I changed two gradle files and It worked for me.
Project Gradle
plugins {
// dependencies for dagger hilt
id 'com.google.dagger.hilt.android' version '2.42' apply false
}
Module Gradle
dependencies {
implementation 'com.google.dagger:hilt-android:2.42'
kapt 'com.google.dagger:hilt-compiler:2.42'
implementation("androidx.hilt:hilt-navigation-fragment:1.0.0")
}
Adding this line to build.gradle dependencies helped me:
kapt("org.jetbrains.kotlinx:kotlinx-metadata-jvm:0.3.0")
https://youtrack.jetbrains.com/issue/KT-45885
Thanks for the answer , i had to do a slight tweak in order to work for me because i'm using Arctic Fox, hopefully this answer will help as well
Build.gradle (project)
buildscript {
ext {
compose_version = '1.0.0'
}
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.1.0-alpha05'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.10"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.37"
}
}
Build.gradle (app)
//Dagger - Hilt
implementation "com.google.dagger:hilt-android:2.34-beta"
kapt "com.google.dagger:hilt-android-compiler:2.34-beta"
implementation "androidx.hilt:hilt-lifecycle-viewmodel:1.0.0-alpha03"
kapt "androidx.hilt:hilt-compiler:1.0.0"
implementation 'androidx.hilt:hilt-navigation-compose:1.0.0-alpha03'
For Kotlin 1.7.10, you just need to make the hilt versions 2.42.
in Project-level build.gradle change hilt version
id 'com.google.dagger.hilt.android' version '2.44' apply false
in App-Level build.gradle
implementation "com.google.dagger:hilt-android:2.44"
kapt "com.google.dagger:hilt-compiler:2.44"
general solution - in AS build console click link at bottom - build with -stacktrace param and find which annotation processor (KAPT) is causing error - then try to update dependency - if you are lucky new version should be available and supporting your gradle version
message in build output you should lookin for
Try:
Run with --stacktrace option to get the stack trace. Run with --info or
--debug option to get more log output. Run with --scan to get full insights.
I got same here. I was using dagger:hilt-android:2.33-beta with Kotlin 1.5.10.Please try this
Project gradle
implementation "com.google.dagger:hilt-android:2.33-beta"
Module gradle
plugins {
...
id 'dagger.hilt.android.plugin'
}
dependencies {
...
//dagger-hilt
implementation "com.google.dagger:hilt-android:2.35.1"
kapt "com.google.dagger:hilt-android-compiler:2.35.1"
}
If any solution solved your problem. Go to https://dagger.dev/hilt/gradle-setup, in Using Hilt with Kotlin section, copy the version mentioned in dependencies and update your build.gradle accordingly
I have an issue when upgrading kotlin-gradle-plugin:1.7.x for fulfill requirement of compose. I revert them to org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.21 and kotlinCompilerExtensionVersion value
composeOptions {
kotlinCompilerExtensionVersion compose_version
}
kotlinCompilerExtensionVersion compose_version
in my case, the problem was in the different versions that I specified in the dependencies.
"2.40" in classpath 'com.google.dagger:hilt-android-gradle-plugin'
and
"2.43.2" in implementation 'com.google.dagger:hilt-android'
Firstly check helt dependency versions with below url
https://dagger.dev/hilt/gradle-setup
Check you kotlin versions
Kotlin version 1.6.0
Project level gradle
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.0"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.40"
App level gradle
def hilt_version="2.40"
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-compiler:$hilt_version"
Kotlin version 1.7.0
Project level gradle
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.7.0"
classpath "com.google.dagger:hilt-android-gradle-plugin:2.42"
App level gradle
def hilt_version="2.42"
implementation "com.google.dagger:hilt-android:$hilt_version"
kapt "com.google.dagger:hilt-compiler:$hilt_version"

Groovy #Grab NoClassDefFoundError: org/apache/ivy/plugins/resolver/DependencyResolver

Using #grab for the first time (new to groovy)
I understand it is meant to work "out the box."
However, when I add this to my class:
#Grab(group='commons-lang', module='commons-lang', version='2.4')
I get the following compilation error:
Caused by: java.lang.NoClassDefFoundError: org/apache/ivy/plugins/resolver/DependencyResolver
Groovy version is Groovy Version: 3.0.4 JVM: 11.0.1 Vendor: Oracle Corporation OS: Mac OS X
you have missing dependency or library ivy-2.4.0.jar
this library is a part of groovy-all artifact. check groovy-all.pom to see all groovy dependencies/features
so, you could setup dependency to groovy-all artifact in your project
or to a separate ivy-2.4.0.jar artifact if you don't want to include all groovy features into your project
Try adding this to gradle.build
configurations {
ivy
}
dependencies {
ivy "org.apache.ivy:ivy:2.4.0"
...
}
tasks.withType(GroovyCompile) {
groovyClasspath += configurations.ivy
}

How to solve NoMethodError that arises due to using a same library with two different versions using gradle or anything else?

I have two dependencies that use a same library but with different versions and I get NoMethodError. I am not sure how to solve it using gradle or anything else? Any help would be great
group 'com.hello'
version '1.0-SNAPSHOT'
apply plugin: 'java'
apply plugin: 'idea'
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
compile 'org.slf4j:slf4j-log4j12:1.7.12'
compile group: 'org.apache.spark', name: 'spark-core_2.11', version: '2.0.1'
compile group: 'org.apache.spark', name: 'spark-streaming_2.11', version: '2.0.1'
compile group: 'org.apache.spark', name: 'spark-streaming-kafka-0-10_2.11', version: '2.0.1'
compile group:'org.apache.kafka', name: 'kafka-clients', version: '0.10.1.0'
compile group: 'com.datastax.spark', name: 'spark-cassandra-connector_2.11', version: '2.0.0-M3'
compile group: 'com.github.brainlag', name: 'nsq-client', version: '1.0.0.RC2'
compile group: 'com.google.code.gson', name: 'gson', version: '2.7'
}
task buildStreamingJar(type: Jar) {
if(project.hasProperty("jarname")) {
def fullyQualifiedPackageName = ""
def jarname = project.getProperty("jarname")
if (jarname.equalsIgnoreCase("SparkDriver1")) {
fullyQualifiedPackageName = "com.hello.streamprocessing.app.SparkDriver1"
}
if (jarname.equalsIgnoreCase("SparkDriver2")) {
fullyQualifiedPackageName = "com.hello.streamprocessing.app.SparkDriver2"
}
baseName = project.name + "-$jarname" + "-stream"
from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } }
with jar
zip64 true
from sourceSets.test.output
manifest {
attributes 'Main-Class': fullyQualifiedPackageName
}
exclude 'META-INF/.RSA', 'META-INF/.SF', 'META-INF/*.DSA'
}
}
so what is happening here is that in my dependencies spark-core_2.11 uses
com.google.guava:14.0.1 and nsq-client uses com.google.guava:19.0
which is leading to the following error.
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.collect.Sets.newConcurrentHashSet()Ljava/util/Set;
at com.github.brainlag.nsq.NSQProducer.(NSQProducer.java:22)
at com.hello.streamprocessing.app.SparkDriver2.main(SparkDriver2.java:37)
I need to use this build.gradle file to build a FAT Uber jar so I can use it with spark-submit
Basically you can't really solve this, if either spark-core or nsq-client is using features of guava that or not present in one version or the other. You can run gradlew dependencies which will show you how gradle resolves the version conflict on guava. By default it will choose version 19.0 as its the newer version. Your best chance is to use versions of your libraries that are dependent on the same version of guava. That is either to downgrade nsq-client or upgrade spark-core if possible.
You can exclude the transitive dependency to guava like this:
dependencies {
...
compile (group: 'com.github.brainlag', name: 'nsq-client', version: '1.0.0.RC2') {
exclude group: 'com.google.guava', module: 'guava'
}
...
}
However this will only work if nsq-client is not relying on features only present in version 19.0 of guava as mentioned above.
Sadly this is a common problem especially with the guava library as it is used in nearly every project and the developers don't care a lot about a stable API of their library.
Your best bet is probably to try excluding guava from spark-core and give it a try and, if it's not working, to exclude it from nsq-client and give it a try. But even if it seems to be working at a first glance odds are good (or actually bad in your case), that you will run into similar problems during runtime of your application.
If the above is not working, you could still fork nsq-client and replace the problematic parts with something compatible to guava 14.0.1. I don't really like this option but if the developers of nsq-client are nice they might accept your change...
One of the dependencies lib is not being downloaded. Use the latest lib of both. Use can as well use this:
repositories {
mavenCentral()
}
configurations {
compile
}
dependencies {
compile 'dependency repo1'
compile 'dependency repo2'
}
task libs(type: Sync) {
from configurations.compile
into "$buildDir/libs"
}
This will help download both dependencies.

error: package org.hamcrest does not exist Android Studio 1.5.1

I am using Android studio 1.5.1.
My build.gradle looks like below
allprojects {
repositories {
maven { url 'http://repo1.maven.org/maven2' }
}
}
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}
apply plugin: 'com.android.application'
dependencies {
// Unit testing dependencies
testCompile 'org.hamcrest:hamcrest-library:1.3'
testCompile 'junit:junit:4.12'
}
I am writing some JUNIT test cases for my application as below
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
public void testSomething throws Exception {
...
assertThat(result, is(true));
}
But when I am running the tests, it is showing that
error: package org.hamcrest does not exist
error: cannot find symbol assertThat(result, is(true));
But I can go to the definition of assertThat, org.hamcrest etc from studio by going to definition as studio decompiles the jars.
Also I can see the package downloaded in .gradle/caches
Can anyone suggest what I am doing wrong here?
Normally Junit test cases using assertFalse, assertTrue etc is working, only hamcrest matching is giving errors.
Manually add the jar from here
Add it to your libs folder.
Right click the jar, and click add as library.
I had the same issue with getting it to find junit. Looks like Gradle is not doing its job.
I have filed a bug report, Please star:
https://code.google.com/p/android/issues/detail?id=209832&thanks=209832&ts=1463161330

Gradle Groovy compilation cannot find javafx classes in tests

I have the following Groovy test (not the real one, mind you) in a Gradle project (under src/test/groovy):
import javafx.scene.paint.Color
import org.junit.Test
class MyTest {
#Test
void test1() {
assert Color.AQUAMARINE != Color.BLUE
}
}
The build file is as simple as it gets and declares that I use Java 8 (so JavaFX is in the classpath, always):
apply plugin: 'groovy'
compileJava {
sourceCompatibility = 1.8
targetCompatibility = 1.8
}
...
It also has a test dependency on Groovy:
testCompile group: 'org.codehaus.groovy', name: 'groovy-all', version: '2.4.4'
Everything works fine, except when I refer to some JavaFX class in the Groovy test.
It fails with this error:
MyTest.groovy: 3: unable to resolve class javafx.scene.paint.Color
# line 3, column 1.
import javafx.scene.paint.Color
^
The Java code compiles fine and I can run my JavaFX application. Only the Groovy tests seem to not be able to see JavaFX.
I've already tried changing the compileJava block to compileGroovy, compileTestGroovy, also together with the compileJava block, so that the Groovy compiler sees JavaFX 8, but nothing helped.
How can I fix this?
Gradle version:
------------------------------------------------------------
Gradle 2.2
------------------------------------------------------------
Build time: 2014-11-10 13:31:44 UTC
Build number: none
Revision: aab8521f1fd9a3484cac18123a72bcfdeb7006ec
Groovy: 2.3.6
Ant: Apache Ant(TM) version 1.9.3 compiled on December 23 2013
JVM: 1.8.0_60 (Oracle Corporation 25.60-b23)
OS: Linux 3.16.0-38-generic amd64
Changed the Gradle version to 2.7 (latest as of today) and it all works.
If you have the same problem, just use Gradle's wrapper and set the Gradle version to the latest version (they move fast, so bugs will exist, but also get fixed quickly).
gradle wrapper --gradle-version 2.7

Resources