2

I'm writing a Maven 3 plugin which builds plugins for another application. A plugin is basically a JAR file with some fancy manifests. The compiled classes need to be post-processed for the plugin to work with the production build of the host application. Unfortunately, the processed version of the plugin won't work with the debug build of the host. I therefore need to produce two artifacts: the raw classes with the classifier debug and the post-processed version as the main artifact.

I've got a working Maven plugin which defines a new packaging type with its own lifecycle mappings. In order to create the debug artifact, though, I need to call jar:jar with the classifier property set. I haven't been able to find a way to change the configuration for a Mojo execution from a lifecycle mapping. Is that even possible? Will I have to make everyone use a super POM provided with my plugin?

For reference, here's the relevant part of my components.xml:

<?xml version="1.0" encoding="utf-8" ?>
<component-set>
  <components>
    <!-- snip other components, including ArtifactHandler -->
    <component>
      <role>org.apache.maven.lifecycle.mapping.LifecycleMapping</role>
      <role-hint>my-packaging</role-hint>
      <implementation>org.apache.maven.lifecycle.mapping.DefaultLifecycleMapping</implementation>
      <configuration>
        <lifecycles>
          <lifecycle>
            <id>default</id>
            <phases>
              <!-- snip other phases -->
              <package>
                org.apache.maven.plugins:maven-jar-plugin:jar
              </package>
            </phases>
          </lifecycle>
        </lifecycles>
      </configuration>
    </component>
  </components>
</component-set>

I need the execution to be equivalent to this POM fragment:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-jar-plugin</artifactId>
  <executions>
    <execution>
      <id>debug-jar</id>
      <phase>package</phase>
      <goal>jar</goal>
      <configuration>
        <classifier>debug</classifier>
      </configuration>
    </execution>
  </executions>
</plugin>

I found one SO question that seems to be the same thing I'm looking for but it doesn't have any answers. This is the documentation that I used to create the lifecycle mapping in the first place. Heavy Googling hasn't turned up anything that seems related, but I'm having trouble coming up with sufficiently specific search terms.

Community
  • 1
  • 1
Sam Hanes
  • 2,789
  • 23
  • 22
  • Are you sure you don't want to just invoke the 'archiver' component from your plugin as an ordinary subroutine, as opposed to forking an execution of the jar plugin? – bmargulies Feb 23 '13 at 03:05
  • @bmargulies I'm not forking a lifecycle from a Mojo. This is a lifecycle mapping associated with a custom packaging type. For projects using the packaging it's the default lifecycle. I could create a wrapper Mojo that invokes the archiver if I have to, but that removes the user's ability to override that part of the configuration so I'd like to avoid it. – Sam Hanes Feb 23 '13 at 03:10
  • Hmm. I'd pose this on one of the maven mailing lists. – bmargulies Feb 23 '13 at 03:17
  • @SamHanes did You ever get this resolved? I'm working on a simpler issue myself and still struggling with this. The closest I've found is: http://stackoverflow.com/questions/1427722/how-do-i-create-a-new-packaging-type-for-maven/1427749 – Raystorm Mar 24 '16 at 19:08
  • @Raystorm no, unfortunately not. I'm still just using a wrapper mojo that calls the archiver from Java with the necessary parameters, plus documentation on how to replace that with the actual archiver for users that need custom parameters. If you find a better solution please do post an answer. – Sam Hanes Mar 28 '16 at 20:59
  • I would suggest creating a new goal that just wraps the [Mojo Executor](https://github.com/TimMoore/mojo-executor) plugin to call jar:jar with the classifier property you need set. – Raystorm Apr 15 '16 at 18:09

0 Answers0