I have two projects, let's say A and B, in the same directory dir
. B is a parent project to its module C. C is dependent on A. Directory structure:
dir/
A/
B/
C/
I use this method create a project with modules and to show, that C is dependent on A. After doing this, Netbeans starts to see packages of A in C, e.g. it shows no missing packages, gives hints on using classes from A in C. If I put A as a module of B, mvn clean install
says that maven reactor found the correct order of compiling projects and compiles them in the order A, B, C. mvn dependency:tree
shows that groupB:C:jar:0.0.1
has a child node groupA:A:jar:0.0.1:compile
.
I am not sure if A can be a module of B, because A has another parent (Spring boot). Thus, I try another variant: remove A from modules of B, then mvn clean install
in A, so that (I guess) the jar it produces goes to the local repo. Both variants seem to be ok for maven and Netbeans, but not for the compiler. During compilation, C does not see the packages of A.
I did mvn clean install
in any of the three projects. The dependency in C must have exact properties of A or a dependency error is produced in Maven. It seems that both Netbeans' hinting mechanism and Maven think that A is a library of C. It is only the compiler who doesn't see it. I guess that I did a newbie error. What can it be?
Relevant fragments of the pom.xml
involved:
A:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>groupA</groupId>
<artifactId>A</artifactId>
<packaging>jar</packaging>
<version>0.0.1</version>
<name>projectA</name>
<description>project A</description>
B: (I tried variants with A being a module of B commented out or not)
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.1</version>
<relativePath/>
</parent>
<groupId>groupB</groupId>
<artifactId>B</artifactId>
<packaging>pom</packaging>
<version>0.0.1</version>
<name>projectB</name>
<description>project B</description>
<modules>
<!--module>../A</module-->
<module>C</module>
</modules>
C:
<parent>
<groupId>groupB</groupId>
<artifactId>B</artifactId>
<version>0.0.1</version>
<relativePath>../</relativePath>
</parent>
<groupId>groupB</groupId>
<artifactId>C</artifactId>
<packaging>jar</packaging>
<version>0.0.1</version>
<name>projectC</name>
<description>project C</description>
<dependencies>
<dependency>
<groupId>groupA</groupId>
<artifactId>A</artifactId>
<version>0.0.1</version>
</dependency>
</dependencies>
question from:
https://stackoverflow.com/questions/65893588/maven-dependency-on-another-local-project-all-ok-but-compiler-does-not-see-jar 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…