16
votes

I am new to Travis CI, but I have connected my Github to it. I have also created a .travis.yml where I set the language to java. I have created a HelloWorld.java file and committed and pushed it to the repo.

In Travis, there is no build at all. When I check requests under settings, I am seeing the commits, with the same status "Missing config", except for one stating "Build created successfully" but that has a red cross and red overlay when you hoover over it.

enter image description here

Is my .travis.yml missing a lot of commands and scripts as I have only set the language?

I dont have any build system as maven or the like on my mac installed, so the language setting won't suffice I guess. I need to put something in the script part for example:

jdk:
 - openjdk6
script:
mvn verify
after_success:
after_failure:

I need also to know what settings could be set for after_success and after_faliure.

Thanks, Sohail

2

2 Answers

30
votes

Travis CI is NOT a build tool. It is a Continous Integration tool which usually executes the same build command you would do locally, but automatically after every push to GitHub.

It requires a build mechanism being active. Well, that is not totally true, but it requires you to specify a valid command in the script: section that can be executed on the Travis CI host trying to build your code. When the return code of the command is 0, the build is treated as SUCCESS. Otherwise, it is treated as FAILURE.

(This is all really simplified, best would be to read Travis CI documentation, and perhaps some documents about Continous Integration in general).

In short: Set up your project to use Maven or Gradle or your favourite build tool. You should be able to locally execute mvn clean verify (when using Maven). Then, set up your .travis.yml:

language: java
sudo: false
script: mvn clean verify

And commit & push it, together with the pom.xml (when using Maven). Now, Travis CI should work like a charm.

1
votes

If you've written tests for you code, you can run them with ./mvnw test locally (Linux and macOS)

This workflow can then be translated to Travis CI by creating travis.yml in the project root / same directory as mvnw files.

Below is an example for a Maven build:

arch: amd64

language: java

jdk: 
  - oraclejdk15

cache:
  directories:
  - $HOME/.m2

script:
  - java --version
  - ./mvnw clean install
  - ./mvnw test