version: 2
jobs:
    build:
        branches:
            only:
                - dev
        docker:
            - image: circleci/openjdk:8-jdk

        working_directory: ~/glowstone

        environment:
            MAVEN_OPTS: -Xmx3200m

        steps:
            - checkout

            - restore_cache:
                keys:
                # Use cache for this pom
                - glowstone-{{ checksum "pom.xml" }}
                # Fallback to latest cache is an exact match is not found
                - glowstone-

            - 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

            - store_test_results:
                path: target/surefire-reports

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

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

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

    build:
        branches:
            ignore:
                - dev

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

        working_directory: ~/glowstone

        environment:
            MAVEN_OPTS: -Xmx3200m

        steps:
            - checkout

            - restore_cache:
                keys:
                # Use cache for this pom
                - glowstone-{{ checksum "pom.xml" }}
                # Fallback to latest cache is an exact match is not found
                - glowstone-

            - 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
