reines / dropwizard-debpkg-maven-plugin

A maven plugin for packing Dropwizard applications as Debian packages.
Apache License 2.0
52 stars 12 forks source link

Problem using with OpenJDK 11 #29

Open boncey opened 3 years ago

boncey commented 3 years ago

I switched to OpenJDK 11 and it now fails with an error.

  [INFO] --- dropwizard-debpkg-maven-plugin:0.10:dwpackage (default) @ money ---
  [INFO] Detected Dropwizard 2.0.16, attempting to validate configuration.
  class io.dropwizard.configuration.ConfigurationMetadata$1: javax/sql/DataSource
  java/sql/Date
  [WARNING] Failed to validate configuration
  [INFO] ------------------------------------------------------------------------
  [INFO] BUILD FAILURE
  [INFO] ------------------------------------------------------------------------
  [INFO] Total time:  10.438 s
  [INFO] Finished at: 2020-12-22T16:01:53Z
  [INFO] ------------------------------------------------------------------------
  [ERROR] Failed to execute goal com.jamierf.dropwizard:dropwizard-debpkg-maven-plugin:0.10:dwpackage (default) on project money: Execution default of goal com.jamierf.dropwizard:dropwizard-debpkg-maven-plugin:0.10:dwpackage failed: org.apache.tools.ant.ExitException: ExitException: status 1 -> [Help 1]
  org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.jamierf.dropwizard:dropwizard-debpkg-maven-plugin:0.10:dwpackage (default) on project money: Execution default of goal com.jamierf.dropwizard:dropwizard-debpkg-maven-plugin:0.10:dwpackage failed: org.apache.tools.ant.ExitException: ExitException: status 1

The relevant part from the stack trace seems to be:

  at com.jamierf.dropwizard.debpkg.validation.ApplicationValidator.validateConfiguration (ApplicationValidator.java:59)
  at com.jamierf.dropwizard.debpkg.validation.ApplicationValidator.validateConfiguration (ApplicationValidator.java:48)
  at com.jamierf.dropwizard.debpkg.DropwizardMojo.validateApplicationConfiguration (DropwizardMojo.java:192)
  at com.jamierf.dropwizard.debpkg.DropwizardMojo.execute (DropwizardMojo.java:109)

The important part from above seems to be:

  class io.dropwizard.configuration.ConfigurationMetadata$1: javax/sql/DataSource
  java/sql/Date

It looks like it's related to the jars that are no longer part of the OpenJDK.

If I run the DW check command against my app's jar it works fine.

Thanks, Darren.

boncey commented 3 years ago

I can replicate this by checking out this project and running ApplicationValidatorTest under Java 11.

    Failed to call configuration validation method

    java.lang.RuntimeException: java.lang.reflect.InvocationTargetException

        at com.google.common.base.Throwables.propagate(Throwables.java:160)
        at com.jamierf.dropwizard.debpkg.validation.ApplicationValidator.validateConfiguration(ApplicationValidator.java:71)
        at com.jamierf.dropwizard.debpkg.validation.ApplicationValidator.validateConfiguration(ApplicationValidator.java:48)
        at com.jamierf.dropwizard.debpkg.validation.ApplicationValidatorTest.testValidConfiguration(ApplicationValidatorTest.java:50)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
        at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
        at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
        at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
        at org.junit.rules.ExternalResource$1.evaluate(ExternalResource.java:48)
        at org.junit.rules.RunRules.evaluate(RunRules.java:20)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:77)
        at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:56)
        at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
        at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
        at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
        at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:220)
        at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:53)
    Caused by: java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:566)
        at com.jamierf.dropwizard.debpkg.validation.ApplicationValidator.validateConfiguration(ApplicationValidator.java:59)
        ... 27 more
    Caused by: java.lang.NoClassDefFoundError: javax/sql/DataSource
        at io.dropwizard.hibernate.HibernateBundle.<init>(HibernateBundle.java:20)
        at com.example.helloworld.HelloWorldApplication$1.<init>(HelloWorldApplication.java:26)
        at com.example.helloworld.HelloWorldApplication.<init>(HelloWorldApplication.java:25)
        at com.example.helloworld.HelloWorldApplication.main(HelloWorldApplication.java:22)
        ... 32 more
    Caused by: java.lang.ClassNotFoundException: javax.sql.DataSource
        at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:471)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:588)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
        ... 36 more
boncey commented 3 years ago

This change fixes the problem.

    --- a/src/main/java/com/jamierf/dropwizard/debpkg/validation/ApplicationValidator.java
    +++ b/src/main/java/com/jamierf/dropwizard/debpkg/validation/ApplicationValidator.java
    @@ -26,7 +26,7 @@ public class ApplicationValidator {
             this.log = log;

             // Set parent to null to avoid pulling in SLF4J and other conflicts from our self
    -        classLoader = new URLClassLoader(new URL[]{artifactFile.toURI().toURL()}, null);
    +        classLoader = new URLClassLoader(new URL[]{artifactFile.toURI().toURL()}, ClassLoader.getPlatformClassLoader());
         }

         private Class<?> getMainClass() throws IOException, ClassNotFoundException {

There was a change in Java 11 to the ClassLoader.

In Java 11, the boot class loader only loads core modules. If you create a class loader with a null parent, it may not find all platform classes. In Java 11, you need to pass ClassLoader.getPlatformClassLoader() instead of null as the parent class loader in such cases.

However, that change requires at least Java version 9 so it will no longer work with Java 8. Also, the HelloWorld application used in the tests will need updating to Java 11 too.

-Also, I was unable to get the code to build locally so I can't even roll my own fork.-

Got it built locally by upgrading maven-plugin-plugin to 3.6.0. 👍

Update:

I've pushed my various hacks and fixes to https://github.com/boncey/dropwizard-debpkg-maven-plugin/tree/java-11-changes. I won't raise a PR as I think it will need some cleanup work and it will also most like break Java 8 compatibility.