mavenmaven-3plexus

Replace plexus component in Maven 3


I need to replace some Maven default functionality with my own implementation, and I am looking for a clean way to do that.

I have extended org.apache.maven.repository.internal.DefaultVersionRangeResolver and registered my extended component using a component.xml as follows:

<component-set>
    <components>
        <component>
            <role>org.sonatype.aether.impl.VersionRangeResolver</role>
            <role-hint>default</role-hint>
            <implementation>com.my.custom.VersionRangeResolver
            </implementation>
            <isolated-realm>false</isolated-realm>
            <requirements>
                <requirement>
                    <role>org.sonatype.aether.spi.log.Logger</role>
                    <role-hint />
                    <field-name>logger</field-name>
                </requirement>
                <requirement>
                    <role>org.sonatype.aether.spi.log.Logger</role>
                    <role-hint />
                    <field-name>logger2</field-name>
                </requirement>
                <requirement>
                    <role>org.sonatype.aether.impl.MetadataResolver</role>
                    <role-hint />
                    <field-name>metadataResolver</field-name>
                </requirement>
            </requirements>
        </component>
    </components>
</component-set>

I have installed the project that contains this in my local repo, and I reference it like this in another project's pom.xml:

<build>
    <extensions>
        <extension>
            <groupId>my.groupId</groupId>
            <artifactId>maven-version-resolver</artifactId>
            <version>SNAPSHOT</version>
        </extension>
    </extensions>
</build>

However, my artifact is not used. When I run this little GMaven groovy script inside the build:

session.container.getComponentDescriptorList(
    'org.sonatype.aether.impl.VersionRangeResolver'
).each{
    println "Role Hint: ${it.roleHint}, implementation: ${it.implementation}" ;
}

it shows me both the default implementation and my own implementation, both with the hint 'default'. So how can I solve this?


Solution

  • This is very late answer, but I hope it will help these who got stuck with similar problem in maven-core.

    With Maven 3.3.1 it is possible to use custom core extensions which are defined in project root and does not require any modifications to command parameters or maven installation: https://maven.apache.org/docs/3.3.1/release-notes.html#Core_Extensions.

    I had very same issue like you to customize version range resolution and managed to make it working. My first working implementation is tagged here: https://github.com/splatch/maven-osgi-resolver/tree/3.3.9-a. I pushed code a little bit forward, but this tag contains everything you need to customize version range handling.

    In general devil sits in details - you must use plexus annotations and declare in META-INF/maven/extension.xml export package with plexus-components.xml, otherwise it will not work.