Intermittent NoClassDefFoundError when running a maven/surefire build in jenkins

后端 未结 4 1782
天涯浪人
天涯浪人 2021-02-04 06:24

We are building a large multi module Maven project on Jenkins, including running a large number of unit test.

Once every few builds the build fails on NoClassDefF

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-04 06:55

    It seems you have a random classloading issue.

    The missing class appears since JUnit 4 : http://findjar.com/class/org/junit/runner/notification/RunListener.html

    You should try to analyse surfire classpath by :

    • execute : mvn -X clean test
    • open file : target\surefire\surefire5942929663635698632tmp

    You will see something like :

    surefireClassPathUrl.0=D\:\\maven2\\repository\\org\\apache\\maven\\surefire\\surefire-junit47\\2.17\\surefire-junit47-2.17.jar
    surefireClassPathUrl.1=D\:\\maven2\\repository\\org\\apache\\maven\\surefire\\common-junit48\\2.17\\common-junit48-2.17.jar
    surefireClassPathUrl.2=D\:\\maven2\\repository\\org\\apache\\maven\\surefire\\common-junit4\\2.17\\common-junit4-2.17.jar
    surefireClassPathUrl.3=D\:\\maven2\\repository\\org\\apache\\maven\\surefire\\common-junit3\\2.17\\common-junit3-2.17.jar
    surefireClassPathUrl.4=D\:\\maven2\\repository\\org\\apache\\maven\\surefire\\surefire-api\\2.17\\surefire-api-2.17.jar
    surefireClassPathUrl.5=D\:\\maven2\\repository\\org\\apache\\maven\\surefire\\common-java5\\2.17\\common-java5-2.17.jar
    surefireClassPathUrl.6=D\:\\maven2\\repository\\org\\apache\\maven\\shared\\maven-shared-utils\\0.4\\maven-shared-utils-0.4.jar
    surefireClassPathUrl.7=D\:\\maven2\\repository\\com\\google\\code\\findbugs\\jsr305\\2.0.1\\jsr305-2.0.1.jar
    surefireClassPathUrl.8=D\:\\maven2\\repository\\org\\apache\\maven\\surefire\\surefire-grouper\\2.17\\surefire-grouper-2.17.jar
    

    Try to ensure JUnit 3.x -and related jars- are not loaded.

    For example, you may try to exclude common-junit3 from surfire-junit47 :

    surfire-junit47 dependencies

                    
                        org.apache.maven.surefire
                        surefire-junit47
                        2.17
                        
                            
                                org.apache.maven.surfire
                                common-junit3
                            
                        
                    
    

提交回复
热议问题