testcontainers/testcontainers-jooq-codegen-maven-plugin

java.lang.NoClassDefFoundError: org/testcontainers/utility/PathUtils

avasenin opened this issue · 14 comments

Version of plugin 0.0.3
Version of jooq: 3.18.7
Version of testcontainers: 1.19.3

This error appeared all the time, even in case of successful runs.

Can be related to testcontainers/testcontainers-java#1454

Exception in thread "Thread-5" java.lang.NoClassDefFoundError: org/testcontainers/utility/PathUtils
	at org.testcontainers.utility.MountableFile.lambda$deleteOnExit$0(MountableFile.java:318)
	at java.base/java.lang.Thread.run(Thread.java:1583)
Caused by: java.lang.ClassNotFoundException: org.testcontainers.utility.PathUtils
	at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50)
	at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271)
	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247)
	at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239)
	... 2 more
	

testcontainers/testcontainers-java#1454
this issue is not solved. should be reopened. :(

Does it even work?
testcontainers/testcontainers-java#1454 (comment)

Hmm, I'm not really sure if we can help much with this. Running Testcontainers code directly from a Maven plugin isn't something we've attempted to support, as we're more focused on testing. I assume your usage scenarios are not testing?

As you say it does look like the Maven classloader closing is what's causing it. If that's Maven's classloader behaviour then I imagine shutdown hooks are essentially not safe inside of a Maven plugin, and should be avoided.

If there's something simple that we could change then I think we could accept a PR, but otherwise I'm afraid we might have to chalk this up as an unsupported use case. Sorry to disappoint.

Looks like this plugin is not supported by the authors from the same organization... do I not understand something?

(this relates both to testcontainers-java and to this maven plugin, so posting here as well)

This is what Maven documentation states:
https://maven.apache.org/plugin-developers/common-bugs.html#using-shutdown-hooks

The problem is that the JVM executing Maven can be running much longer than the actual Maven build. Of course, this does not apply to the standalone invocation of Maven from the command line. However, it affects the embedded usage of Maven in IDEs or CI servers. In those cases, the cleanup tasks will be deferred, too. If the JVM is then executing a bunch of other Maven builds, many such cleanup tasks can sum up, eating up resources of the JVM.

For this reason, plugin developers should avoid usage of shutdown hooks and rather use try/finally blocks to perform cleanup as soon as the resources are no longer needed.

So, I guess, the maven plugin should clean up the shutdown hooks created by testcontainers-java?
Or rather - remove them from the shutdown hooks and execute them in finally block?

Any news here?

I get the same error with MYSQL, followed the official guide:
testcontainers-jooq-codegen-maven-plugin-guide

Exception in thread "Thread-5" java.lang.NoClassDefFoundError: org/testcontainers/utility/PathUtils at org.testcontainers.utility.MountableFile.lambda$deleteOnExit$0(MountableFile.java:318) at java.base/java.lang.Thread.run(Thread.java:833) Caused by: java.lang.ClassNotFoundException: org.testcontainers.utility.PathUtils at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(SelfFirstStrategy.java:50) at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(ClassRealm.java:271) at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:247) at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(ClassRealm.java:239) ... 2 more

@oxygenecore The comment you quoted from testcontainers/testcontainers-java#1454 is from 2019, it significantly predates the creation of this plugin and hence is not related with regards to org not supporting this plugin. However, the technical investigation is of course related.

@sivaprasadreddy is the author of this plugin. I don't know if this exception (maybe originating from executing of the shutdown hook) is really an issue in the context of this use case (which file are we supposed to delete?). Can we technically remove the shutdown hook from within the plugin?