How to Use Travis CI with Java on GitHub


1. Build

  • Sign in to your user Github account and fork this repo (
  • Go to and Sign in with GitHub account
  • Accept the Authorization of Travis CI
  • Click on your profile picture in the top right of your Travis Dashboard, click Settings

  • Select the repo you want to use with Travis CI. If repo cannot be found, click Sync account

  • Back to Github. Create a .travis.yml file and add the following content(to tell Travis CI what to do), commit and push the changes to the root directory of your repo

    # Building a Java project
    language: java
    # We can specify a list of JDKs to be used for testing
     - openjdk11
  • Back to Travis CI. Click your repo and you will find it start build by Travis CI

  • If the build is successful, you will see a green badge as follows.

  • Create the badge(copy the markdown code from Travis CI and paste in the top line of

    Travis CI => select your repository => click the build status image => select FORMAT as Markdown => Copy the code of RESULT => paste in the top line of

  • You will see a badge like this in your repo of Github

2. Test

This repo also integrates with Codecov to generate reports.

  • Accept the authorization of Codecov and add your repository
  • Add the following code in the end of .travis.yml file. This is to enable CodeCov's coverage.
    If a build is successful, the code is submitted for coverage analysis

    - bash <(curl -s
  • Commit and push the changes to your repo, which will trigger a new build in Travis CI
  • Create the badge of coverage

    Codecov =>select your repository => Setting => Bedge => Copy the contect of Markdown => paste in
  • You will see the badge like this in your repo


  • Travis CI can help you release to Github after a success build. You will need to provide a Github personal access token(Tutorial:
  • Now that we have a token go to the project you want to use it with on Travis CI. Then on your project page, go to More options => Settings

  • In the Environment Variables section, add variable named GITHUB_TOKEN and use the generated token from Github in previous step

  provider: releases
  file_glob: true
  skip_cleanup: true
  api_key: $GITHUB_TOKEN
    - .travis.yml
    tags: true
    branch: tag
    repo: <your_github_username>/<your_repo_name>
  • Commit and push to trigger a Travis CI build. If the build is successful, you will see .travis.yml in the Releases section of your repo like this

4. Trigger a failed build and notify build result

  • Travis CI can notify you about your build results through email, IRC, chat or custom webhooks (
  • Add the following to your .travis.yml, which will send the build result to your Email

    - by your e-mail)
  • Modify the line 61 of as follows

    triOut = triOut + 2;

  • Commit and push to trigger a Travis CI build. As expected, this build will failed and you will receive an Email like this

阅读 138
1 声望
0 粉丝
0 条评论

1 声望
0 粉丝