Search code examples
eclipsemavendependencies

Maven dependency not propagated to dependent project


I have two Maven projects in my Eclipse workspace, datastore and service.

datastore has HSQLDB as a Maven dependency with scope compile.

Since service depends on datastore, I have added datastore as a required project for it in Properties > Java Build Path > Projects.

However, when I now run service, I get a ClassNotFoundException for the HSQLDB JDBC driver (in one of datastore’s classes called from service).

If I add HSQLDB as a dependency to service everything works as it should—though I understand I should not need this, as Maven dependencies with scope compile should get propagated to dependent projects.

Also, I notice the pom.xml for service contains no reference to datastore.

Where’s the error, if any?


Solution

  • Properties > Java Build Path > Projects is an Eclipse mechanism and will not propagate Maven dependencies. In order for dependency propagation to work as intended, datastore needs to be a Maven dependency.

    Add datastore as a Maven dependency, using the group ID, artifact ID and version from its pom.xml. After that, the project can be removed from Properties > Java Build Path > Projects.