Расширение Maven не активно во время сборки - PullRequest
0 голосов
/ 18 октября 2019

Я пытаюсь создать новое расширение maven. Однако, когда я запускаю сборку maven с расширением, объявленным в ${maven.projectBasedir}/.mvn/extensions.xml, ExecutionListener расширения не будет прослушивать.

pom.xml моего расширения:

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.example</groupId>
    <artifactId>test-extension</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.apache.maven</groupId>
            <artifactId>maven-core</artifactId>
            <version>3.6.0</version>
        </dependency>
        <dependency>
            <groupId>org.codehaus.plexus</groupId>
            <artifactId>plexus-component-annotations</artifactId>
            <version>1.7.1</version>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.plexus</groupId>
                <artifactId>plexus-component-metadata</artifactId>
                <version>1.7.1</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate-metadata</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

</project>

Слушатель выполнения выглядит так:

package org.example.testextension;

import org.apache.maven.execution.AbstractExecutionListener;
import org.apache.maven.execution.ExecutionEvent;
import org.apache.maven.execution.ExecutionListener;
import org.codehaus.plexus.component.annotations.Component;

@Component(role =  ExecutionListener.class)
public class Foo extends AbstractExecutionListener {

    static {
        // force exception being thrown
        ((String)null).length();
    }

    public Foo() {
        System.out.println("Building World!");
        throw new RuntimeException("forcing failure");
    }


    @Override
    public void sessionStarted(ExecutionEvent event) {
        System.out.println("Hello World!");
        throw new RuntimeException("forcing failure");
    }

    @Override
    public void mojoStarted(ExecutionEvent event) {
        System.out.println("Failing World!");
        throw new RuntimeException("forcing failure");
    }
}

Сгенерированный components.xml:

<?xml version="1.0" encoding="UTF-8"?>
<component-set>
  <components>
    <component>
      <role>org.apache.maven.execution.ExecutionListener</role>
      <role-hint>default</role-hint>
      <implementation>org.example.testextension.Foo</implementation>
      <description />
      <isolated-realm>false</isolated-realm>
    </component>
  </components>
</component-set>

И META-INF/maven/extension.xml:

<extension>
    <exportedPackages>
        <exportedPackage>org.example.testextension</exportedPackage>
    </exportedPackages>
    <exportedArtifacts>
        <exportedArtifact>org.apache.maven:maven-core</exportedArtifact>
        <exportedArtifact>org.codehaus.plexus:plexus-component-annotations</exportedArtifact>
    </exportedArtifacts>
</extension>

Я пытаюсьзапустить вышеуказанное расширение в другом проекте с pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.example</groupId>
    <artifactId>maven-extension-test</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</project>

и ./.mvn/extensions.xml

<extensions xmlns="http://maven.apache.org/EXTENSIONS/1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/EXTENSIONS/1.0.0 http://maven.apache.org/xsd/core-extensions-1.0.0.xsd">
    <extension>
        <groupId>org.example</groupId>
        <artifactId>test-extension</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </extension>
</extensions>

При запуске этой сборки я вижу, что расширение пытается загрузитьиз репо мавена. Но больше ничего не происходит с расширением.

Я ожидал увидеть сбой сборки из-за различных исключений, вызванных в слушателе выполнения. Однако сборка завершается успешно.

Чего мне не хватает, чтобы в сборке использовался прослушиватель выполнения расширения?

Я использую maven:

Maven home: C:\Program Files\apache\apache-maven-3.6.2\bin\..
Java version: 1.8.0_161, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk1.8.0_161\jre
Default locale: de_DE, platform encoding: Cp1252
OS name: "windows 7", version: "6.1", arch: "amd64", family: "windows"

РЕДАКТИРОВАТЬ:
Проблема также была сообщена Maven Issue Tracker: https://issues.apache.org/jira/browse/MNGSITE-379

...