自定义Maven插件开发-尽管包含依赖项,但getArtifacts为空

时间:2018-12-28 07:08:43

标签: maven-plugin

MavenProject.getArtifacts()始终为空,尽管我能够看到MavenProject.getDependencies()返回所需的依赖项列表。

我尝试将ArtifactHandled添加到components.xml,并对其进行了适当配置,但仍然没有解决办法

components.xml文件

<components>
    <component>
        <role>org.apache.maven.artifact.handler.ArtifactHandler</role>
        <role-hint>xyz</role-hint>
        <implementation>
            org.apache.maven.artifact.handler.DefaultArtifactHandler
        </implementation>
        <configuration>
            <type>xyz</type>
            <extension>xyz</extension>
            <language>xyz</language>
            <addedToClasspath>true</addedToClasspath>
        </configuration>
    </component>

    <component>
        <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
        <role-hint>xyz</role-hint>
        <implementation>
            org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping
        </implementation>
        <configuration>
            <phases>
                <compile>
                    com.xyz.maven.plugin:otx-maven-plugin:cmp
                </compile>
                <package>
                    com.xyz.maven.plugin:otx-maven-plugin:pkg
                </package>
                <install>
                    org.apache.maven.plugins:maven-install-plugin:2.5.2:install
                </install>
             </phases>
        </configuration>
    </component>
</components>

pom.xml中的依赖性

   <dependencies>
    <dependency>
        <groupId>com.xyz.test.Project</groupId>
        <artifactId>testProject</artifactId>
        <version>1.0.0-SNAPSHOT</version>
        <type>xyz</type>
        <scope>compile</scope>
    </dependency>
</dependencies>

我想知道如何将getDependencies转换为关联的getArtifacts,因为这是编译器所使用的

1 个答案:

答案 0 :(得分:0)

似乎我需要将requireDependencyResolution属性添加到@Mojo批注 对于包装生命周期,我需要requireDependencyResolution = ResolutionScope.RUNTIME 对于编译生命周期,我需要requireDependencyResolution = ResolutionScope.COMPILE

示例:@Mojo(name =“ myCompiler”,defaultPhase = LifecyclePhase.COMPILE,threadSafe = true,requireDependencyResolution = ResolutionScope.COMPILE)