title: Classes and packages encapsulation in an hexagonal architecture
body: <p>I would like to know if in Java (JDK 17) there is a way to easily handle classes and packages encapsulation in an hexagonal architure. I would like to make unavailable classes present in an <code>adapter</code> to the domain.
  To illustrate my goal, say we have this package organisation:</p>
  <pre><code>com.company
             |-domain
                    |-model
                          |-Customer.java
                          |-Product.java
                    |-ports
                          |-DbPort.java
                          |-ServiceBusPort.java
                    |-services
                             |-CustomerService.java
                             |-ProductService.java
             |-adapters 
                     |-inbound
                             |-rest
                                 |-CustomerRestAdapter.java
                                 |-ProductRestAdapter.java
                             |-bus
                                 |-ServiceBusAdapter.java
                                 |-RabbitAdapter.java
                     |-outbound
                             |-db
                                |-entities
                                        |-Customer.java
                                        |-Product.java
                                |-repositories
                                        |-CustomerRepository.java
                                        |-ProductRepository.java
                                |-mappers
                             |-bus
                                 |-dtos
                                     |-CutomerDto.java
                                     |-ProductDto.java
                                 |-mappers
  </code></pre>
  <p>What I want to achieve is: all classes and packages under <code>com.company.adapters</code> should not be visible from the <code>com.company.domain</code> package. The goal is to prevent developers to use for example the class <code>com.company.adapters.outbound.db.entities.Customer</code> in <code>com.company.domain.services.CustomerService</code>. But classes inside <code>com.company.domain</code> should be accessible from everywhere.</p>