0

I'm migrating a maven java8 project to Java 11. All the source files and test files compiles successfully. There are tests that makes use of mockito/powermock. When I try to mvn clean install, the build fails because of the failures in tests. All the tests fails with the same cause (java.lang.ClassNotFoundException: org.mockito.cglib.proxy.MethodInterceptor) I'm using surefire plugin version 3.3.0-M3. Please see relevant sections in pom.xml below. Please help me to resolve these ClassNotFoundException and make the build success.

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>3.0.0-M3</version>
            <configuration>
                <argLine>
                    --illegal-access=permit
                </argLine>
            </configuration>
        </plugin>


   <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-core</artifactId>
        <version>2.23.0</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-api-mockito2</artifactId>
        <version>2.0.2</version>
        <scope>test</scope>
        <exclusions>
            <exclusion>
                <groupId>org.mockito</groupId>
                <artifactId>mockito-all</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-module-junit4</artifactId>
        <version>2.0.2</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.powermock</groupId>
        <artifactId>powermock-module-testng</artifactId>
        <version>2.0.2</version>
        <scope>test</scope>
    </dependency>

UPDATE:
The exception is coming from the APIs of following dependency which requires mockito 1.9.5.

<dependency>
    <groupId>com.googlecode.catch-exception</groupId>
    <artifactId>catch-exception</artifactId>
    <version>1.2.0</version>
    <scope>test</scope>
</dependency>
Master Po
  • 1,497
  • 1
  • 23
  • 42
  • Mockito 2+ no longer uses cglib. See https://stackoverflow.com/questions/43192045/mockito-core-2-7-19-and-cglib – JavaTechnical May 18 '20 at 06:26
  • @JavaTechnical That means my pom resolves an older version of mockito. right? Is there any issues with powermock and mockito combination? – Master Po May 18 '20 at 06:53
  • Yes, most likely. – JavaTechnical May 18 '20 at 06:57
  • I don't know of issues using both together, they should most likely work, but you can check if there are any version conflicts.. – JavaTechnical May 18 '20 at 07:03
  • This was thrown from a different dependency (catch-exception) that I have in my module which requires an older version of mockito. – Master Po May 21 '20 at 08:27
  • Since, mockito has the scope of `test`, I suppose that you can use different versions for each of your modules, unless and until you have any test dependencies. – JavaTechnical May 21 '20 at 17:02
  • If I understand correctly you are saying that I can specify mockito-core - 1.9.5 in module poms which requires the catch-exception. is that so? But I am running the goal from the master pom.xml I think there will be version conflicts – Master Po May 22 '20 at 13:55
  • You can remove the mockito dependencies in the *parent pom* and put them in each of the module pom.xml files. – JavaTechnical May 22 '20 at 15:12
  • Sure. I'll try it out. Its a big project having 14 modules – Master Po May 25 '20 at 05:17

0 Answers0