Saturday, May 26, 2012

Maven Project Compiles in Eclipse but Maven Build Fails

Today I ran into a perplexing Eclipse/Maven issue where my Maven project would compile just fine according to Eclipse, but the Maven compile goal would fail. If you are reading this you probably had the same issue and this might help.

Version Information

Maven 3.0.4
Eclipse Indigo

The Error

The following error was produced by the Maven compile goal:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project blah: Compilation failure: Compilation failure:
[ERROR] Blah.java:[6,17] error: package javax.jnlp does not exist

The Solution

The problem was caused by the scope I had defined for the jnlp-api dependency in a child module in a multi-module Maven project. In the parent module inside the distributionManagement tag in the pom.xml, I defined the scope as "provided". The problem occurred when I accidentally defined the scope for that dependency in the child's pom.xml as "runtime". The fix was of course to make the scopes match in both pom.xml files.

I could have saved a lot more time debugging this, if Maven would have produced a more specific error message. Oh well.

1 comment:

toth said...

Hi,
Similar issue, Eclipse compiles but maven m2 plugin (clean package) fails.

[ERROR] SomeClass.java:[41,50] error: incompatible types: Long cannot be converted to Float

The type mismatch indeed existed but Eclipse showed the projects as correctly compiled.
Any idea why both compile tasks behave differently?

Best
Luis