Skip to content

Accessing "META-INF/maven/plugin.xml" files during tests #76

@jmini

Description

@jmini

If I got this right, a maven plugin is nothing more than a regular jar with some additional metadata files in META-INF/maven/.

A jar built with the de.benediktritter.maven-plugin-development contains those file:

Screenshot of the example-maven-plugin-1.0.0-SNAPSHOT.jar content

Screenshot of a jar corresponding to the example-maven-plugin project.

The files are generated in the $buildDir/mavenPlugin/descriptor folder.

Usually when I have a task that generates files that needs to be present in the jar, I modify the source set to add the generated folder like this:

sourceSets.main.output.dir file("$buildDir/mavenPlugin/descriptor"), builtBy: generateMavenPluginDescriptor

While I was working on having functional tests for my maven plugin (see #41 - I will share the results soon) I noticed that the META-INF/maven/plugin.xml are not available during the test.

Adding this code to a test shows the problem:

System.out.println(getClass().getClassLoader());

if (getClass().getClassLoader() instanceof URLClassLoader) {
    Arrays.stream(((URLClassLoader) getClass().getClassLoader()).getURLs())
            .forEach(e -> System.out.println(e));
} else {
    System.out.println("XXXX Not a URLClassLoader");
}

During the test task the jar is not present on the classpath, only the folder containing the *.class files.

Output:

sun.misc.Launcher$AppClassLoader@2a139a55
file:/<user home>/.gradle/caches/7.3/workerMain/gradle-worker.jar
file:/<path to>/example-maven-plugin/build/classes/java/test/
file:/<path to>/example-maven-plugin/build/classes/java/main/
...
file:/<user home>/.gradle/caches/modules-2/files-2.1/junit/junit/4.12/2973d150c0dc1fefe998f834810d68f278ea58ec/junit-4.12.jar
... and a lot of other jars from the gradle cache (corresponding to my test runtime classpath)

I was wondering if this is intended?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions