jenkins-docs/simple-java-maven-app

Jenkins tutorial failing due to maven 3.8.1 and Tests not passing

ricardogarceb opened this issue · 5 comments

Hi.

So I'm learning a bit of Jenkins and found 2 problems when using this Git project following the tutorial for Building a Java app and Maven with Jenkins.
I'm using Windows running Jenkins in Docker with Linux containers.

1st problem, it cannot Build the project because Jenkinsfile suggested by documentation or tutorial uses maven:3.8.1-adoptopenjdk-11 but enforcer complains it should be at least 3.8.6, so I had to manually change it in Jenkinsfile to maven:3.8.6-openjdk-18 for this to build.

2nd problem, it cannot pass Tests. It always says "message" is not "Hello World!".
I tried everything I barely know, saving string to variables, using compareTo(), using equals(), checking the strings with println... no matter what I tried it always returns erro and I cannot finish the tutorial. I printed AssertionError e message and it shows this trace:

-------------------------------------------------------
 T E S T S
-------------------------------------------------------

Running com.mycompany.app.AppTest
Hello World!
org.opentest4j.AssertionFailedError: expected: <Hello World!
> but was: <>
Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.017 sec <<< FAILURE!
com.mycompany.app.AppTest.testAppMain()  Time elapsed: 0.015 sec  <<< FAILURE!
org.opentest4j.AssertionFailedError: "message" is not "Hello World!"
	at org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:38)
	at org.junit.jupiter.api.Assertions.fail(Assertions.java:135)
	at com.mycompany.app.AppTest.testAppMain(AppTest.java:43)

Results :

Failed tests:   com.mycompany.app.AppTest.testAppMain(): "message" is not "Hello World!"

Tests run: 2, Failures: 1, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.572 s
[INFO] Finished at: 2022-12-19T11:56:12Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test (default-test) on project my-app: There are test failures.
[ERROR] 
[ERROR] Please refer to /var/jenkins_home/workspace/simple-java-maven-app/target/surefire-reports for the individual test results.

Jenkins test failed

I'm out of ideas. I'm very limited at Java, Jenkins and so and I cannot understand why an official tutorial does not work by default, but no documentation is provided to workaround any errors. I'm very frustrated.
I saw this project was updated 2 days ago. Was it not tested? Was it tested following the Jenkins tutorial? Using Windows?

Thanks for the report. I believe the failing test is intentional and is part of the tutorial. I'll double check.

I've updated Apache Maven, Blue Ocean, and Pipeline Groovy plugins with:

Also fixed the test in the source code and significantly simplified the test so that it would run on Java 11.

Just to add to this I reviewed the code on GitHub and found this commit on pom.xml "[Mak this work on Java 17 onwards]" and inside the xml file it only supports java 11

so I downloaded Java 11 open jdk and tried it again and it works fine without any errors. It is not compatible with other versions as of now. Should have noticed it earlier but thanks again.

@ricardogarceb @MarkEWaite

so I downloaded Java 11 open jdk and tried it again and it works fine without any errors. It is not compatible with other versions as of now. Should have noticed it earlier but thanks again.

I cloned https://github.com/jenkins-docs/simple-java-maven-app.git and built it with Java 17.0.5 and Apache Maven 3.8.6. The pom.xml file defines that it needs Java 11 or newer. The Jenkins project supports Java 11 and Java 17. As far as I can tell, this sample Java application compiles with both Java 11 and Java 17.