Closed dbwiddis closed 1 year ago
Further analysis:
DirectoryNotEmptyException
is anticipated in the catch block but only if the boolean ignoreNonEmpty
is true.copyDirectoryStructure()
calls, and the ignoreNonEmpty
value is set false for the first one (which is the one causing the problem here). patched-test-runtime
directory (if it exists) before the first call, but in that case, it seems the ignoreNonEmpty
boolean is useless, so I'm assuming it's there for a reason; perhaps the first call is intended to throw an exception on a nonEmpty directory, exactly as it's doing. So at present, this seems to be the intention, and successive tests without cleaning up in between are not permitted.
Thank you for raising this issue including a minimal reproducer, Daniel.
I can't recall why I resorted to copying files back in the days, would be good if there's a "don't copy files" approach.
I found quite convenient workaround:
Define in your parent POM:
…
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>${maven-clean-plugin.version}</version>
<executions>
<execution>
<id>clean-junit-platform</id>
<phase>initialize</phase>
<goals>
<goal>clean</goal>
</goals>
<configuration>
<excludeDefaultDirectories>true</excludeDefaultDirectories>
<fast>true</fast>
<filesets>
<fileset>
<directory>${project.build.directory}/junit-platform</directory>
</fileset>
</filesets>
<skip>false</skip>
</configuration>
</execution>
</executions>
</plugin>
…
and instantiate it in the artifact's POM which has the junit-platform-maven-plugin
in in already. Like this:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<executions>
<execution>
<id>clean-junit-platform</id>
</execution>
</executions>
</plugin>
<plugin>
<groupId>de.sormuras.junit</groupId>
<artifactId>junit-platform-maven-plugin</artifactId>
</plugin>
…
Goo luck!
Yep. Already worked around it. :-)
Fall is coming - might be a good time to tackle this bug within the plugin.
I'd be happy to submit a fix, except it's really not clear what the fix is. I'd just always set ignoreNonEmpty
to true and it would work.
But then why is that boolean there in the first place? :-)
So my workaround works great for running tests, but I'm blocked on publishing a release due to a different bug in maven-javadoc-plugin that can't find my module descriptor in the case the output directory exists but my previously built jar has been "cleaned". :(
Hey @sormuras as I hack around this for yet another release, I'm wondering if there's anything I can do to help get this fixed. I certainly know a way to fix it but I'm not sure if that will break some other intended behavior. To summarize:
clean
for modular builds all the time, or tests breakclean
in the initialize phase so users don't have to, which is less efficient but workableHi Daniel!
I certainly know a way to fix it but I'm not sure if that will break some other intended behavior.
If you have time to prepare a fix I am happy to merge it. As long as existing integration tests don't break, we're fine. If a few fail, there's always the option to name the next release 1.2.0
or even 2.0.0
Sure, I'll take a crack at it this weekend. My plan is to toggle the ignoreNonEmpty
boolean to true
in this line:
https://github.com/sormuras/junit-platform-maven-plugin/blob/be28792abb6ba9d6489713c407a58389c96da2d4/src/main/java/de/sormuras/junit/platform/maven/plugin/MavenDriver.java#L138
That'll take 5 seconds. Writing a failing test, proving this fixes it, and debugging any other failures that causes may require extra cups of coffee. :)
Initial attempts toggling the boolean worked, but ended up keeping the old files there because the copy failed (as before) but the exception was caught. And old compiled files might not be current, which is bad.
So I just replicated the subset of clean that really is needed, deleting the target directory before copying.
Originally reported in #92, but the problem can be reproduced without the complexity I originally saw. Any project with modular patched test runtime will cause the problem.
Running
mvn test
multiple times without aclean
, on a modular project, fails.Minimal reproducer project: https://github.com/dbwiddis/foo
mvn clean test test
---> failsmvn clean test clean test
---> succeedsAdditional debugging info:
The stack trace points to a problem copying the directory structure with the code in these lines
target/junit-runtime/patched-test-runtime
directory, or the entire contents of the directory, in between runs ofmvn test
also fixes the problem, indicating something associated with that directory is failing in these lines:dstFldr
here ispatched-test-runtime
and it is non-empty after the first run.