Jasig / maven-notice-plugin

Apache License 2.0
7 stars 16 forks source link

Problem with schema URL during build #21

Open galzetta opened 3 years ago

galzetta commented 3 years ago

I'm using this plugin with Maven 3.5.0 and JDK 11 and I'm getting this error:

[ERROR] Failed to execute goal <my-plugin>:generate-files (default) on project webapp: Unable to execute mojo: Failed to parse 'license-mappings.xml' from 'jar:file:/home/slave/.m2/repository/<package>/license-resources/2.0-SNAPSHOT/license-resources-2.0-SNAPSHOT.jar!/license-mappings.xml': unexpected element (uri:"https://source.jasig.org/schemas/maven-notice-plugin/license-lookup", local:"license-lookup"). Expected elements are <{}license-lookup> -> [Help 1]

The error only happens on my Jenkins workers, while on my local machine everything runs fine. Can you help me understand the issue?

The license-mappings.xml is well formed and has been in use for the last 3 years so there is no issue with it, the last commit on it is from the start of 2020 and in more than a year we never had an issue before.

ChristianMurphy commented 3 years ago

I'm using this plugin with [...] JDK 11

This may be related to or a duplicate of https://github.com/Jasig/maven-notice-plugin/issues/18

galzetta commented 3 years ago

@ChristianMurphy I don't think so, I already fixed the problem with JAXB by providing the correct dependencies. On my local machine everything runs fine, on the builder it fails giving that error message. It seems like maven is trying to access https://source.jasig.org/schemas/maven-notice-plugin/license-lookup, which currently returns a 404 instead of listing the files in the directory, and so the build breaks.

ChristianMurphy commented 3 years ago

the last commit on it is from the start of 2020 and in more than a year we never had an issue before

last commit on what? This project was last updated in 2017

https://source.jasig.org/schemas/maven-notice-plugin/license-lookup, which currently returns a 404 instead of listing the files in the directory, and so the build breaks.

right https://sources.jasig.org was decommissioned some time ago, references to it should be updated. If there are references left behind, a PR to update them would be welcome!

galzetta commented 3 years ago

I was referring to the license-mappings.xml, just to clarify that I'm 100% certain that there are no issues with the XML contents of the file.

If that url is decommissioned what is the new URL that should be used for the schema?

ChristianMurphy commented 3 years ago

The file is located in the project at https://github.com/Jasig/maven-notice-plugin/blob/master/src/main/xsd/license-lookup-v1.0.xsd So any HTTPS hosted version of the raw file works. For example if https://rawgit.org is used, it would be at https://ghcdn.rawgit.org/Jasig/maven-notice-plugin/7d1ea6c31c1722eb2e9d1dd071829064fa1f5372/src/main/xsd/license-lookup-v1.0.xsd

galzetta commented 3 years ago

Trying to use the github raw url gives a slightly different error:

unexpected element (uri:"https://raw.githubusercontent.com/Jasig/maven-notice-plugin/master/src/main/xsd", local:"license-lookup"). Expected elements are <{https://source.jasig.org/schemas/maven-notice-plugin/license-lookup}license-lookup>

Probably the problem is that the schema file references source.jasig.org and it must match what you use in the license-mappings.xml.

galzetta commented 3 years ago

I'm trying to make sense of this issue. I've looked at the source code and the only thing that I can think of is related to the JAXBContext documentation (https://docs.oracle.com/javaee/7/api/javax/xml/bind/JAXBContext.html) where they state:

JAXB Runtime Binding Framework Compatibility

The following JAXB 1.0 restriction only applies to binding schema to interfaces/implementation classes. Since this binding does not require a common runtime system, a JAXB client application must not attempt to mix runtime objects (JAXBContext, > Marshaller, etc. ) from different providers. This does not mean that the client application isn't portable, it simply means that a client has to use a runtime system provided by the same provider that was used to compile the schema.

Maybe the way I'm using the plugin is mixxing providers and therefore causing this issue?

I have never used JAXB before so I don't really understand how this works. For example in the sources there is this file: https://github.com/Jasig/maven-notice-plugin/blob/master/src/main/binding/bindings.xjb but I cannot find any point where it is references explicitly, so does JAXB implicitly loads it somewhere? Why isn't this under the resources directory? However given that this seems the thing that binds the schema to JAXB I'm pretty sure the problem is that when using the JDK 11 either it isn't loaded or is loaded by an incompatible class as described by the documentation above.

For reference I'm using this plugin inside my own Mojo, so I'm really doing this:

final ExecutionEnvironment environment = executionEnvironment(mavenProject, mavenSession, pluginManager);
Dependency licenseResourcesDependency = dependency(
        groupId("<groupId>"),
        artifactId("license-resources"),
        version("<version>")
);
// These dependencies are not provided by the runtime in JDK 11
final List<Dependency> noticeDependencies = dependencies(
        licenseResourcesDependency,
        dependency(
                groupId("org.glassfish.jaxb"),
                artifactId("jaxb-runtime"),
                version("2.3.1")
        ),
        dependency(
                groupId("javax.xml.bind"),
                artifactId("jaxb-api"),
                version("2.3.1")
        )
);

final Plugin noticePlugin = plugin(
        groupId("org.jasig.maven"),
        artifactId("maven-notice-plugin"),
        version("1.1.0"),
        noticeDependencies
);
final Xpp3Dom noticePluginConf = configuration(
        element(name("noticeTemplate"), "<name>/licenses/" + licenseName + "/NOTICE.template"),
        element(name("licenseMapping"),
                element(name("param"), "license-mappings.xml")
        ),
        element(name("fileName"), "NOTICE"),
        element(name("excludeScopes"), element(name("param"), "test"))
);
executeMojo(
        noticePlugin,
        goal("generate"),
        noticePluginConf,
        environment
);

So I'm simply adding the missing dependencies and I load the license-mappings.xml from an other artifact. This works fine with JDK 8, but with JDK 11 projects it fails with the error above. I'm not sure whether the issue might simply be that I have to find the correct artifacts for the jaxb dependencies?