Can a module-info.java 'opens' statement include a package and all sub-packages?

Currently no, as the JLS defines a module declaration as a list of directives where each directive has the below syntax:

ModuleDirective:
     requires {RequiresModifier} ModuleName ;
     exports PackageName [to ModuleName {, ModuleName}] ;
     opens PackageName [to ModuleName {, ModuleName}] ;
     uses TypeName ;
     provides TypeName with TypeName {, TypeName} ; 

The same syntax applies for both exports and opens: no wildcards are allowed in the package name. Maybe that could be improved in the future, but I think it would be a bad practice, similar to the bad practice of using such wildcards in import statements.


You can use open module to open all packages (internal or not) to all modules. I don't think there's any intermediate granularity.

open module foo.microservice {
  requires spring.core;
  requires spring.beans;
  requires spring.context;
  requires java.sql; // required for Spring Annotation based configuration :(

  exports foo.microservice.configuration;
  exports foo.microservice.controllers;
  exports foo.microservice.models;
  exports foo.microservice.services;
}

(copied from Alexey Romanov's comment)