Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
426 views
in Technique[技术] by (71.8m points)

dependencies - How to make one module depend on another module artifact?

I have maven multiple-module project.

 A: parent.
    B: child1.
    C: child2.

B will be packaged to get jar file and then c will use this jar file to compile the code.

In B, if I run mvn package, it will create b.jar (stays in B/target/jars not in B/target -for another purpose).

In C, I need to use that b.jar to compile the code.

Now, from A, when I run: mvn package. First, I am successful to create b.jar file for B.

But when it come to C's compilation phase, it looks like C doesn't recognize b.jar in the classpath (the compilation gets errors because C's code can not import the class file from B).

My question is: How can I solve this problem?

---------- Below are the pom files

A: pom.xml
  <groupId>AAA</groupId>
  <artifactId>A</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>

   <modules>
   <module>C</module>
   <module>B</module>
   </modules>

B: pom.xml
        <groupId>AAA</groupId>
 <artifactId>B</artifactId>
 <packaging>jar</packaging>
 <version>0.0.1-SNAPSHOT</version>
 <parent>
  <artifactId>A</artifactId>
  <groupId>AAA</groupId>
  <version>0.0.1-SNAPSHOT</version>
 </parent>

C: pom.xml
       <parent>
  <artifactId>A</artifactId>
  <groupId>AAA</groupId>
  <version>0.0.1-SNAPSHOT</version>
 </parent>

 <groupId>AAA</groupId>
 <artifactId>C</artifactId>
 <packaging>war</packaging>
 <version>0.0.1-SNAPSHOT</version>

 <dependencies>

  <dependency>
   <groupId>AAA</groupId>
   <artifactId>B</artifactId>
   <version>0.0.1-SNAPSHOT</version>
  </dependency>
....
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try ${project.version}

e.g.

<dependency>
   <groupId>AAA</groupId>
   <artifactId>B</artifactId>
   <version>${project.version}</version>
</dependency>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...