maven-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lukáš Křečan (JIRA) <>
Subject [jira] [Commented] (SUREFIRE-1531) Option to switch-off Java 9 modules
Date Sun, 01 Jul 2018 19:16:00 GMT


Lukáš Křečan commented on SUREFIRE-1531:

The test case:
import org.junit.Test;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.scheduling.TaskScheduler;

import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.mock;

public class SimpleTest {

    public void test() {
        MyScheduler mock = mock(MyScheduler.class);

    interface MyScheduler extends TaskScheduler, DisposableBean {


Fails with:
Underlying exception : java.lang.IllegalStateException: Error invoking (accessor)::defineClass
	at shedlock.example/net.javacrumbs.shedlockexample.SimpleTest.test(
Caused by: java.lang.IllegalStateException: Error invoking (accessor)::defineClass
	at shedlock.example/net.javacrumbs.shedlockexample.SimpleTest.test(
Caused by: java.lang.IllegalAccessError: class org.mockito.codegen.MyScheduler$MockitoMock$1440016807
cannot access its superinterface net.javacrumbs.shedlockexample.SimpleTest$MyScheduler
	at shedlock.example/net.javacrumbs.shedlockexample.SimpleTest.test(

> Option to switch-off Java 9 modules
> -----------------------------------
>                 Key: SUREFIRE-1531
>                 URL:
>             Project: Maven Surefire
>          Issue Type: Improvement
>          Components: Maven Surefire Plugin
>    Affects Versions: 2.22.0
>            Reporter: Lukáš Křečan
>            Priority: Major
> I am working on a library and I am adding support for Java 9 modules. Surefire 2.21.0
by default executes tests with Java 9 modules switched-on if it detects While
it may make sense in some cases, in my case I'd like the switch it off.
> The reason is simple. I am using Mockito to mock an interface that extends a Spring interface.
Mockito has to create an implementation of this interface (proxy or subclass) and for this
it needs to have access to the Spring interfaces. If Java 9 modules are enabled for the tests
I have to manually add each such dependencies to Surefire configuration, which does not make
much sense. To makes things worse, the interface actually extends two Spring interfaces form
two different Spring modules so the configuration is almost impossible to get right.
> So far I am at ( and I am still getting IllegalAccessErrors)
> {code:java}
> --add-exports spring.context/org.springframework.scheduling=org.mockito
> --add-exports spring.beans/org.springframework.beans.factory=org.mockito
> {code}
> I would prefer to switch-off the Java 9 modules for the test module altogether (same
behavior as pre 2.21.0)
> The test is here []
> If you want, I can send a pull request.

This message was sent by Atlassian JIRA

View raw message