I am trying to run Cucumber feature files in IntelliJ.
Cucumber Options is pointing to the right folder, but I get the "No tasks available" notification when trying to execute the JUnit runner class.
What am I doing wrong?
Here is my build.gradle:
plugins {
id 'java'
}
sourceCompatibility = 1.8
apply plugin: 'java'
repositories {
mavenCentral()
}
compileJava.options.encoding = "UTF-8"
dependencies {
compile 'org.codehaus.groovy:groovy-all:2.3.11'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile 'io.cucumber:cucumber-java:4.7.1'
compile 'org.seleniumhq.selenium:selenium-server:2.44.0'
testImplementation 'io.cucumber:cucumber-java:4.7.1'
compile group: 'junit', name: 'junit', version: '4.12'
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.141.59'
compile group: 'io.cucumber', name: 'cucumber-java', version: '4.7.1'
compile group: 'io.cucumber', name: 'cucumber-junit', version: '4.7.1'
compile group: 'io.cucumber', name: 'cucumber-core', version: '4.7.1'
compile group: 'net.masterthought', name: 'cucumber-reporting', version: '3.20.0'
compile group: 'io.cucumber', name: 'gherkin', version: '5.1.0'
compile group: 'info.cukes', name: 'cucumber-picocontainer', version: '1.2.5'
compile group: 'io.github.bonigarcia', name: 'webdrivermanager', version: '3.6.0'
}
Ok, none of the proposed solutions worked, but I finally figured it out.
Went to Settings > Build, Execution, Deployment > Build Tools > Gradle and changed Run tests using: from Gradle (Default) to IntelliJ IDEA.
Note: found the solution here.
When I had this problem ("No tasks available" message when trying to run a test), what worked for me was to simply re-import the project from the Gradle view.
Right-click on project in Gradle view and select Reimport Gradle Project.
I was facing the same issue.
When using gradle make sure your project structure is correct.
Your tests should be in src>test>java
This resolved the issue for me.
"No tasks available" – I got this message when trying to run Spock test.
The reason was I did not have gradle plugins configured properly:
plugins {
id 'java-library'
id 'groovy' // this one is also necessary
}
Make sure you have 'groovy' plugin enabled, then re-import your project.
I had the same problem. When I used the full package name in glue it worked, this is mine:
...
features = "src/test/resources/features",
glue = {"test.java.stepdefinitions"},
...
I also faced a similar issue, In my case, it was because I forget to use the "public" access modifier while defining test class, and apparent with Junit 4, all test classes should be public.
I faced the same issue when I was trying to run the JUnit tests in my Gradle project. the solution worked in my case.
In the Android Studio, open the Gradle panel and right click on your project name, then click on Reload Gradle Project
Related
I have a Gradle plugin implemented with Kotlin, which is built with a gradle kotlin DSL build script. This works fine. The build script is as follows and is located in the buildSrc directory of project:
plugins {
groovy
`kotlin-dsl`
}
repositories {
mavenLocal()
mavenCentral()
jcenter()
}
dependencies {
testImplementation(gradleTestKit())
implementation(kotlin("gradle-plugin"))
implementation ("com.bmuschko:gradle-docker-plugin:6.1.3")
}
Now i want to call a existing Groovy Class in the same buildSrc Source Tree from the Kotlin Plugin code. This works fine in Intellij.
But when building with gradle i get a : unresolved reference Class for the Groovy Class.
Looking at the build, i see that the compileKotlin task is executed first. When i uncomment the failing reference, i see that the groovyCompile produces the correct binaries.
So i tried this:
tasks.compileKotlin {
dependsOn(tasks.compileGroovy)
}
Naturally that is not good enough, but i tried to get the build to compile the Groovy code first.
I got the following error:
Circular dependency between the following tasks:
:buildSrc:compileGroovy
\--- :buildSrc:compileJava
\--- :buildSrc:compileKotlin
\--- :buildSrc:compileGroovy (*)
So i tried without succeeding , to remove the compileJava task dependency from compileGroovy:
tasks.compileGroovy {
dependsOn.remove(tasks.compileJava)
}
Some problem as above. Basically it is unclear to me how to remove precondigured taskdependencies in gradle
What i really need is something equivalent to gradle groovy build as :
compileGroovy.dependsOn = compileGroovy.taskDependencies.values - 'compileJava'
compileKotlin.dependsOn compileGroovy
compileKotlin.classpath += files(compileGroovy.destinationDir)
classes.dependsOn compileKotlin
How would look that like the Gradle Kotlin Dsl?
Or are there better ways to solve this Groovy / Kotlin Code Dependency problem?
Version Info:
------------------------------------------------------------
Gradle 5.2.1
------------------------------------------------------------
Build time: 2019-02-08 19:00:10 UTC
Revision: f02764e074c32ee8851a4e1877dd1fea8ffb7183
Kotlin DSL: 1.1.3
Kotlin: 1.3.20
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 1.8.0_232 (AdoptOpenJDK 25.232-b09)
OS: Mac OS X 10.15.3 x86_64
I think this is equivalent, though I think it just knocks Java out of the picture, so Groovy/Kotlin/Java buildSrc code won't work...:
tasks {
val compileJava = named("compileJava", JavaCompile::class).get()
val compileKotlin = named("compileKotlin", KotlinCompile::class).get()
val compileGroovy = named("compileGroovy", GroovyCompile::class).get()
val classes by getting
compileGroovy.dependsOn.remove("compileJava")
compileKotlin.setDependsOn(mutableListOf(compileGroovy))
compileKotlin.classpath += files(compileGroovy.destinationDir)
classes.setDependsOn(mutableListOf(compileKotlin))
}
This has been vastly improved in Gradle 6.1
https://docs.gradle.org/6.1/release-notes.html#defining-compilation-order-between-groovy,-scala-and-java
And I'm not sure the above works for test ordering if they have unexpected language dependency ordering
I am trying to run the simple 'getting-started'-type gradle project with quarkus and my unit test fails everytime with this error
Caused by: io.quarkus.bootstrap.BootstrapException: Failed to locate project pom.xml for C:\Users\myuser\IdeaProjects\myproj\build\classes\java\main
Followed instructions here https://quarkus.io/guides/gradle-tooling
Any suggestions or thoughts on what is going on?
Gradle version details
Gradle 5.4
Build time: 2019-04-16 02:44:16 UTC
Revision: a4f3f91a30d4e36d82cc7592c4a0726df52aba0d
Kotlin: 1.3.21
Groovy: 2.5.4
Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM: 11.0.2 (Oracle Corporation 11.0.2+9)
OS: Windows 10 10.0 amd64
btw. the problem is still open (current version 0.19.1) and issue (2307) is still unresolved.
The reason is that #QuarkusTest points to the QuarkusTestExtension, which in BootstrapClassLoaderFactory.newDeploymentClassLoader attempts to resolve local project with Maven.
We have options:
wait for official solution (see issue)
write own extension overriding BootstrapClassLoaderFactory to "understand" gradle project structure
apply a workaround (for time being), i.e. generate pom.xml from gradle build
Workaround
in build.grade:
plugins {
id 'java'
id 'io.quarkus' version '0.19.1'
// ...
id 'maven-publish'
}
// ...
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
// augment your pom here if necessary
}
}
}
// ...
task createPom(type: Copy) {
description 'This is workaround to generate pom.xml, needed for #QuarkusTest tests.'
dependsOn('generatePomFileForMavenJavaPublication')
from "$buildDir/publications/mavenJava/pom-default.xml"
into '.'
rename('pom-default.xml', 'pom.xml')
}
Note:
use 'maven-publish', not obsolete 'maven' plugin.
do not forget to apply ./gradlew createPom on dependencies changes
I'm trying to set up Appium with Android Studio and encounter loads of errors. I include the necessary dependencies via Selenium and Appium jar file for java and use as a library, I get the following error:
Error: Program type already present: org.openqa.selenium.WebDriver$Window
**Just add the following dependency in your app gradle. it is working fine for me **
implementation('org.seleniumhq.selenium:selenium-java:2.41.0')
testImplementation group: 'junit', name: 'junit', version: '4.12'
build fails, classpath error:
thufir#dur:~/NetBeansProjects/kotlinShadowJar$
thufir#dur:~/NetBeansProjects/kotlinShadowJar$ gradle clean
FAILURE: Build failed with an exception.
* What went wrong:
A problem occurred configuring root project 'kotlinShadowJar'.
> Could not resolve all files for configuration ':classpath'.
> Could not find org.jetbrains.kotlin:kotlin-gradle-plugin:.
Searched in the following locations:
file:/home/thufir/.gradle/caches/4.3.1/embedded-kotlin-repo-1.1.51-1/repo/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.pom
file:/home/thufir/.gradle/caches/4.3.1/embedded-kotlin-repo-1.1.51-1/repo/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.jar
https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.pom
https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.jar
https://repo.gradle.org/gradle/repo/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.pom
https://repo.gradle.org/gradle/repo/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.jar
Required by:
project :
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
cat build.gradle.kts:
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
buildscript {
repositories {
mavenCentral()
gradleScriptKotlin()
}
dependencies {
classpath(kotlinModule("gradle-plugin"))
classpath("com.github.jengelman.gradle.plugins:shadow:1.2.3")
}
}
apply {
plugin("kotlin")
plugin("com.github.johnrengelman.shadow")
}
repositories {
mavenCentral()
}
val shadowJar: ShadowJar by tasks
shadowJar.apply {
manifest.attributes.apply {
put("Implementation-Title", "Gradle Jar File Example")
put("Implementation-Version" version)
put("Main-Class", "com.mkyong.DateUtils")
}
baseName = project.name + "-all"
}
The buildfile was a direct copy of a working build. The context is getting started with Kotlin script Gradle. So far as I can tell the script should be good.
Note that I'm not using intelli-J, this is strictly from the CLI with Kotlin script Gradle.
perhaps it's something quite simple, like "plugin" versus "plugins"...
Looking at the error logs, you can see the plugin version request:
Searched in the following locations:
file:/home/thufir/.gradle/caches/4.3.1/embedded-kotlin-repo-1.1.51-1/repo/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.pom
file:/home/thufir/.gradle/caches/4.3.1/embedded-kotlin-repo-1.1.51-1/repo/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.jar
https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.pom
https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.jar
https://repo.gradle.org/gradle/repo/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.pom
https://repo.gradle.org/gradle/repo/org/jetbrains/kotlin/kotlin-gradle-plugin//kotlin-gradle-plugin-.jar
You can see that a version is not requested on each plugin request because they are looking for kotlin-gradle-plugin-.jar.
If you look at the source, you will also see that kotlinModule is deprecated.
I would recommend a few different changes to improve the build script:
Using the Gradle wrapper (./gradlew
Specify a version for your kotlinModule until you upgrade your Gradle version - kotlinModule("gradle-plugin", "1.1.51")
Use the plugins {} block instead of buildscript for plugins
I'm trying to setup jenkins for testing a web application. For this setup I have a gradle build file.
apply plugin: 'java'
apply plugin: 'maven'
defaultTasks 'clean','compileJava','test'
group = 'automationtest'
version = '1.1-SNAPSHOT'
description = ""
repositories {
maven { url "http://repo.maven.apache.org/maven2" }
}
dependencies {
compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version:'2.52.0'
compile group: 'org.uncommons', name: 'reportng', version:'1.1.4'
compile group: 'org.apache.velocity', name: 'velocity', version:'1.7'
compile group: 'com.google.inject', name: 'guice', version:'4.0'
testCompile group: 'junit', name: 'junit', version:'3.8.1'
testCompile group: 'org.testng', name: 'testng', version:'6.9.4'
}
test{
useTestNG() {
suites "src/test/resources/BasicTestXML/LoginTesten.xml"
}
}
With the above build file I can perfectly run my automation test in jenkins, if I have a localhost running for the application.
But to make it less dependable of human interaction I want to have jenkins first build the web application and after that run the automation tests on the built web application.
Is this possible? And how can I make this happen?
Can I build them from git or do they need to be at the same location for this to happen?
The webapp is also an ant project so does this bring any difficulties?
If you want to make it even Jenkins independent, you can e. g. make your Gradle build trigger the Ant build that builds the web application and then deploy the result somewhere, starting a container to deploy to. Then after the tests are finished your gradle build can stop the running container again.