kontext-e / jqassistant-gradle-plugin

Gradle Plugin for jQAssistant
3 stars 3 forks source link

JAXB implementation not found on classpath #13

Closed MarcoJanecki closed 9 hours ago

MarcoJanecki commented 5 months ago

Hey guys :)

I am just trying to setup the Plugin for my Gradle project. I am using Java 17 (for a SpringBoot project) and Gradle 8.8.

I configured my build.gradle and jqassistant.yml like in your example project. (Hint: The version stated - 2.0.0-SNAPSHOT - is not available on mavenCentral. I changed it to 2.0.0)

When I try to execute ./gradlew scan or ./gradlew analyze, I get the error that JAXB implementation is missing on classpath.

`[main] INFO PluginResolverImpl - Resolving 7 plugins and required dependencies. Exception in thread "main" java.lang.IllegalStateException: Cannot create JAXB context for org.jqassistant.schema.plugin.v1.JqassistantPlugin at com.buschmais.jqassistant.core.shared.xml.JAXBUnmarshaller.(JAXBUnmarshaller.java:78) at com.buschmais.jqassistant.core.runtime.impl.plugin.PluginConfigurationReaderImpl.(PluginConfigurationReaderImpl.java:47) at com.buschmais.jqassistant.commandline.Main.getPluginRepository(Main.java:128) at com.buschmais.jqassistant.commandline.Main.interpretCommandLine(Main.java:204) at com.buschmais.jqassistant.commandline.Main.run(Main.java:89) at com.buschmais.jqassistant.commandline.Main.main(Main.java:70) Caused by: javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.

FAILURE: Build failed with an exception.

I tried to add the dependency to my build.gradle (see below) manually, but that didn't change anything.

implementation('javax.xml.bind:jaxb-api:2.3.0') implementation('javax.activation:activation:1.1') implementation('org.glassfish.jaxb:jaxb-runtime:2.3.0')

What am I doing wrong or missing? Do I have to add those dependencies somewhere else to make them available to JQAssistant?

Thanks for any hints! I much appreciate this plugin! :)

fed6297d commented 3 months ago

I'm having similar problems. Interestingly I use the gradle plugin for two projcts:

The gradle configuration is comparable. For the second project I get above errors, for the first project I do not have any problems. Using the jqassistant 2.4.0 CLI application, things work for the second project, too.

For me it looks like there a classpath problem within plugin execution (side effect with other plugins?). If anybody has an idea how to debug and analyze the problem, give me a hint.

fed6297d commented 2 months ago

We were able to solve the problems by moving the asciidoc and jQAsssistant specific gradle code in to its own sub project. After that everything run fine again. I'm not a gradle expert, but assume that other gradle plugins / dependencies disruppted somehow the propper execution.

WilliamThimm commented 2 months ago

Hello,

Thank you for reporting the issue.

This indeed seems like a problem with the classpath. However, when Gradle starts a jQAssistant task, it creates a new classpath with only the dependencies required to launch jQAssistant. This means that the workaround attempted by @MarcoJanecki will not work. The implementation(...) call in the build.gradle file only modifies the classpath used to run your project and should be entirely separate from the classpath used to run jQAssistant. This is why I am confused by @fed6297d's observation that there could be side effects with other plugins.

To see the classpath used to run jQAssistant, you can use the -info flag with the Gradle command (i.e., gradle -info scan). Before the scan task starts, the entire classpath is printed to the console.

There are two approaches that could possibly fix the problem:

  1. One idea is to try adding the missing dependency as a plugin for jQAssistant itself (using the jqassistant.yaml method), not for Gradle. If jQAssistant adds everything configured in the plugins section to the classpath, this could solve the issue. However, if jQAssistant only adds dependencies that are actual jQAssistant plugins and skips the rest, this approach would be a dead end. Note that the dependencies declared for jQAssistant will not appear in the classpath displayed by gradle -info scan. The plugins are resolved during the runtime of jQAssistant, and gradle -info scan will only display the classpath used to start jQAssistant.

  2. The other idea it to add the jqassistant-block in the build.gradle and declare the missing dependencies as plugins there. When doing this, the jars are added to the classpath when jqassistant is started, so gradle -info scan should display the added jars. This would look as follows:

    jqassistant{
    plugin 'javax.xml.bind:jaxb-api:2.3.0'
    plugin 'javax.activation:activation:1.1'
    plugin 'org.glassfish.jaxb:jaxb-runtime:2.3.0'
    }

    Do not worry that the plugin option is marked as deprecated. This is because the jqassistant.yaml method is the easier way to configure jQAssistant. I do not have any plans to remove this plugin option, as it can still be useful in such situations.

Please let me know if this resolves the problem, and if so, which approach helped. I would also be interested to know which plugin is suspected to interfere in @fed6297d's case!

WilliamThimm commented 9 hours ago

Hello,

This issue should now be fixed in Version 3.0.0. Note that the ID of the plugin has changed to conform with Gradle guidlines. The plugin now no longer calls the Main class of jQAssistant but instead executes the jqassistant.cmd/sh packaged with the commandline distribution, meaning that the classpath is now entirely seperate from gradle and should no longer cause any trouble. Please have a look at the README for more information on how to use the new version.

If there are still any issues, please feel free to reach out again!