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

    working_directory: ~/repo

    steps:
      - checkout

      # Download and cache dependencies
      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "pom.xml" }}
            # fallback to using the latest cache if no exact match is found
            - v1-dependencies-

      - run: mvn dependency:go-offline

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

      - run:
          name: Build war file
          command: mvn package

      - persist_to_workspace:
          root: artifacts
          paths:
            - target/courses.war

  deploy:
    machine:
      enabled: true

    working_directory: ~/repo

    steps:
      - add_ssh_keys:
          fingerprints:
            - "de:20:51:fb:e5:c6:eb:62:56:9a:f0:f3:43:01:09:94"

      - run:
          name: Deploy to server
          command: |
            scp -P $SSH_PORT $CIRCLE_WORKING_DIRECTORY/artifacts/target/courses.war $SSH_USER@$SSH_HOST:/home/$SSH_USER

workflows:
  version: 2
  main_flow:
    jobs:
      - build
      - deploy:
          requires:
            - build

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

    working_directory: ~/repo

    steps:
      - checkout

      # Download and cache dependencies
      - restore_cache:
          keys:
            - v1-dependencies-{{ checksum "pom.xml" }}
            # fallback to using the latest cache if no exact match is found
            - v1-dependencies-

      - run: mvn dependency:go-offline

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

      - run:
          name: Build war file
          command: mvn package

      - persist_to_workspace:
          root: target
          paths:
            - courses.war

  deploy:
    machine:
      enabled: true

    working_directory: ~/repo

    steps:
      - add_ssh_keys:
          fingerprints:
            - "de:20:51:fb:e5:c6:eb:62:56:9a:f0:f3:43:01:09:94"

      - run:
          name: Deploy to server
          command: |
            scp -P $SSH_PORT $CIRCLE_WORKING_DIRECTORY/target/courses.war $SSH_USER@$SSH_HOST:/home/$SSH_USER

workflows:
  version: 2
  main_flow:
    jobs:
      - build
      - deploy:
          requires:
            - build

Update artifact settings in CircleCI
Update artifact settings in CircleCI
