NoClassDefFoundError when hudson runs a maven project - maven

I have a project for running tests. It's a maven project which uses Selenium. It runs correctly when launched locally, but from the Hudson platform, it throws NoClassDefFoundError:
Parsing POMs
[elsevier-selenium] $ "C:\Program Files\Java\jdk1.7.0_25/bin/java" -Xmx1024m -cp E:\hudson\plugins\maven-plugin\WEB-INF\lib\maven-agent-1.353.jar;E:\maven\boot\classworlds-1.1.jar hudson.maven.agent.Main E:\maven E:\hudson\war\WEB-INF\lib\remoting-1.353.jar E:\hudson\plugins\maven-plugin\WEB-INF\lib\maven-interceptor-1.353.jar 1753 E:\hudson\plugins\maven-plugin\WEB-INF\lib\maven2.1-interceptor-1.2.jar
<===[HUDSON REMOTING CAPACITY]===>channel started
Executing Maven: -B -f E:\hudson\jobs\tests-selenium\workspace\elsevier-selenium\pom.xml integration-test
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building selenium-elsevier
[INFO] task-segment: [integration-test]
[INFO] ------------------------------------------------------------------------
[INFO] [compiler:testCompile {execution: default}]
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 5 source files to E:\hudson\jobs\tests-selenium\workspace\elsevier-selenium\target\test-classes
[INFO] [site:attach-descriptor {execution: default-attach-descriptor}]
[INFO] [failsafe:integration-test {execution: default}]
[INFO] Failsafe report directory: E:\hudson\jobs\tests-selenium\workspace\elsevier-selenium\target\failsafe-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running fr.elsevier.tests.disponibilite.SearchTest
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.203 sec <<< FAILURE!
fr.elsevier.tests.disponibilite.SearchTest Time elapsed: 0.203 sec <<< ERROR!
java.lang.NoClassDefFoundError: Could not initialize class fr.elsevier.tests.BaseSelenium
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at org.apache.maven.surefire.report.SmartStackTraceParser.getClass(SmartStackTraceParser.java:63)
at org.apache.maven.surefire.report.SmartStackTraceParser.<init>(SmartStackTraceParser.java:53)
at org.apache.maven.surefire.common.junit4.JUnit4StackTraceWriter.smartTrimmedStackTrace(JUnit4StackTraceWriter.java:72)
[...]
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:124)
SearchTest extends BaseSelenium.
Which means it cannot even find a class in my source folder. The project structure is like this:
src/
fr.elsevier.tests/
disponibilite/
SearchTest.java
BaseSelenium.java
pom.xml
Why does the build generates these NoClassDefFoundErrors and how to fix it?

Try using -e or -X command line argument in local and hudson build. Then try to compare the classpath of the java processes launched.
You can then actually figure out which part of maven lifecycle threw the exception with better stacktrace.

Related

Jenkins job produces a successful build without completing the pipeline [duplicate]

I configure my job as freestyle. And I need to run cases to a specified machine. MY project is maven project. I want to copy reports to master node after cases finish to run.
Jenkins ver. 1.483
I use pscp to copy files which works fine by hand in windows command prompt.
My command looks like:
mvn clean install -U
pscp -P 22 -i pgrsa.ppk -r %SLAVE_JENKINS_HOME%\workspace\%JOB_NAME%\target\surefire-reports ci#master:%JENKINS_HOME%/workspace/%JOB_NAME%
The pscp seems not work. When I use command like this:
echo EchoCommand is working.===
mvn clean install -U
echo EchoCommand is working again.===
EchoCommand is working again.===Not show at the output of the console while EchoCommand is working.=== has been shown. Why? Anyone knows that?
EDIT
C:\Tools\Jenkins\workspace\myproject-testng-sample-windows>echo EchoCommand is working.===
EchoCommand is working.===
C:\Tools\Jenkins\workspace\myproject-testng-sample-windows>mvn clean install -U
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.pak.automation:myproject-testng-sample:jar:1.0.0-SNPASHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-deploy-plugin is missing. # com.pak:pak-parent:2.0.0, C:\Users\pak\.m2\repository\com\pak\pak-parent\2.0.0\pak-parent-2.0.0.pom, line 484, column 12
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-source-plugin is missing. # com.pak:pak-parent:2.0.0, C:\Users\pak\.m2\repository\com\pak\pak-parent\2.0.0\pak-parent-2.0.0.pom, line 472, column 12
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building myproject-testng-sample 1.0.0-SNPASHOT
[INFO] ------------------------------------------------------------------------
Downloading: http://mvn.pak.com/pakrepo/org/apache/maven/plugins/maven-source-plugin/maven-metadata.xml
Downloading: http://mvn.pak.com/pak-releases/org/apache/maven/plugins/maven-source-plugin/maven-metadata.xml
Downloading: http://mvn.pak.com/pak-snapshots/org/apache/maven/plugins/maven-source-plugin/maven-metadata.xml
Downloading: http://mvn.pak.com/third-party/org/apache/maven/plugins/maven-source-plugin/maven-metadata.xml
377/377 B
377/377 B 377/377 B
Downloaded: http://mvn.pak.com/third-party/org/apache/maven/plugins/maven-source-plugin/maven-metadata.xml (377 B at 1.5 KB/sec)
Downloaded: http://mvn.pak.com/pakrepo/org/apache/maven/plugins/maven-source-plugin/maven-metadata.xml (377 B at 1.4 KB/sec)
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # myproject-testng-sample ---
[INFO] Deleting C:\Tools\Jenkins\workspace\myproject-testng-sample-windows\target
[INFO]
[INFO] --- maven-resources-plugin:2.3:resources (default-resources) # myproject-testng-sample ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Tools\Jenkins\workspace\myproject-testng-sample-windows\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.0.2:compile (default-compile) # myproject-testng-sample ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.3:testResources (default-testResources) # myproject-testng-sample ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Tools\Jenkins\workspace\myproject-testng-sample-windows\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.0.2:testCompile (default-testCompile) # myproject-testng-sample ---
[INFO] Compiling 4 source files to C:\Tools\Jenkins\workspace\myproject-testng-sample-windows\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # myproject-testng-sample ---
[INFO] Surefire report directory: C:\Tools\Jenkins\workspace\myproject-testng-sample-windows\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running TestSuite
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator#4d20a47e
testMethod1
testMethod2
testMethodmyproject2
testmyprojectSample
testMethod1
testMethod2
testMethodmyproject2
testmyprojectSample
we wont run test with class name: com.pak.myproject.sample.NoInjectionTest
we wont run test with class name: com.pak.myproject.sample.NoInjectionTest
I am test method 2
parameter in test method is: firstname
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.895 sec
Results :
Tests run: 4, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # myproject-testng-sample ---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar: C:\Tools\Jenkins\workspace\myproject-testng-sample-windows\target\myproject-testng-sample-1.0.0-SNPASHOT.jar
[INFO]
[INFO] >>> maven-source-plugin:2.1.1:jar (attach-sources) # myproject-testng-sample >>>
[INFO]
[INFO] <<< maven-source-plugin:2.1.1:jar (attach-sources) # myproject-testng-sample <<<
[INFO]
[INFO] --- maven-source-plugin:2.1.1:jar (attach-sources) # myproject-testng-sample ---
[INFO] No sources in project. Archive not created.
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) # myproject-testng-sample ---
[INFO] Installing C:\Tools\Jenkins\workspace\myproject-testng-sample-windows\target\myproject-testng-sample-1.0.0-SNPASHOT.jar to C:\Users\pak\.m2\repository\com\pak\automation\myproject-testng-sample\1.0.0-SNPASHOT\myproject-testng-sample-1.0.0-SNPASHOT.jar
[INFO] Installing C:\Tools\Jenkins\workspace\myproject-testng-sample-windows\pom.xml to C:\Users\pak\.m2\repository\com\pak\automation\myproject-testng-sample\1.0.0-SNPASHOT\myproject-testng-sample-1.0.0-SNPASHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.649 s
[INFO] Finished at: 2014-04-08T13:19:58+08:00
[INFO] Final Memory: 10M/24M
[INFO] ------------------------------------------------------------------------
Recording test results
TestNG Reports Processing: START
mvn is a batch file. So It is need to call mvn .... Not just mvn ....
See call-batch-file-from-cygwin-breaks-after-1st-command
This could be due to an environment problem. You could, however, save yourself a lot of time and work by doing things a little bit different:
Make your job a Maven Project, makes configuration easier (and offers you nice features like test reports for single modules etc.). This might also make your report copying unneccessary.
Depending on what you want to do with these reports afterwards, you could simple use the Jenkins archiving mechanism to copy them over to your master.
if you REALLY need to copy them by hand, use the Publish Over SSH Jenkinsn plugin
Are you using Execute Shell in your free-style project, i.e. you are running on a *nix based environment? If so, your problem is detailed in my answer here:
Jenkins Build Script exits after Google Test execution
Jenkins launches Execute Shell as a temporary shell script with command /bin/sh -xe tempshell.sh. Note the -e part. This tells sh to exit when any single command in the script returns with non-zero value.
Your mvn clean install -U is probably returning with a non-zero value. You can check that by running it on command line, immediately followed by echo $?
Solution: To circumvent that, add set +e to the top of your Execute Shell script.
The problem may be that you are not giving enter after the last command.
Today I came across the same problem in our project, last command in jenkins is not executed.
After some trail and error methods, came to understand that.

Run maven project without testng from Jenkins

I am working on selenium and have created a maven project with user creation and user registration in Eclipse. There is no TESTNG involved in this implementation.
Now, I have created a maven job in Jenkins and configured the pom.xml path and goal set as 'clean install'.
While running this maven job from Jenkins, the build is success but none of the scripts from Eclipse ran for user creation and user registration.
I am seeing the below in the console output in Jenkins against the Job:
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # GDPortalDemo ---
[INFO] Surefire report directory: C:\RSV\Selenium\GDPortalDemo\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[JENKINS] Recording test results
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # GDPortalDemo---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar: C:\RSV\Selenium\GDPortalDemo\target\GDPortalDemo-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) # GDPortalDemo---
[INFO] Installing C:\RSV\Selenium\GDPortalDemo\target\HybridSauceDemo-0.0.1-SNAPSHOT.jar to C:\Users\daisy\.m2\repository\GDPortalDemo\GDPortalDemo\0.0.1-SNAPSHOT\GDPortalDemo-0.0.1-SNAPSHOT.jar
[INFO] Installing C:\RSV\Selenium\GDPortalDemo\pom.xml to C:\Users\daisy\.m2\repository\GDPortalDemo\GDPortalDemo\0.0.1-SNAPSHOT\GDPortalDemo-0.0.1-SNAPSHOT.pom
Earlier, I had sure-fire plugin in my pom.xml. I have removed that plugin from pom.xml now and then executed the job.
Can we run a maven job from Jenkins that doesn't have testng tests? In my project, we are not going to use testng. Appreciate any help on this please.

VSTS Maven build - no JUnit tests run

[Update: Problem cause found! read below]
Problem: VSTS Maven build does not seem to run JUnit, does not show any JUnit results, does not seem to produce any JUnit testreports.
In VSTS, we have a Java project with a Contact and TestContact class with 1 testcase;
source\module\src\main\java\nl\customer\model\situation\Contact.java
source\module\src\test\java\nl\customer\model\ContactTest.java
source\module\pom.xml
Running Maven from Eclipse works fine. Console shows Maven using Surefire reports, running/passing the 1 unit test.
Running the project with Maven on a Windows PC also works:
mvn test
Logging:
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Domain Model
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # module ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 30 resources
[INFO] skip non existing resourceDirectory C:\project\source\projectdomain\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # module ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # module ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\project\source\module\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # module ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.20.1:test (default-test) # module ---
[INFO]
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running nl.customer.module.ContactTest
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.002 s - in nl.customer.module.ContactTest
[INFO]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.109 s
[INFO] Finished at: 2018-01-09T14:05:03+01:00
[INFO] Final Memory: 10M/196M
[INFO] ------------------------------------------------------------------------
In VSTS, using the Maven build step (goal: install) succeeds, but the log does not show anything about JUnit, even with system.debug = true.
Consequently, trying the "Publish test results" always fails (both when using a seperate build task or the Publish TFS option in the maven build task).
It seems I have found the cause of the problem: in VSTS, the Maven build task has the option
Set MAVEN_OPTS to
In our build definition, this was set to
-Xmx1024m -X
The first parameter is correct, it sets the maximum memory.
The second parameter is incorrect. If you want Maven to give debug output, you should put the "-X" parameter under Goal(s).
There is no real warning about the second parameter in the logging.

How to compile all maven modules even if tests fail, but fail overall build if any tests fail

Context: I want to compile and test all modules in a multi-module project but if any fail either compilation or tests I want the overall build to fail.
Default configurations either stop on the first failure or skip modules after a test failure
Running:
mvn clean install
stops at the first failing module.
If you add:
mvn clean install -fae //fail at end
then all modules are run, but if tests fail then any dependent modules are skpped:
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] ------------------------------------------------------------------------
[INFO] Module A ............................................. SUCCESS [15.210s]
[INFO] Module B ............................................. SUCCESS [10.923s]
[INFO] Module C ............................................. FAILED [1.731s]
[INFO] Module D ............................................. SUCCESS [3.791s]
[INFO] Module E ............................................. SUCCESS [1.488s]
[INFO] Module F ............................................. SKIPPED (dependency build failed or was skipped)
[INFO] Module G ............................................. SKIPPED (dependency build failed or was skipped)
[INFO] Module H ............................................. SKIPPED (dependency build failed or was skipped)
[INFO] Module I ............................................. SUCCESS [1.690s]
[INFO] -----------------------------------------
Another option to force all modules to compile is:
mvn clean install -fn //fail never
but this results in the build passing when tests fail
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] ------------------------------------------------------------------------
[INFO] Module A ............................................. SUCCESS [15.210s]
[INFO] Module B ............................................. SUCCESS [10.923s]
[INFO] Module C ............................................. FAILED [1.731s]
[INFO] Module D ............................................. SUCCESS [3.791s]
[INFO] Module E ............................................. SUCCESS [1.488s]
[INFO] Module F ............................................. SUCCESS [9.062s]
[INFO] Module G ............................................. SUCCESS [16.324s]
[INFO] Module H ............................................. SUCCESS [4.032s]
[INFO] Module I ............................................. SUCCESS [1.690s]
[INFO] ------------------------------------------------------------------------
[INFO] Error for project: Module C (during install)
[INFO] ------------------------------------------------------------------------
[INFO] There are test failures.
Please refer to C:\MavenBuildDir\ModuleC\surefire-reports for the
individual test results.
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] + Ignoring failures
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 30 minutes 38 seconds
[INFO] Finished at: Fri May 23 16:42:08 BST 2014
[INFO] Final Memory: 39M/185M
Can anyone advise a set of options to achieve the following:
compile all modules
run tests on all modules
If a module's tests fail but the code compiles dependent modules still get compiled and tested
Responses much appreciated - otherwise we have to run the tests repeatedly on the build server if there are multiple issues - burning a lot of time.
I would suggest to use:
mvn -Dmaven.test.failure.ignore=true --fail-at-end clean install
I would suggest to split it into two mvn calls:
mvn clean compile
mvn -fae install
The first call will fail, if there are compile errors. The second call will reuse the compiled .class-files, since "clean" is omitted. It will fail at the end, if there are test failures. But compilation has already been finished for ALL modules.
Here is a different approach: parse maven output. So either you
pipe it into some grep like command:
mvn clean install -fn | perl -pe 'END { exit $status } $status=1 if /BUILD FAILURE/;'
See https://github.com/backuitist/maven-fae-seriously
configure your CI server to do it:
See https://stackoverflow.com/a/28683700/303737

No line-after-line output from #Test block when running JUnit test with maven

I have a Junit test running under maven with
mvn clean test -Dtest=MyTest
The output looks as following:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building autotest-tests
[INFO] task-segment: [clean, test]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean {execution: default-clean}]
[INFO] Deleting directory workspace/tests/target
[INFO] [compiler:testCompile {execution: compile tests}]
[INFO] Compiling 76 source files to workspace/tests/target/test-classes
[INFO] [surefire:test {execution: run tests}]
[INFO] Surefire report directory: workspace/tests/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Concurrency config is parallel='classes', perCoreThreadCount=true, threadCount=2, useUnlimitedThreads=false
Output of #Before block...
Output of #Before block...
Output of #Before block...
Then the output stops. Any line by line output to command line from the #Test block is held back I see them on the console only after the test is over:
Output of #Test block...
Output of #Test block...
Output of #Test block...
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 75.564 sec
Results :
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 minute 18 seconds
[INFO] Finished at: Mon Feb 06 12:22:22 CET 2012
[INFO] Final Memory: 24M/302M
[INFO] ------------------------------------------------------------------------
I did work before, i.e. I was getting a line by line test output on the console as the test was proceeding. Since some time (maybe an update) stopped.
Any ideas what is the reason behind it?
The surefire plugin write the output to a file by default. This can be controlled with the useFile option, which can be set from the command line:
-Dsurefire.useFile=false
It is also possible to set this as a default value in your settings.xml by creating and activating a profile:
<profiles>
<profile>
<id>sureFire.useFile</id>
<properties>
<surefire.useFile>false</surefire.useFile>
</properties>
</profile>
</profile>
<activeProfiles>
<activeProfile>sureFire.useFile</activeProfile>
</activeProfiles>

Resources