JerryCai
JerryCai

Reputation: 1693

How to compile a maven project which reference to another local changed maven project?

I have 2 projects, A and B. B is a lib project and A reference to B. When I add new function to B, it's ok to run mvn install on B, but it failed on mvn install on A due to can not find the symbol from new B.

I'm sure I did install correctly on project B, but why A still failed to compile and install?

This is A's pom.xml:

<dependency>
    <groupId>A and B's group</groupId>
    <artifactId>B</artifactId>
    <scope>provided</scope>     
</dependency>

any clue? Thanks

Upvotes: 3

Views: 1616

Answers (4)

yu yang Jian
yu yang Jian

Reputation: 7171

Use <scope>system</scope> in jar <dependecy></dependency>,

please reference (https://stackoverflow.com/a/28958317/4573839).

Upvotes: 0

khmarbaise
khmarbaise

Reputation: 97517

I would suggest to create a multi-module build like the following:

+-- root
      +-- pom.xml
      +-- module-A
      +-- module-B

In the root pom you need to define the modules like this and define the packaging to pom.

<modules>
  <module>module-A</module>
  <module>module-B</module>
</modules>

Furthermore you can define a dependency of module-A to module -B simply by:

<project ..
  <parent>
     <groupId>project.parent</groupId>
     <artifactId>parent</artifactId>
     <version>1.0-SNAPSHOT</version>
  </parent>

  <artifactId>module-A</artifactId>

  <dependencies>
    <dependency>
      <groupId>${project.groupId}</groupId>
      <artifactId>module-B</artifactId>
      <version>${project.version}</version>
    </dependency>
    ..
  </dependencies>
  ..
</project>

With this setup you can simply build all modules from the root folder just by:

mvn clean package

or you can import that structure into Eclipse (m2e installed?) or any other IDE like IntelliJ or Netbeans.

Upvotes: 1

Arpit
Arpit

Reputation: 6260

You can include the <version> element in the project's as well as dependency's declaration.

  • pass a version variable from Maven command line. Eg: ${build.version}

Module A's pom.xml:

<groupId>A & B's Group ID</groupId>
<artifactId>A</artifactId>
<version>${build.version}</version>

<dependencies>
    <dependency>
        <groupId>A & B's Group ID</groupId>
        <artifactId>B</artifactId>
        <version>${build.version}</version>
        <type>war</type>
        <scope>provided</scope>
    </dependency>   
...

So, whenever Project B is built and installed, the dependency will be available in the local maven repository for that particular version and will be picked by Project A

Upvotes: 0

Thorn G
Thorn G

Reputation: 12776

Try mvn clean install to do a totally fresh build of A, or mvn -U install to force Maven to look for updated snapshots. It sounds like your environment is still using the older JAR. It's hard to tell what your setup is from this description -- sounds like you're correctly installing B to your local repository, but I'm not sure if your IDE might be trying to be 'helpful' as well.

Upvotes: 0

Related Questions