version: 2
jobs:
    build:
        branches:
            only:
                - dev

        working_directory: ~/glowstone

        docker:
            - image: circleci/openjdk:8-jdk-browsers

        steps:

            - checkout

            - restore_cache:
                key: glowstone-{{ checksum "pom.xml" }}

            - run: mvn -T 2 -B dependency:go-offline

            - save_cache:
                paths:
                    - ~/.m2
                key: glowstone-{{ checksum "pom.xml" }}

            - run: mvn -T 2 -B -s .circleci/maven.xml source:jar javadoc:jar deploy

            - run: mv target/apidocs ./javadocs

            - run: zip -r javadocs.zip javadocs/

            - store_test_results:
                path: target/surefire-reports

            - store_artifacts:
                path: target/glowstone.jar
                destination: glowstone.jar

            - store_artifacts:
                path: javadocs.zip
                destination: javadocs.zip

            - store_artifacts:
                path: javadocs
                destination: javadocs

    build_other:
        branches:
            ignore:
                - dev

        working_directory: ~/glowstone

        docker:
            - image: circleci/openjdk:8-jdk-browsers

        steps:

            - checkout

            - restore_cache:
                key: glowstone-{{ checksum "pom.xml" }}

            - run: mvn -T 2 -B dependency:go-offline

            - save_cache:
                paths:
                    - ~/.m2
                key: glowstone-{{ checksum "pom.xml" }}

            - run: mvn -T 2 -B package

            - store_test_results:
                path: target/surefire-reports

            - store_artifacts:
                path: target/glowstone.jar
                destination: glowstone.jar
