Search code examples
javaeclipsemavendependenciesworkspace

Maven Eclipse plugin bug? failing to auto-add in-workspace dependency JAR to Run Configuration module-path


So here is a quick rundown of my situation:

I have two Java projects: one in Java 8 (so not modular) and one in Java 11 that is modular.

The modular/not-modular issue may not be relevant but for the sake of clarity, I've stated it.

For reference, the Java 8 is a game library I made, and the Java 11 is the game implementation I'm making.

I need to reference the Java 8 library from my Java 11 game project.

Both projects are Maven projects, and I have my dependency defined in my game's POM file.

I'm using latest version of Eclipse (2020-03 4.15.0) and Maven 3.6.3 with Java version 11.0.7 OracleJDK.

My Problem:

My understanding is that my Java 8 library project becomes an automatic module. Adding it into my Java 11 game project module-info file works (with a warning about the name being unstable, but no issue) and I can compile my game project code with no issues in Eclipse.

When I attempt to run the game, I get Module <my-library> not found, required by <my-game>. Now, since Maven is managing the dependencies, it should just work.

How can I get my game to run?


Solution

  • I Can Fix It Three Ways...

    First I can simply manually add the library project's JAR file (in it's target folder) to the Run Configuration module-path of my game project.

    Second, I can delete the library project from my workspace. This means Maven then goes and gets the JAR from the local m2 repo (it's been installed with mvn install). In this situation Maven DOES automatically add the JAR to the Run Configuration module-path correctly.

    Third, I can change the version of the library project in it's POM file and like option two, this means it no longer satisfies the dependency and Maven then looks for the JAR in the local m2 repo.

    But...

    All three of these options seem to me like they should be unnecessary. This feels like a bug with Maven failing to add the in-workspace project dependency to the module path in the Run Configuration in Eclipse.

    To be fair, it is a Maven Eclipse plugin feature that automatically detects when one of the in-workspace projects is a dependency and uses that "live" version instead of the m2 repo version. This is very handy for these situations where development on a library is happening in parallel.

    But until this bug is fixed (or unless it's not a bug and I'm missing something), this caused me a ton of frustration. I've posted this in hopes of helping anyone else who may be facing the same issue.