When i run my cucumber based project it behaves as though it cannot find the Steps classes - I can tell because the log on Jenkins is offering code snippets for implementation.
I'm using Gradle and I know there are issues with cucumber-jvm.
The relevant part of the build file:
task cucumber(type: JavaExec) {
dependsOn assemble, compileTestJava
main = "cucumber.api.cli.Main"
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
args = ['-f', 'pretty', '--glue', 'steps', 'src/test/resources']
systemProperties = System.getProperties()
}
I can't see why running the same command (./gradlew clean cucumber) via Jenkins fails?
Here's the output from Jenkins:
+ ./gradlew -Dapk=/Users/rakesh/workspace1/AcmeApp_4_10_Tiles/bin/AcmeApp_4_10_Tiles.apk clean cucumber
:clean
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar
:assemble
:compileTestJava
:cucumber
Feature: Thrid party request for the Landing page.
TODO: additional requests for box connection
...
You can implement missing steps with the snippets below:
#Given("^the user chooses not to login$")
...
BUILD SUCCESSFUL
Total time: 8.074 secs
$ /Users/rakesh/Apps/adt-bundle-mac-x86_64-20131030/sdk/platform-tools/adb disconnect emulator-5812
[android] Stopping Android emulator
[android] Archiving emulator log
$ /Users/rakesh/Apps/adt-bundle-mac-x86_64-20131030/sdk/platform-tools/adb kill-server
Finished: SUCCESS
I would also like to mention that sometimes this problem occurs,if there are dependencies missing in build.gradle.
In my case,the following statement was missing in main task in build.gradle..
dependsOn assemble, compileTestJava
Adding this,resolved the issue.
I solved the problem and it had nothing to do with cucumber, gradle or Jenkins! I had renamed the steps classes (case change) which completely confused subversion and the java step classes were actually missing!!
Related
I am running Idea 2020.1.3 Ultimate.
I have created a Gradle project with Gradle 6.5.1 and Junit 5.6.2.
When running a simple test that only prints output to the screen, I see that after each line, Idea adds a blank line. This is making analyzing the results very difficult, since it doubles and triples the output.
This issue doesn't restore when running Gradle from command line.
It does restore when running with TestNG instead of JUnit.
It was also restored with JUnit 4 versions.
Any ideas?
Test Code:
#Test
public void testDummy(){
System.out.println("line1");
System.out.println("line2");
System.out.println("line3");
}
Test output (The blank lines are from the output):
Output:
Testing started at 13:29 ...
> Task :compileJava UP-TO-DATE
> Task :processResources NO-SOURCE
> Task :classes UP-TO-DATE
> Task :compileTestJava UP-TO-DATE
> Task :processTestResources NO-SOURCE
> Task :testClasses UP-TO-DATE
> Task :test
line1
line2
line3
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.5.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD SUCCESSFUL in 839ms
3 actionable tasks: 1 executed, 2 up-to-date
13:29:19: Task execution finished ':test --tests "org.example.tests.DummyTest.testDummy"'.
build.gradle file:
plugins {
id 'java'
id 'idea'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
// https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.6.2'
}
test {
useJUnitPlatform()
testLogging {
outputs.upToDateWhen {false}
showStandardStreams = true
}
}
It's a known bug. The fix is planned for 2020.3.
I ran your tests from the console and everything was correct. Looks like IntelliJ is adding these blank lines to your output. If you want to get rid of them, consider running your tests from the console (or the IntelliJ terminal).
Anyway, I found a way to trick IntelliJ to stop adding blank lines to your output. Instead of using System.out.println, use System.out.print and then flush the PrintStream. You should use a simple function to do this, like:
private void log(String message) {
System.out.print(message);
System.out.flush();
}
and then invoke
log("line1");
log("line2");
log("line3");
which produces the following output:
...
> Task :test
line1
line2
line3
Overview
There is an issue when attempting to migrate a Kotlin AppEngine project from an old MacBook Pro (MBP) to a new MBP, when running the Main method and building a .jar file locally.
The Main method in IntelliJ fails intermittently on the new MBP. The old .jar runs as expected on the new MBP, and the new .jar runs as expected on the old MBP.
Expected
Run existing local .jar file from Kotlin project on the old MBP.
Clone Kotlin project from GitHub repository into local IntelliJ project on new MBP.
Build .jar on new MBP.
Run .jar on new MBP.
Host .jar on Google AppEngine instance.
Observed
Running .jar on existing MBP works as expected.
Running main method with the same code runs intermittently on the new MBP after the GitHub repo is cloned locally.
Error
The Main method runs on the old MBP as expected, but not on the new MBP with the following error.
Exception in thread "Timer-0" com.google.cloud.storage.StorageException: 401 Unauthorized
at com.google.cloud.storage.spi.v1.HttpStorageRpc.translate(HttpStorageRpc.java:229)
at com.google.cloud.storage.spi.v1.HttpStorageRpc.create(HttpStorageRpc.java:310)
at com.google.cloud.storage.StorageImpl$3.call(StorageImpl.java:196)
at com.google.cloud.storage.StorageImpl$3.call(StorageImpl.java:193)
at com.google.api.gax.retrying.DirectRetryingExecutor.submit(DirectRetryingExecutor.java:105)
at com.google.cloud.RetryHelper.run(RetryHelper.java:76)
at com.google.cloud.RetryHelper.runWithRetries(RetryHelper.java:50)
at com.google.cloud.storage.StorageImpl.internalCreate(StorageImpl.java:192)
at com.google.cloud.storage.StorageImpl.create(StorageImpl.java:154)
at content.SaveContentKt.saveContent(SaveContent.kt:38)
at content.ContentTasks.generateContent(ContentTasks.kt:55)
at content.ContentTasks.run(ContentTasks.kt:41)
at java.base/java.util.TimerThread.mainLoop(Timer.java:556)
at java.base/java.util.TimerThread.run(Timer.java:506)
Caused by: com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unauthorized
at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:150)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:554)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:474)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:591)
at com.google.cloud.storage.spi.v1.HttpStorageRpc.create(HttpStorageRpc.java:307)
... 12 more
Configuration
The gradle-wrapper.properties Gradle, IntelliJ Preferences Gradle JVM, Project SDK, Run/Debug Configurations JRE, and Project language level versions are the same across both machines.
Preferences > Gradle
Use Gradle from: 'gradle-wrapper.properties' file
Gradle JVM: Library/Java/JavaVirtualMachines/12.0.1
File > Project Structure... > Project
Project SDK: 12.0.1
Project language level: 11
Running .jar file: Project Structure > Project Settings > Artifacts > Add > JAR > From modules with dependencies...
Module: coinverse-media.main
Main Class: Initialization
Lastly, build artifact and run .jar file.
build.gradle
buildscript {
ext.kotlin_version = '1.3.61'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.2.51'
}
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
implementation 'com.squareup.retrofit2:retrofit:2.7.0'
implementation 'com.squareup.retrofit2:converter-gson:2.7.0'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.7.0'
implementation 'com.google.firebase:firebase-admin:6.12.0'
implementation 'com.google.cloud:google-cloud-storage:1.102.0'
implementation 'com.google.apis:google-api-services-youtube:v3-rev20190827-1.30.1'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
Attempted Solutions
Invalidate Caches / Restart...: This appears to fix the issue for a few times running the Main method, then the error continues to show.
./gradlew clean build
Gradle > Reimport All Gradle Projects
Updating to the latest Gradle version.
Ensure existing MBP and new MBP are running on the same IntelliJ/Project/Run configurations.
Potentially related build dependency conflict issue: Guava Dependency Breaking Jar Built With Kotlin.
Build Data
Build scan results
Stack trace
6:09:42 PM: Executing task 'assemble'...
Task :compileKotlin UP-TO-DATE
Task :compileJava NO-SOURCE
Task :processResources NO-SOURCE
Task :classes UP-TO-DATE
Task :inspectClassesForKotlinIC UP-TO-DATE
Task :jar UP-TO-DATE
Task :assemble UP-TO-DATE
BUILD SUCCESSFUL in 75ms
3 actionable tasks: 3 up-to-date
6:09:42 PM: Task execution finished 'assemble'.
Hidden files
I would like to make releaseBuild task that will execute clean task before building project.
I have prepared script that works great to do clean before releaseBuild task, not cleaning just before finishing thanks to jar.mustRunAfter(clean).
However, I would like also to have possibility to execute publishToMavenLocal task that will be done only after releaseBuild finish successfully (so cleaning and building). Then there is problem.
plugins {
id 'java'
id 'maven-publish'
}
group 'com.example'
version '1.0-SNAPSHOT'
task releaseBuild {
outputs.upToDateWhen { false }
// generatePomFileForMavenJavaPublication.mustRunAfter(clean)
jar.mustRunAfter(clean)
releaseBuild.dependsOn(clean, build)
}
publishToMavenLocal.dependsOn(releaseBuild)
publishing {
publications {
mavenJava(MavenPublication) {
pom {
from components.java
packaging 'jar'
}
}
}
}
gradle releaseBuild works well.
gradle publishToMavenLocal shows the error:
> Task :generatePomFileForMavenJavaPublication
> Task :clean
> Task :compileJava NO-SOURCE
> Task :processResources NO-SOURCE
> Task :classes UP-TO-DATE
> Task :jar
> Task :publishMavenJavaPublicationToMavenLocal FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':publishMavenJavaPublicationToMavenLocal'.
> Failed to publish publication 'mavenJava' to repository 'mavenLocal'
> java.io.FileNotFoundException: __path__\build\publications\mavenJava\pom-default.xml (System nie może odnaleźć określonej ścieżki -- File not found)
The clean is after generating pom file.
When I uncomment line with generatePomFileForMavenJavaPublication.mustRunAfter(clean), I've got error:
> Could not get unknown property 'generatePomFileForMavenJavaPublication' for task ':releaseBuild' of type org.gradle.api.DefaultTask.
Add at the end of your script.
publishMavenJavaPublicationToMavenLocal.mustRunAfter(clean)
There is a task-tree plugin which is very helpful in such situations.
It is handy to distinguish between Configuration and Execution phases of Gradle build when fine-tuning tasks configuration. It will help if you read about Build Lifecycle.
Adding dependencies to the clean task usually gives more headache than benefit. Consider adding only "soft" dependencies like mustRunAfter and add clean task explicitly to your command line:
gradle clean releaseBuild publishToMavenLocal
I'm trying to write a BitBucket Pipeline script for my repository, but so far without much luck, because Gradle seems a pain to debug.
Is there any way to show the resulting files (from compiling the jar for example) in the console when it finishes the : build task?
Preferably I'd like to see as much information as possible, rather too much than too little.
Adding logging.captureStandardOutput LogLevel.DEBUG in my build.gradle file didn't seem to do much, still getting the same output:
:compileJavaNote: -snip-\src\main\java\com\-snip-\atlas\utility\SchematicUtil.java uses or overrides a deprecated API.
Note: Recompile with -Xlint: deprecation for details.
:processResources
:classes
:jar
:assemble
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build
BUILD SUCCESSFUL
Total time: 1.16 secs
Here's one way to do it (e.g. jar for a simple Java project). The build.gradle is:
apply plugin: 'java'
jar {
doLast {
new File("${buildDir}/libs").eachFileRecurse { file ->
println "TRACER: ${file.getAbsolutePath()}"
}
}
}
It should be straight-forward to tailor for other needs.
I am actually using the newly released Gradle 2, but having the same issues as described in the previous post.
I am also a newb trying to follow the example given in the Spring guide (http://spring.io/guides/gs/gradle/#scratch) but after my first compile, there were no classes.
I have tried various configurations of tree structure including adding the structure and code suggested in the above thread:
"I guess the source file path is src/org/gradle/example/simple/HelloWorld.java. (The diagram shows something different.) That doesn't match Gradle's default, so you'll have to reconfigure it: sourceSets.main.java.srcDirs = ["src"] – Peter Niederwieser Dec 7 '12 at 1:23 "
adding the line: sourceSets.main.java.srcDirs = ["src"] allows the code to compile, however, I still have no classes.
Here is the successful build.
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:jar UP-TO-DATE
:assemble UP-TO-DATE
:compileTestJava UP-TO-DATE
:processTestResources UP-TO-DATE
:testClasses UP-TO-DATE
:test UP-TO-DATE
:check UP-TO-DATE
:build UP-TO-DATE
BUILD SUCCESSFUL
Total time: 4.468 secs
Here is the build file:
apply plugin: 'java'
sourceSets.main.java.srcDirs=["src"]
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
compile "joda-time:joda-time:2.2"
}
jar {
baseName = 'gs-gradle'
version = '0.1.0'
}
task wrapper(type:Wrapper) {
gradleVersion = '1.11'
}
apply plugin: 'application'
mainClassName = 'hello.HelloWorld'
Where are my classes? Please help.
After I got stuck with the same problem, I hacked around for a bit before I understood the reason for this behavior.
My project structure was like so
MyProject
- src
- main
- java
- hello
HelloWorld.java
build.gradle
The problem was that the build.gradle is supposed to be under the Project-Root folder i.e. MyProject and not under the hello folder !!!
Changed it so that my Project structure looks like below, ran the gradle build and saw that classes folder was created:
MyProject
- src
- main
- java
- hello
HelloWorld.java
build.gradle
When you think about it, the build.gradle is used to build the complete project and not just the classes within one folder and should rightfully sit under the project-root folder.