imagej / imagej2

Open scientific N-dimensional image processing :microscope: :sparkler:
https://imagej.net/
BSD 2-Clause "Simplified" License
1.19k stars 333 forks source link

Maven build problem #273

Open BarchSteel opened 3 years ago

BarchSteel commented 3 years ago

Hello, I set up Eclipse, JDK8, cloned imagej/imagej, imported the project -> everything OK. I can also start & debug ImageJ 2.1.1-snapshot from with Eclipse. (go to net.imagej->main.java and Run As->Java App)

But I can't get the maven build to succeed to build the package or do an install. It will fail during the tests. What can I do to skip the tests? What is my mistake, so that I can build the package, or do a maven install? My goal is to create and test a stand-alone version for testing my modifications.

[ERROR] Tests run: 2, Failures: 0, Errors: 2, Skipped: 0, Time elapsed: 4.614 s <<< FAILURE! - in net.imagej.app.MainTest
[ERROR] testMains(net.imagej.app.MainTest)  Time elapsed: 3.787 s  <<< ERROR!
org.scijava.NoSuchServiceException: Service net.imagej.app.MainTest$LitmusService not found.
    at net.imagej.app.MainTest.testMains(MainTest.java:60)

[ERROR] testHeadless(net.imagej.app.MainTest)  Time elapsed: 0.719 s  <<< ERROR!
org.scijava.NoSuchServiceException: Service net.imagej.app.MainTest$LitmusService not found.
    at net.imagej.app.MainTest.testHeadless(MainTest.java:75)

[INFO] Running net.imagej.app.ServiceCompletenessTest
[INFO] Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.073 s - in net.imagej.app.ServiceCompletenessTest
[INFO] Running net.imagej.app.ToplevelImageJAppTest
[ERROR] Tests run: 1, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.071 s <<< FAILURE! - in net.imagej.app.ToplevelImageJAppTest
[ERROR] testApp(net.imagej.app.ToplevelImageJAppTest)  Time elapsed: 0.07 s  <<< FAILURE!
java.lang.AssertionError
    at net.imagej.app.ToplevelImageJAppTest.testApp(ToplevelImageJAppTest.java:71)

[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Failures: 
[ERROR]   ToplevelImageJAppTest.testApp:71
[ERROR] Errors: 
[ERROR]   MainTest.testHeadless:75 » NoSuchService Service net.imagej.app.MainTest$Litmu...
[ERROR]   MainTest.testMains:60 » NoSuchService Service net.imagej.app.MainTest$LitmusSe...
[INFO] 
[ERROR] Tests run: 5, Failures: 1, Errors: 2, Skipped: 0
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  19.141 s
[INFO] Finished at: 2020-12-16T21:04:18+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.22.2:test (default-test) on project imagej: There are test failures.
[ERROR] 
imagejan commented 3 years ago

Thanks for reporting, @BarchSteel!

I cannot reproduce with my local clone, building with Maven 3.3.9 and Java 1.8.0_271 on Mac OSX, using:

mvn clean install

You can skip tests by running:

mvn -DskipTests

Please note however that it shouldn't be necessary at all for you to build this project. If you want to test modifications in any specific component (such as scifio), just build that component only and put the built jar file into your up-to-date Fiji installation.

You can have Maven copy the jars and all dependencies by using:

mvn -Dscijava.app.directory=/path/to/your/Fiji.app
BarchSteel commented 3 years ago

Thank you for the answer.

The problem is reproducible for me. I also tested on a different PC (also Windows 10, x64, same Eclipse Version), and the error is identical.

But your trick: -DskipTests worked! I created the .jar. (I entered it as "goal" in the menu for Run As->"2 Maven build..." and it seemed to work.)

I wanted to debug my changes in scifio, but I could not get the debugger to work correctly on my setup, unless I had both ImageJ and SCIFIO as projects set up. I also needed to disable the default SCIFIO dependency in the ImageJ project and manually add my scifio project to the class-path.

The reason that I could not copy over the sicfio.jar was, because building scifio.jar using the maven build process, also fails during the test, but of course with different code lines (I made a forum post for this, in case others struggle in the same way: https://forum.image.sc/t/trouble-compiling-scifio-from-git-repository/46695)

frauzufall commented 3 years ago

Looks like in both cases the services are not discovered (based on the forum post, the SCIFIO NullPointerException during the tests is thrown here). Running mvn test on both repos (imagej/imagej and scifio/scifio) should work and it looks like in your case it doesn't. Maybe @tomburke-rse can help, he is a Windows user.

BarchSteel commented 3 years ago

I set up a test build using the GitHub actions workflow to compile imagej on windows-latest and there it works without problems: https://github.com/BarchSteel/imagej/runs/1575995959?check_suite_focus=true

So the problem lies on my PC, either with Eclipse, or the JDK.

ctrueden commented 3 years ago

There is a longstanding bug in the EclipseHelper code which runs the SciJava plugin indexer. Under some circumstances, the EclipseHelper ends up writing the indexed plugins to target/META-INF/json/org.scijava.plugin.Plugin, instead of the needed target/classes/META-INF/json/org.scijava.plugin.Plugin. You can work around it by running mvn manually on the CLI, then doing a refresh in Eclipse. I keep meaning to dig deeply into this bug and fix it, but haven't had time.

@BarchSteel I'm not certain your problem is the same as this, but I am quite suspicious. :wink:

It is unfortunate that we need this EclipseHelper thing, but unfortunately Eclipse does not run annotation processors otherwise. (Yes, you can configure it to run individual ones on a per project basis, but it's clunky at best and requires special files committed to every repository. Whereas the EclipseHelper solution—in theory at least—avoids community projects needing to care about this arcana.)

BarchSteel commented 3 years ago

I installed the apache-maven-3.6.3 and used it on the command line in the ImageJ source directory. mvn Unfortunately, at first, the error message stayed the same. For me, there were two different files. \target\META-INF\json\org.scijava.plugin.Plugin <-- does contain a reference to LitmusTest \target\classes\META-INF\json\org.scijava.plugin.Plugin <-- is missing the LitmusTest

The solution was to delete the complete target folder and re-create it by running mvn. Now the test passed!

So this is not a maven problem, but an Eclipse IDE problem. If this could be fixed, it would it easier for newcomers to contribute to the project (I prefer Eclipse GUI over the CLI).

I was looking around to find this EclipseHelper : maybe it's in here: https://github.com/scijava/scijava-maven-plugin

Just out of curiosity: How is scijava-maven-plugin referenced from imagej pom.xml? It seems the dependency goes like this: imagej->scijava-common -> scijava-base ->scijava-maven-plugin

imagesc-bot commented 3 years ago

This issue has been mentioned on Image.sc Forum. There might be relevant details there:

https://forum.image.sc/t/trouble-compiling-scifio-from-git-repository/46695/2

imagejan commented 3 years ago

How is scijava-maven-plugin referenced from imagej pom.xml?

The pom.xml in imagej directly inherits from its parent POM, pom-scijava, which serves as a "bill of materials" (BOM) and itself has pom-scijava-base as a parent.