1

MavenProject.getArtifacts() is always empty, though I am able to see the MavenProject.getDependencies() returning the required list of dependencies.

I have tried adding the ArtifactHandled to the components.xml and configured it appropriately but still no solution

components.xml file

<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>

dependency in 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>

I would like to know how to transform the getDependencies into associated getArtifacts since that is what is used by the compiler

Phantom
  • 81
  • 7
  • One more thing that I saw was that the dependencies mentioned do not get downloaded unless I separately fire mvn dependency:resolve – Phantom Dec 28 '18 at 11:07
  • It seems I might have to use Phase in the life cycle to achieve it, but I am not sure how. Was referring the post https://stackoverflow.com/questions/50418101/custom-maven-packaging-transitive-dependencies-arent-included Any inputs on how to do it? – Phantom Dec 29 '18 at 04:36

1 Answers1

3

It seems I needed to add the requiresDependencyResolution attribute to the @Mojo annotation For packaging lifecycle I needed requiresDependencyResolution = ResolutionScope.RUNTIME For compile lifecycle I needed requiresDependencyResolution = ResolutionScope.COMPILE

Example: @Mojo(name = "myCompiler", defaultPhase = LifecyclePhase.COMPILE, threadSafe = true, requiresDependencyResolution = ResolutionScope.COMPILE )

Phantom
  • 81
  • 7