I have a multi-module Maven project, with modules 'app' and 'domain'. App depends on Domain. The domain module has public and private code. Public code is in the package **/domain/api/**
.
In the pom of the Domain module, I added an execution for the maven jar plugin, which generates an additional project artifact with classifier 'api' (containing only the public classes).
In the App module, I added a 'runtime' scoped dependency on the Domain module (so all classes are present at runtime) and I added a compile-time scoped dependency on the classified 'API'. This is to ensure the App modules only access public api code from the domain.
Everything compiles and runs. I have checked the contents of the api artifact from the domain module and it contains only the code intended to be public.
But in IntelliJ I'm still able to use (import) domain code from private packages. IntelliJ seems to ignore the classifier part. So IntelliJ compiles when I reference private code (which is wrong IMHO) and the Maven build fails (which is good).
Is this an IntelliJ issue or am I missing something?
The relevant pom part from de App module:
<dependency>
<groupId>com.acme</groupId>
<artifactId>sbp-domain</artifactId>
<version>${project.version}</version>
<classifier>api</classifier>
</dependency>
<dependency>
<groupId>com.acme</groupId>
<artifactId>sbp-domain</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
question from:
https://stackoverflow.com/questions/65950563/intellij-maven-multimodule-project-with-classified-dependency 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…