How to package, compress and deploy binaries as zip/tar.gz from a github repo with maven/travis to bintray.com generic repo

d0x picture d0x · Aug 18, 2013 · Viewed 7.3k times · Source

Since Github disabled the downloads, we need to use a new service (like Bintray.com) for publishing our binaries. For our usecase I need to build a package (using appassembler-maven-plugin), then zip and tar.gz this build and deploy it to bintray.

It would be nice if a nightly builds will be shipped by travis and releases from hand with the mvn release plugin.

Currently the pom looks like this:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>myproject</groupId>
    <artifactId>myproject</artifactId>
    <version>1.0.0-SNAPSHOT</version>
    <packaging>jar</packaging>

    <scm>
        <url>https://github.com/d0x/fromGithubToBintray</url>
        <connection>scm:git:git://github.com/d0x/fromGithubToBintray.git</connection>
        <developerConnection>scm:git:[email protected]:d0x/fromGithubToBintray.git</developerConnection>
    </scm>

    <developers>
        <developer>
            <name>Christian Schneider</name>
            <url>https://github.com/d0x</url>
            <id>d0x</id>
        </developer>
    </developers>

<!--    <distributionManagement> -->
<!--        <repository> -->
<!--            <id>bintray</id> -->
<!--            <url>https://api.bintray.com/maven/d0x/fromGithubToBintray/downloads</url> -->
<!--        </repository> -->
<!--    </distributionManagement> -->


    <properties>
        <mainClass>fromGithubToBintray.Main</mainClass>

        <java-version>1.7</java-version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>

    <dependencies>
        <!-- ... -->        
    </dependencies>

    <build>
        <plugins>

            <!-- To build a clean binary pacakge to distribute -->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>appassembler-maven-plugin</artifactId>
                <version>1.4</version>
                <configuration>
                    <programs>
                        <program>
                            <mainClass>${mainClass}</mainClass>
                            <name>fromGithubToBintray</name>
                        </program>
                    </programs>

                    <extraJvmArguments>-Djava.awt.headless=true</extraJvmArguments>
                </configuration>
            </plugin>

            <!-- To specify the Java Version -->
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <source>${java-version}</source>
                    <target>${java-version}</target>
                </configuration>
            </plugin>

            <plugin>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.4.1</version>
                <configuration>
                    <useReleaseProfile>false</useReleaseProfile>
                    <releaseProfiles>release</releaseProfiles>
                    <autoVersionSubmodules>true</autoVersionSubmodules>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

How to tune the pom file to do that?

Reproduce:

I uploaded the small example to github: https://github.com/d0x/fromGithubToBintray

To exectue it do the following:

  1. git clone https://github.com/d0x/fromGithubToBintray.git
  2. cd fromGithubToBintray
  3. mvn clean package appassembler:assemble
  4. chmod +x target/appassembler/bin/fromGithubToBintray
  5. ./target/appassembler/bin/fromGithubToBintray

This should print You did it!. Now the goal is to upload compress and upload this appassembler folder to bintray.

Research done:

  • This tutorial shows how to use Bintray.com to publish to a Maven Repository.
  • Also I saw that the Netty project host its downloads on bintray. But in their Poms either in Jenkins I don't see bintray related stuff.

Answer

JBaruch picture JBaruch · Aug 19, 2013

The problem is that Bintray does not support SNAPSHOTs (Bintray is for releases only). What you need is an Artifactory+Bintray combo, that deploys snapshots to Artifactory, and once in a while (when you deside), releases a 'production-ready' version to Bintray.

Depending on the nature of your project you might be qualified to a free account on oss.jfrog.org. The requirement is that your deliverable is an open-source library/product, which is included in JCenter.

Pushing from Artifactory to Bintray is a really simple process, you can perform it just by clicking a button in Artifactory UI or by performing a REST call. Just remember - it must be a release, not a SNAPSHOT.

There are number of ways to convert a SNAPSHOT to release, which include changing versions in POM by hand, Maven Release Plugin, and others. When you use oss.jfrog.org as your Artifactory server, it includes a special plugin, which converts SHAPSHOTs to releases and deploys to Bintray in one go.