I tried to use Java 9+ built-in JPMS(Java Platform Module System) to modulize a Spring Boot application, check the complete sample codes here.
In IDEA, when running the tests, it worked well.
But when I ran it via mvn clean verify in the root folder, and the greeting.application.test will fail due to an exception "can not find the package com.example.greeting.application and class GreetingApplication".
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project greeting-application-test: Compilation failure: Compilation fai
lure:
[ERROR] /D:/hantsylabs/spring-puzzles/modular-jpms/greeting-application-test/src/main/java/com/example/greeting/application/test/GreetingApplicationTests.java:[3,40] package com.exampl
e.greeting.application does not exist
[ERROR] /D:/hantsylabs/spring-puzzles/modular-jpms/greeting-application-test/src/main/java/com/example/greeting/application/test/GreetingApplicationTests.java:[13,19] cannot find symbo
l
[ERROR] symbol: class GreetingApplication
The module-info.java in the greeting.application.test like this.
module greeting.application.test {
requires greeting.application;
requires spring.web;
requires spring.core;
requires spring.beans;
requires spring.context;
requires spring.boot;
requires spring.boot.autoconfigure;
requires spring.webflux;
requires spring.test;
requires spring.boot.test;
requires spring.boot.test.autoconfigure;
requires org.junit.jupiter;
requires org.junit.jupiter.api;
requires org.junit.jupiter.params;
requires org.junit.jupiter.engine;
requires org.junit.platform.commons;
requires org.assertj.core;
requires org.mockito.junit.jupiter;
requires transitive net.bytebuddy;
opens com.example.greeting.application.test to spring.core, org.junit.platform.commons;
}