Einar Sundgren
Einar Sundgren

Reputation: 4423

Source dependency in Maven multi module project - cannot compile modules by themselves

I have a multi module Maven project where the modules Foo and Bar are Java packages. Foo contains a class that Bar inherits from. Both Foo and Bar has main methods for testing and debugging. The modules reside in folder Project

Compiling the entire project using mvn clean package works fine. But not compiling with the same command in the Bar module.

In Project there is a pom.xml containing:

...
<module>Foo</module>
<module>Bar</module>
<module>FooBar</module>
...

In Bar is pom.xml that contains:

    ...
    <dependency>
        <groupId>com.example.foo</groupId>
        <artifactId>Foo</artifactId>
        <version>1.0.0-SNAPSHOT</version>
    </dependency> 
    ...

When I try to use Maven to compile Bar from within the modules folder I get errors that it cannot locate the sibling package Foo. Other dependencies that are downloaded works fine.

What am I doing wrong?

Im pretty new to Maven and this seems to be a beginners error so I assume there is an easy answer.

Upvotes: 1

Views: 1121

Answers (1)

hotzst
hotzst

Reputation: 7496

In order to compile the Bar module the artefact com.example.foo:Foo:1.0.0-SNAPSHOT must be retrieved from at least the local Maven repository.

The artefact is saved in the local repository when executing the goal install. As you only execute clean package on the whole build this does not happen.

You have to execute install or clean install on the artefact Foo or the whole project. Every time you update the version you also have to rebuild the whole project (or at least the local dependencies).

Upvotes: 3

Related Questions