We have been using the wonderful flex mojos to build some of our actionscript code.

i needed to publish a jar containing the asdocs, but alas, the asdoc plugin doesn’t contain an equivalent to the javadoc:jar goal from the javadoc plugin.

needing something immediately, GMaven to the rescue!

the below profile will generate an attached jar when running mvn -P release

<profiles>
    <profile>
        <id>release</id>
        <build>
            <plugins>
                <plugin>
                    <groupId>info.flex-mojos</groupId>
                    <artifactId>asdoc-mojo</artifactId>
                    <executions>
                        <execution>
                            <phase>package</phase>
                            <id>attach-asdocs</id>
                            <goals>
                                <goal>asdoc</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
                <plugin>
                    <groupId>org.codehaus.groovy.maven</groupId>
                    <artifactId>gmaven-plugin</artifactId>
                    <version>1.0-rc-3</version>
                    <executions>
                        <execution>
                            <id>package-asdoc</id>
                            <phase>package</phase>
                            <goals>
                                <goal>execute</goal>
                            </goals>
                            <configuration>
                                <classpath>
                                    <classpath>
                                        <groupId>org.codehaus.plexus</groupId>
                                        <artifactId>plexus-archiver</artifactId>
                                    </classpath>
                                    <classpath>
                                        <groupId>org.apache.maven</groupId>
                                        <artifactId>maven-archiver</artifactId>
                                    </classpath>
                                </classpath>
                                <source>
                                    import org.codehaus.plexus.archiver.Archiver;
                                    import org.codehaus.plexus.archiver.jar.JarArchiver;
                                    import org.apache.maven.archiver.MavenArchiver;
                                    import org.apache.maven.archiver.MavenArchiveConfiguration;

                                    File asDocJar = new File(project.build.directory, "${project.build.finalName}-asdoc.jar")

                                    if( asDocJar.exists() ) asDocJar.delete()

                                    archiver = new MavenArchiver()
                                    archiver.archiver = new JarArchiver()
                                    archiver.outputFile = asDocJar
                                    archiver.archiver.addDirectory( new File(project.build.directory, "site/asdocs") )

                                    archive = new MavenArchiveConfiguration()
                                    archive.addMavenDescriptor = false

                                    archiver.createArchive( project, archive )

                                    helper = session.lookup("org.apache.maven.project.MavenProjectHelper")

                                    // need to attach to the *original* project
                                    // http://jira.codehaus.org/browse/MGROOVY-172
                                    project.class.getDeclaredField("original").accessible = true
                                    helper.attachArtifact( project.original, "zip", "asdoc", asDocJar )
                                </source>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>

        <dependencies>
            <dependency>
              <groupId>org.codehaus.plexus</groupId>
              <artifactId>plexus-archiver</artifactId>
              <version>1.0-alpha-7</version>
            </dependency>
            <dependency>
              <groupId>org.apache.maven</groupId>
              <artifactId>maven-archiver</artifactId>
              <version>2.3</version>
            </dependency>
        </dependencies>
    </profile>
</profiles>
Tags: ,

2 Responses to “creating attached maven artifacts with gmaven”

  1. Wim Deblauwe Says:

    Hi, thanks for this.

    If you use Maven 2.2.0 and Gmaven 1.0-rc5, which are currently the last versions for each, then you need to replace

    project.class.getDeclaredField(”original”).accessible = true
    helper.attachArtifact( project.original, “zip”, “asdoc”, asDocJar )

    with

    helper.attachArtifact( project.getDelegate(), “zip”, “asdoc”, asDocJar )

    otherwise, you get the following error:

    NoSuchFieldError: original

    hope this helps someone avoiding my struggle :)

    regards,

    Wim

  2. mrduguo Says:

    Latest maven 3.0.4/ gmaven 1.4 doesn’t need set field accessible any more:

    def mavenProjectHelper = session.lookup(”org.apache.maven.project.MavenProjectHelper”)
    mavenProjectHelper.attachArtifact( project, “zip”, “asdoc”, asDocJar )

Leave a Reply