Thursday, March 14, 2013

Whipping Maven, part deux

Success! I've got it attaching the zip and uploading everything automatically. This snippet shows the difference between my new POM and the one I posted last night:

            <!-- assemble a zip file with the deps in lib/ -->
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <id>dist-zip</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <descriptors>
                                <descriptor>assembly.xml</descriptor>
                            </descriptors>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>

        <extensions>
            <extension>
                <groupId>org.apache.maven.wagon</groupId>
                <artifactId>wagon-ssh</artifactId>
                <version>2.4</version>
            </extension>
        </extensions>
    </build>

    <distributionManagement>
        <repository>
            <id>chalcodes</id>
            <url>${chalcodes.url}</url>
        </repository>
    </distributionManagement>

There are a few things to note here. The ${chalcodes.url} property is injected by my ~/.m2/settings.xml. The SSH wagon extension requires that the URL contains the absolute path of the repository on the host, e.g., scp://example.com:1234/home/user/public_html/maven. If you supply a path relative to your home directory like you normally would with scp, it tries to create the directory /public_html, which of course fails. Also note that the assembly plugin goal must be single and not assembly.

There was one other hitch that took me a while to figure out. The wagon was able to create the subdirectories it needed, but it couldn't upload the files. It was failing with this error:

org.apache.maven.wagon.CommandExecutionException: Exit code: 0 - stdin: is not a tty

It turned out that my .bash_profile was including a file that contained the command stty. This doesn't cause any problems for scp, but apparently it screws up the Java implementation that Maven uses.

And here's the result: a sweet directory full of sweet files. It even generates the checksums automatically!

No comments:

Post a Comment