Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven 3.0 Plugin - how Do I set a goal that depends on another goal

I'm working on a Maven plugin for building a custom package type. I've got it packing and creating a fine. However, I have a previous goal that creates a library folder.

I want my build (package) goal to make sure the previous Lib goal was already run first. How can I do that?

declaring the build class like so:

@Mojo(name = "build", defaultPhase = LifecyclePhase.PACKAGE,
      requiresProject = true)
@Execute(goal="lib", phase = LifecyclePhase.PREPARE_PACKAGE)
public class BuildComponent extends AbstractComponentMojo

and the lib class like so:

@Mojo(name = "lib", defaultPhase = LifecyclePhase.PREPARE_PACKAGE,
      requiresProject = true)
@Execute(goal="compile", phase = LifecyclePhase.COMPILE)
public class LibComponent extends AbstractLibMojo

That worked so both goals will run. I'd like to just call mvn groupId:build instead of mvn groupId:lib groupId:build to have a successful build.

Am I missing some annotation processing at runtime? From what I've read I think I need a custom lifecycle to make this work. I've found the Maven Lifecycle Extensions example but I'm not sure how to use it to inject goals or phases into the lifecycle maven builds up and starts out with.

like image 428
Raystorm Avatar asked Dec 17 '25 21:12

Raystorm


1 Answers

I was able to get it working. However I feel like I'm doing the maven-2 approach instead of the maven-3 one. I'd love to see a Maven 3.0 answer

Basically I removed the @Execute annotations since they weren't needed anyway. Then I added the file src/main/resources/META-INF/plexus/components.xml

<?xml version="1.0" encoding="UTF-8"?>
<component-set>
  <components>
    <component>
      <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
      <role-hint>wcc</role-hint>
      <implementation>
         org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping
      </implementation>
      <configuration>
            <phases>
              <process-resources>
                org.apache.maven.plugins:maven-resources-plugin:resources
              </process-resources>
              <compile>
                org.apache.maven.plugins:maven-compiler-plugin:compile
              </compile>
              <process-classes>
                org.ucmtwine:ucm-maven-plugin:classpath
              </process-classes>
              <process-test-resources>
                org.apache.maven.plugins:maven-resources-plugin:testResources
              </process-test-resources>
              <test-compile>
                org.apache.maven.plugins:maven-compiler-plugin:testCompile
              </test-compile>
              <test>
                org.apache.maven.plugins:maven-surefire-plugin:test
              </test>
              <prepare-package>
                org.ucmtwine:ucm-maven-plugin:lib
              </prepare-package>
              <package>
                org.ucmtwine:ucm-maven-plugin:build
              </package>
              <install>
                org.apache.maven.plugins:maven-install-plugin:install
              </install>
              <deploy>
                org.ucmtwine:ucm-maven-plugin:deploy
              </deploy>
            </phases>
      </configuration>
    </component>

    <component>
      <role>org.apache.maven.artifact.handler.ArtifactHandler</role>
      <role-hint>wcc</role-hint>
      <implementation>
        org.apache.maven.artifact.handler.DefaultArtifactHandler
      </implementation>
      <configuration>
        <!--the extension used by Maven in the repository-->
        <extension>zip</extension>
        <!--the type used when specifying dependencies etc.-->
        <type>wcc</type>
        <!--the packaging used when declaring an implementation of
          the packaging-->
        <packaging>wcc</packaging>
      </configuration>
    </component>
  </components>
</component-set>

And then in the application where I'm using the plugin I set <packaging>wcc</packaging> and <extensions>true</extensions> where I declare my custom plugin.

like image 112
Raystorm Avatar answered Dec 19 '25 09:12

Raystorm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!