java9-modules-maven-junit-example icon indicating copy to clipboard operation
java9-modules-maven-junit-example copied to clipboard

Eclipse Build Fails

Open kolotyluk opened this issue 7 years ago • 12 comments

Everything works fine building and running under Maven, but importing the project into Eclipse Oxygen the tests do not compile properly.

I will continue to investigate, but it would be nice if this worked with Oxygen, as it is supposed to have Java 9 support.

Assert cannot be resolved Assert cannot be resolved Assert cannot be resolved Assert cannot be resolved Test cannot be resolved to a type Test cannot be resolved to a type Test cannot be resolved to a type Test cannot be resolved to a type Test cannot be resolved to a type TestCase cannot be resolved to a type TestSuite cannot be resolved to a type The import junit cannot be resolved The import junit cannot be resolved The import junit cannot be resolved The import org cannot be resolved The import org cannot be resolved The import org cannot be resolved The import org cannot be resolved The method assertTrue(boolean) is undefined for the type AppTest

kolotyluk avatar Jan 04 '18 22:01 kolotyluk

Since it is my first comment here: thanks @jklingen for posting this example.

@kolotyluk: this is interesting. I searched a little bit and found that this project is likely to do things the right way (see details below). So it's probably an m2eclipse bug. Just in case I tried with a Netbeans nightly build too (201801070002), not to avail.

Details Test dependencies don't have to be specified in module-info, Maven will add them to the classpath (and not to the module path): https://stackoverflow.com/a/47148586/4900484 Here you have a description of what Maven has to do in order to implement this behavior: https://stackoverflow.com/questions/41366582/where-should-i-put-unit-tests-when-migrating-a-java-8-project-to-jigsaw#comment69959520_41370766

shows you that the maven-compiler-plugin is using solution 3 from Nicolai which has been verified as the correct approach by some developers of the jigsaw team

bfreuden avatar Jan 07 '18 13:01 bfreuden

If I am understanding this m2eclipse commit properly: https://github.com/eclipse/m2e-core/commit/1f299d8e8140e198880d08d299df5177460d5d8f

... the only thing in this project that might be incorrect (in the future) is: <maven.compiler.target>1.9</maven.compiler.target> <maven.compiler.source>1.9</maven.compiler.source>

That probably should be written: <maven.compiler.target>9</maven.compiler.target> <maven.compiler.source>9</maven.compiler.source>

bfreuden avatar Jan 07 '18 13:01 bfreuden

@kolotyluk thanks for reporting this. As eclipse is not my preferred IDE, I had never tried to run the example on Oxygen before, but I did yesterday evening and experienced the same behavior. I haven't been able (yet) to figure out what's going wrong :-/

@bfreuden thanks for your investigation and for sharing your findings. I just had a look at the ticket resolved by the commit you mentioned above and right now I am not sure why 1.9 should not be supported by newer versions of maven and javac. At least it is working well over here with JDK 9 and 9.0.1 and maven-compiler plugin 3.7.0. Did you experience something else? Actually, the error message pasted into the ticket rather seems to indicate the use of an older version of maven-compiler-plugin. That said, it probably wouldn't be a bad idea to change it to 9.

jklingen avatar Jan 07 '18 17:01 jklingen

It might have something to do with the future Java versioning scheme: 18.3, 18.9 In Eclipse it now looks like this: image You're right, it is working well with the configuration you're describing.

One last question if you don't mind: do you know an IDE that is able to import those (correct) POM files without any error (I mean: auto configure a project from the sole POM files)? Eclipse is complaining (probably because of m2eclipse) and NetBeans does not seem to be very happy neither. Are you using IDEA?

bfreuden avatar Jan 07 '18 17:01 bfreuden

Yes, I am using IntelliJ Ultimate, I think it should also work fine with the free community edition.

I'll try with a few other open source project repos using modules, maybe that will shade some light.

jklingen avatar Jan 07 '18 18:01 jklingen

Indeed, it is working with IntelliJ community edition. Thank you! It must be something wrong with m2eclipse...

bfreuden avatar Jan 07 '18 20:01 bfreuden

Yes, I also assume it actually is an issue with Eclipse's Maven integration.

On the other hand, we're probably not the first ones who try to use modules with Eclipse, Maven and unit tests - so maybe it just needs a special twist. I'll see whether I can find something.

jklingen avatar Jan 08 '18 20:01 jklingen

Thank you! Just in case I posted a message on the m2e users list.

bfreuden avatar Jan 09 '18 14:01 bfreuden

I got an answer to my question: https://dev.eclipse.org/mhonarc/lists/m2e-users/msg05698.html

m2eclipse team is basically waiting for a JDT fix (that seem to be in progress according to the comments).

bfreuden avatar Jan 09 '18 15:01 bfreuden

@bfreuden thanks again for going after this one 👍 I have added a note to the readme file.

jklingen avatar Jan 14 '18 14:01 jklingen

My pleasure! Thanks for sharing the project in first place. Very useful to get started!

bfreuden avatar Jan 15 '18 15:01 bfreuden

For the sake of the follow-up: now your project works nicely in Eclipse Photon M5.

bfreuden avatar Feb 10 '18 14:02 bfreuden